aboutsummaryrefslogtreecommitdiff
path: root/pixel-client
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client')
-rw-r--r--pixel-client/src/game.rs50
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)?)
}
}
}