diff options
| author | troido <troido@protonmail.com> | 2020-02-23 01:18:17 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-23 01:18:17 +0100 |
| commit | 7262cfc53b4af978d6db1b91e3143200f906587f (patch) | |
| tree | f6aa651a3040a1389a9c4e82796f1c04b3c5198c /src/playerstate.rs | |
| parent | 522aad7889cd62e96af7c420789507ccbf5b7aaa (diff) | |
rooms have named locations to be used by portals
Diffstat (limited to 'src/playerstate.rs')
| -rw-r--r-- | src/playerstate.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/playerstate.rs b/src/playerstate.rs index ff9565b..8e3d99f 100644 --- a/src/playerstate.rs +++ b/src/playerstate.rs @@ -10,25 +10,35 @@ use crate::{ Result, aerr, Sprite, - Encyclopedia + Encyclopedia, + Pos }; #[derive(Debug, Clone)] pub struct PlayerState { pub id: PlayerId, pub room: Option<RoomId>, + pub pos: RoomPos, pub inventory_capacity: usize, pub inventory: Vec<Template>, pub health: i64, pub maximum_health: i64 } +#[derive(Debug, Clone)] +pub enum RoomPos { + Pos(Pos), + Name(String), + Unknown +} + impl PlayerState { pub fn new(id: PlayerId) -> Self { Self{ id, room: None, + pos: RoomPos::Unknown, inventory: Vec::new(), inventory_capacity: 10, health: 9, @@ -40,6 +50,7 @@ impl PlayerState { Self { id, room: Some(room), + pos: RoomPos::Unknown, inventory, health, inventory_capacity, @@ -79,6 +90,7 @@ impl PlayerState { Value::String(name) => Some(RoomId::from_str(name)), _ => None }, + pos: RoomPos::Unknown, inventory: items, health: val.get("health").ok_or(aerr!("player json does not have health"))?.as_i64().ok_or(aerr!("player health not a number"))?, inventory_capacity: inventory.get("capacity").ok_or(aerr!("inventory does no have capacity"))?.as_i64().ok_or(aerr!("inventory capacity not a number"))? as usize, |
