diff options
| -rw-r--r-- | server/src/data.rs | 5 | ||||
| -rw-r--r-- | server/src/game.rs | 9 | ||||
| -rw-r--r-- | server/src/state.rs | 12 | 
3 files changed, 24 insertions, 2 deletions
diff --git a/server/src/data.rs b/server/src/data.rs index 9fd3e95c..5f35a360 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -100,6 +100,7 @@ pub struct Demand {  #[derive(Debug, Clone, Serialize, Deserialize, Default)]  #[rustfmt::skip]  pub struct Gamedata { +    pub spec: String,      pub item_names: Vec<String>,      pub tile_names: Vec<String>,      pub tile_collide: Vec<bool>, @@ -165,7 +166,7 @@ impl DataIndex {          let demands_in = serde_yaml::from_str(&self.read_demands(demands).await?)?;          let recipes_in = serde_yaml::from_str(&self.read_recipes(recipes).await?)?; -        let mut gd = Gamedata::build(map_in, demands_in, recipes_in)?; +        let mut gd = Gamedata::build(spec, map_in, demands_in, recipes_in)?;          gd.map_names = self.maps.clone();          Ok(gd)      } @@ -173,6 +174,7 @@ impl DataIndex {  impl Gamedata {      pub fn build( +        spec: String,          map_in: InitialMap,          demands_in: Vec<DemandDecl>,          recipes_in: Vec<RecipeDecl>, @@ -281,6 +283,7 @@ impl Gamedata {          );          Ok(Gamedata { +            spec,              demands,              tile_collide,              tile_interact, diff --git a/server/src/game.rs b/server/src/game.rs index 5cdf8cd4..e13a2f93 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -63,7 +63,7 @@ pub struct Player {  }  pub struct Game { -    data: Arc<Gamedata>, +    pub data: Arc<Gamedata>,      tiles: HashMap<IVec2, Tile>,      pub players: HashMap<PlayerID, Player>,      packet_out: VecDeque<PacketC>, @@ -544,6 +544,13 @@ impl Game {          return self.end.map(|t| t < Instant::now()).unwrap_or_default();      } + +    pub fn count_chefs(&self) -> usize { +        self.players +            .iter() +            .map(|(_, p)| if p.character > 0 { 1 } else { 0 }) +            .sum() +    }  }  impl From<TileIndex> for Tile { diff --git a/server/src/state.rs b/server/src/state.rs index b496040b..2af436a3 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -57,6 +57,9 @@ enum Command {      /// Send an effect      Effect { name: String },      /// Reload the resource index +    ReloadIndex, +    /// Reload the current map +    #[clap(alias = "r")]      Reload,  } @@ -159,6 +162,15 @@ impl State {                  );              }              Command::Reload => { +                if self.game.count_chefs() > 1 { +                    bail!("must be at most one player to reload"); +                } +                self.game.load( +                    self.index.generate(self.game.data.spec.to_string()).await?, +                    None, +                ); +            } +            Command::ReloadIndex => {                  self.index.reload()?;              }              Command::Download { r#type, name } => {  |