diff options
Diffstat (limited to 'server/protocol')
-rw-r--r-- | server/protocol/src/lib.rs | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 2c165a92..05561a12 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -71,13 +71,12 @@ pub struct MapMetadata { #[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, Default)] #[rustfmt::skip] -pub struct ClientGamedata { +pub struct Gamedata { pub current_map: String, pub item_names: Vec<String>, pub tile_names: Vec<String>, pub tile_collide: Vec<bool>, pub tile_interact: Vec<bool>, - pub map_names: HashSet<String>, // for compat with game jam version pub maps: HashMap<String, MapMetadata>, pub recipes: Vec<Recipe>, } @@ -144,7 +143,7 @@ pub enum PacketC { id: PlayerID, }, Data { - data: ClientGamedata, + data: Gamedata, }, AddPlayer { id: PlayerID, @@ -257,6 +256,42 @@ pub enum Recipe { }, } +impl Gamedata { + pub fn tile_name(&self, index: TileIndex) -> &String { + &self.tile_names[index.0] + } + pub fn is_tile_colliding(&self, index: TileIndex) -> bool { + self.tile_collide[index.0] + } + pub fn is_tile_interactable(&self, index: TileIndex) -> bool { + self.tile_interact[index.0] + } + pub fn item_name(&self, index: ItemIndex) -> &String { + &self.item_names[index.0] + } + pub fn recipe(&self, index: RecipeIndex) -> &Recipe { + &self.recipes[index.0] + } + pub fn get_tile_by_name(&self, name: &str) -> Option<TileIndex> { + self.tile_names + .iter() + .position(|t| t == name) + .map(TileIndex) + } + pub fn get_item_by_name(&self, name: &str) -> Option<ItemIndex> { + self.item_names + .iter() + .position(|t| t == name) + .map(ItemIndex) + } + pub fn recipes(&self) -> impl Iterator<Item = (RecipeIndex, &Recipe)> { + self.recipes + .iter() + .enumerate() + .map(|(i, e)| (RecipeIndex(i), e)) + } +} + impl Recipe { pub fn tile(&self) -> Option<TileIndex> { match self { |