From 3951a63d9393ed7e1381bbb9da95dfb2dd2d6b13 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 14 Oct 2024 00:24:15 +0200 Subject: book intermediate representation and packets for sending to client --- server/src/data/mod.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'server/src/data/mod.rs') 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)>, pub chef_spawn: Vec2, pub customer_spawn: Vec2, pub score_baseline: i64, - pub default_timer: Option + pub default_timer: Option, + 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, + 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, -- cgit v1.2.3-70-g09d2