diff options
author | metamuffin <metamuffin@disroot.org> | 2024-12-25 19:37:20 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-12-25 19:37:20 +0100 |
commit | bd74a4e0c0e4e42717c2931eab3febfae219ac9c (patch) | |
tree | 30d6dc91921aab9a8ffd271901d8122891560a65 /pixel-client/src | |
parent | 462bc5a62f24a35e05d6a171566495e2641583a8 (diff) | |
download | hurrycurry-bd74a4e0c0e4e42717c2931eab3febfae219ac9c.tar hurrycurry-bd74a4e0c0e4e42717c2931eab3febfae219ac9c.tar.bz2 hurrycurry-bd74a4e0c0e4e42717c2931eab3febfae219ac9c.tar.zst |
variable hand count
Diffstat (limited to 'pixel-client/src')
-rw-r--r-- | pixel-client/src/game.rs | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs index 4dc43b72..cbcc62d5 100644 --- a/pixel-client/src/game.rs +++ b/pixel-client/src/game.rs @@ -156,13 +156,13 @@ impl Game { self.network.queue_out.push_back(PacketS::Interact { player: self.my_id, pos: Some(self.players[&self.my_id].movement.get_interact_target()), - hand: Hand::Left, + hand: Hand(0), }); } else { self.network.queue_out.push_back(PacketS::Interact { player: self.my_id, pos: None, - hand: Hand::Left, + hand: Hand(0), }); } self.interacting = interact; @@ -331,19 +331,23 @@ impl Game { } } PacketC::MoveItem { from, to } => { - let mut item = self.get_item(from).take(); + let mut item = self.get_item(from).unwrap().take(); if let Some(item) = &mut item { item.parent_position = self.get_location_position(to); } - *self.get_item(to) = item; + *self.get_item(to).unwrap() = item; } PacketC::SetItem { location, item } => { let position = self.get_location_position(location); let slot = match location { ItemLocation::Tile(pos) => &mut self.tiles.get_mut(&pos).unwrap().item, - ItemLocation::Player(pid, hand) => { - &mut self.players.get_mut(&pid).unwrap().items[hand.index()] - } + ItemLocation::Player(pid, hand) => self + .players + .get_mut(&pid) + .unwrap() + .items + .get_mut(hand.0) + .unwrap(), }; self.items_removed.extend(slot.take()); *slot = item.map(|kind| Item { @@ -354,7 +358,13 @@ impl Game { active: None, }) } - PacketC::ClearProgress { item } => self.get_item(item).as_mut().unwrap().active = None, + PacketC::ClearProgress { item } => { + if let Some(slot) = self.get_item(item) { + if let Some(item) = slot { + item.active = None; + } + } + } PacketC::SetProgress { item, position, @@ -362,13 +372,17 @@ impl Game { player, warn, } => { - self.get_item(item).as_mut().unwrap().active = Some(Involvement { - position, - speed, - player, - warn, - recipe: RecipeIndex(0), - }); + if let Some(slot) = self.get_item(item) { + if let Some(item) = slot { + item.active = Some(Involvement { + position, + speed, + player, + warn, + recipe: RecipeIndex(0), + }); + } + } } PacketC::ServerMessage { .. } => { // TODO @@ -392,11 +406,11 @@ impl Game { } } - pub fn get_item(&mut self, location: ItemLocation) -> &mut Option<Item> { + pub fn get_item(&mut self, location: ItemLocation) -> Option<&mut Option<Item>> { match location { - ItemLocation::Tile(pos) => &mut self.tiles.get_mut(&pos).unwrap().item, + ItemLocation::Tile(pos) => Some(&mut self.tiles.get_mut(&pos)?.item), ItemLocation::Player(pid, hand) => { - &mut self.players.get_mut(&pid).unwrap().items[hand.index()] + Some(self.players.get_mut(&pid)?.items.get_mut(hand.0)?) } } } |