diff options
author | metamuffin <metamuffin@disroot.org> | 2024-12-23 15:37:11 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-12-25 20:01:20 +0100 |
commit | b0df9b7c27a3d6316969d7feff4d912c3abf99f6 (patch) | |
tree | 118daa57feda8b571bd00bd22f6ff0dac4cc46de /server/protocol/src/helpers.rs | |
parent | 2ceeea0e5fc245602618ec47f6ff1f91a094e130 (diff) | |
download | hurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar hurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar.bz2 hurrycurry-b0df9b7c27a3d6316969d7feff4d912c3abf99f6.tar.zst |
two-handed server
Diffstat (limited to 'server/protocol/src/helpers.rs')
-rw-r--r-- | server/protocol/src/helpers.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/server/protocol/src/helpers.rs b/server/protocol/src/helpers.rs index 924d0886..21835101 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,7 +99,32 @@ 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 { + f.write_str(match self { + Hand::Left => "left", + Hand::Right => "right", + }) + } +} + +impl Hand { + pub fn index(&self) -> usize { + match self { + Hand::Left => 0, + Hand::Right => 1, + } + } + pub fn from_index(i: usize) -> Self { + match i { + 0 => Hand::Left, + 1 => Hand::Right, + _ => Hand::Left, } } } |