diff options
author | metamuffin <metamuffin@disroot.org> | 2024-10-14 00:24:15 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-10-14 00:24:15 +0200 |
commit | 3951a63d9393ed7e1381bbb9da95dfb2dd2d6b13 (patch) | |
tree | cd586f961075c8d5f8d2ac583dfbc257d82efca5 /server/src/data/mod.rs | |
parent | 3b0bb4132eb8d3a0fd3438f4f344e8687a5dd71e (diff) | |
download | hurrycurry-3951a63d9393ed7e1381bbb9da95dfb2dd2d6b13.tar hurrycurry-3951a63d9393ed7e1381bbb9da95dfb2dd2d6b13.tar.bz2 hurrycurry-3951a63d9393ed7e1381bbb9da95dfb2dd2d6b13.tar.zst |
book intermediate representation and packets for sending to client
Diffstat (limited to 'server/src/data/mod.rs')
-rw-r--r-- | server/src/data/mod.rs | 19 |
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, |