diff options
author | metamuffin <metamuffin@noreply.codeberg.org> | 2024-12-25 19:05:05 +0000 |
---|---|---|
committer | metamuffin <metamuffin@noreply.codeberg.org> | 2024-12-25 19:05:05 +0000 |
commit | cc6b50debb9d5b740adbe6f803755413c972659a (patch) | |
tree | b34a0a5669707992f1334f88a1959d5b1e120415 /server/protocol/src | |
parent | 2ceeea0e5fc245602618ec47f6ff1f91a094e130 (diff) | |
parent | 53cf167c08986caf346957d1f357cefaee1bd6b5 (diff) | |
download | hurrycurry-cc6b50debb9d5b740adbe6f803755413c972659a.tar hurrycurry-cc6b50debb9d5b740adbe6f803755413c972659a.tar.bz2 hurrycurry-cc6b50debb9d5b740adbe6f803755413c972659a.tar.zst |
Merge pull request 'Two-handed players' (#236) from two-handed into master
Reviewed-on: https://codeberg.org/hurrycurry/hurrycurry/pulls/236
Diffstat (limited to 'server/protocol/src')
-rw-r--r-- | server/protocol/src/helpers.rs | 11 | ||||
-rw-r--r-- | server/protocol/src/lib.rs | 9 |
2 files changed, 17 insertions, 3 deletions
diff --git a/server/protocol/src/helpers.rs b/server/protocol/src/helpers.rs index 924d0886..b85c2f84 100644 --- a/server/protocol/src/helpers.rs +++ b/server/protocol/src/helpers.rs @@ -1,7 +1,8 @@ use std::fmt::Display; use crate::{ - DocumentElement, Gamedata, ItemIndex, ItemLocation, PlayerID, Recipe, RecipeIndex, TileIndex, + DocumentElement, Gamedata, Hand, ItemIndex, ItemLocation, PlayerID, Recipe, RecipeIndex, + TileIndex, }; impl Gamedata { @@ -98,11 +99,17 @@ impl Display for ItemLocation { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { ItemLocation::Tile(pos) => write!(f, "tile({pos})"), - ItemLocation::Player(PlayerID(id)) => write!(f, "player({id})"), + ItemLocation::Player(PlayerID(id), hand) => write!(f, "player({id}_{hand})"), } } } +impl Display for Hand { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "h{}", self.0) + } +} + impl Default for DocumentElement { fn default() -> Self { Self::Document { es: vec![] } diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 2ef07015..74d463a1 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -71,6 +71,10 @@ pub struct RecipeIndex(pub usize); #[serde(transparent)] pub struct DemandIndex(pub usize); +#[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, Hash)] +#[serde(transparent)] +pub struct Hand(pub usize); + #[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)] pub struct MapMetadata { pub name: String, @@ -98,6 +102,7 @@ pub struct Gamedata { pub bot_algos: Vec<String>, pub recipes: Vec<Recipe>, pub demands: Vec<Demand>, + pub hand_count: usize, } #[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)] @@ -124,6 +129,7 @@ pub enum PacketS { }, Interact { player: PlayerID, + hand: Hand, #[bincode(with_serde)] pos: Option<IVec2>, }, @@ -144,6 +150,7 @@ pub enum PacketS { /// For internal use only (customers) ReplaceHand { player: PlayerID, + hand: Hand, item: Option<ItemIndex>, }, #[serde(skip)] @@ -344,7 +351,7 @@ pub enum Recipe { #[serde(rename_all = "snake_case")] pub enum ItemLocation { Tile(#[bincode(with_serde)] IVec2), - Player(PlayerID), + Player(PlayerID, Hand), } #[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)] |