summaryrefslogtreecommitdiff
path: root/server/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/data')
-rw-r--r--server/src/data/mod.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs
index 39684c6f..549574c7 100644
--- a/server/src/data/mod.rs
+++ b/server/src/data/mod.rs
@@ -20,12 +20,12 @@ pub mod demands;
pub mod index;
use crate::entity::{construct_entity, Entities, EntityDecl};
-use anyhow::{anyhow, bail, Result};
+use anyhow::{anyhow, bail, Context, Result};
use demands::generate_demands;
use hurrycurry_bot::algos::ALGO_CONSTRUCTORS;
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
- Gamedata, ItemIndex, MapMetadata, Recipe, TileIndex,
+ DocumentElement, Gamedata, ItemIndex, MapMetadata, Recipe, TileIndex,
};
use serde::{Deserialize, Serialize};
use std::{
@@ -87,14 +87,15 @@ pub struct DemandDecl {
points: i64,
}
-#[derive(Debug,Clone, Default)]
+#[derive(Debug, Clone, Default)]
#[rustfmt::skip]
pub struct Serverdata {
pub initial_map: HashMap<IVec2, (TileIndex, Option<ItemIndex>)>,
pub chef_spawn: Vec2,
pub customer_spawn: Vec2,
pub score_baseline: i64,
- pub default_timer: Option<Duration>
+ pub default_timer: Option<Duration>,
+ pub book: DocumentElement
}
#[derive(Debug, Deserialize, Default)]
@@ -145,7 +146,13 @@ impl DataIndex {
.read_recipes(map_in.recipes.as_deref().unwrap_or("default"))
.await?,
)?;
- build_data(&self.maps, map.to_string(), map_in, recipes_in)
+ let book = serde_json::from_str(
+ &read_to_string(data_dir().join("book.json"))
+ .await
+ .context("loading book")?,
+ )
+ .context("invalid book")?;
+ build_data(&self.maps, map.to_string(), map_in, recipes_in, book)
}
}
@@ -154,6 +161,7 @@ pub fn build_data(
map_name: String,
map_in: MapDecl,
recipes_in: Vec<RecipeDecl>,
+ book: DocumentElement,
) -> Result<(Gamedata, Serverdata, Entities)> {
let reg = ItemTileRegistry::default();
let mut recipes = Vec::new();
@@ -304,6 +312,7 @@ pub fn build_data(
chef_spawn,
customer_spawn,
default_timer,
+ book,
score_baseline: map_in.score_baseline,
},
entities,