diff --git a/src/mock.rs b/src/mock.rs index b5928cb..cb44fa0 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -118,8 +118,8 @@ pub fn item() -> Item { pub fn room() -> Room { Room { - id: "a".to_string(), - palette: "9".to_string(), + id: 10, + palette_id: 9, name: Some("cellar 7".to_string()), tiles: vec![ "0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"1l".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(), @@ -176,8 +176,8 @@ pub fn game_default() -> Game { ], rooms: vec![ Room { - id: "0".to_string(), - palette: "0".to_string(), + id: 0, + palette_id: 0, name: None, tiles: vec![ "0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(), diff --git a/src/room.rs b/src/room.rs index 3f6a423..900b198 100644 --- a/src/room.rs +++ b/src/room.rs @@ -1,9 +1,9 @@ -use crate::{Exit, ExitInstance, Instance, mock, Position}; +use crate::{Exit, ExitInstance, Instance, mock, Position, from_base36, to_base36}; #[derive(Debug, Eq, PartialEq)] pub struct Room { - pub id: String, - pub palette: String, // id + pub id: u64, + pub palette_id: u64, // id pub name: Option, pub tiles: Vec, // tile ids pub items: Vec, @@ -15,9 +15,9 @@ impl From for Room { fn from(string: String) -> Room { // todo handle room_format? let mut lines: Vec<&str> = string.lines().collect(); - let id = lines[0].replace("ROOM ", ""); + let id = from_base36(&lines[0].replace("ROOM ", "")); let mut name = None; - let mut palette = "0".to_string(); + let mut palette_id = 0; let mut items: Vec = Vec::new(); let mut exits: Vec = Vec::new(); let mut endings: Vec = Vec::new(); @@ -28,7 +28,7 @@ impl From for Room { if last_line.starts_with("NAME") { name = Some(last_line.replace("NAME ", "").to_string()); } else if last_line.starts_with("PAL") { - palette = last_line.replace("PAL ", "").to_string(); + palette_id = from_base36(&last_line.replace("PAL ", "")); } else if last_line.starts_with("ITM") { let last_line = last_line.replace("ITM ", ""); let item_position: Vec<&str> = last_line.split(' ').collect(); @@ -70,7 +70,7 @@ impl From for Room { } } - Room { id, palette, name, tiles, items, exits, endings } + Room { id, palette_id, name, tiles, items, exits, endings } } } @@ -123,13 +123,13 @@ impl ToString for Room { format!( "ROOM {}\n{}{}{}{}{}\nPAL {}", - self.id, + to_base36(self.id), tiles, if self.name.as_ref().is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() }, items, exits, endings, - self.palette + to_base36(self.palette_id) ) } }