convert room id and palette id to u64

This commit is contained in:
Max Bradbury 2020-04-13 13:46:33 +01:00
parent e249727c3e
commit 53d5a28923
2 changed files with 13 additions and 13 deletions

View File

@ -118,8 +118,8 @@ pub fn item() -> Item {
pub fn room() -> Room { pub fn room() -> Room {
Room { Room {
id: "a".to_string(), id: 10,
palette: "9".to_string(), palette_id: 9,
name: Some("cellar 7".to_string()), name: Some("cellar 7".to_string()),
tiles: vec![ 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(), "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![ rooms: vec![
Room { Room {
id: "0".to_string(), id: 0,
palette: "0".to_string(), palette_id: 0,
name: None, name: None,
tiles: vec![ 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(), "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(),

View File

@ -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)] #[derive(Debug, Eq, PartialEq)]
pub struct Room { pub struct Room {
pub id: String, pub id: u64,
pub palette: String, // id pub palette_id: u64, // id
pub name: Option<String>, pub name: Option<String>,
pub tiles: Vec<String>, // tile ids pub tiles: Vec<String>, // tile ids
pub items: Vec<Instance>, pub items: Vec<Instance>,
@ -15,9 +15,9 @@ impl From<String> for Room {
fn from(string: String) -> Room { fn from(string: String) -> Room {
// todo handle room_format? // todo handle room_format?
let mut lines: Vec<&str> = string.lines().collect(); 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 name = None;
let mut palette = "0".to_string(); let mut palette_id = 0;
let mut items: Vec<Instance> = Vec::new(); let mut items: Vec<Instance> = Vec::new();
let mut exits: Vec<ExitInstance> = Vec::new(); let mut exits: Vec<ExitInstance> = Vec::new();
let mut endings: Vec<Instance> = Vec::new(); let mut endings: Vec<Instance> = Vec::new();
@ -28,7 +28,7 @@ impl From<String> for Room {
if last_line.starts_with("NAME") { if last_line.starts_with("NAME") {
name = Some(last_line.replace("NAME ", "").to_string()); name = Some(last_line.replace("NAME ", "").to_string());
} else if last_line.starts_with("PAL") { } 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") { } else if last_line.starts_with("ITM") {
let last_line = last_line.replace("ITM ", ""); let last_line = last_line.replace("ITM ", "");
let item_position: Vec<&str> = last_line.split(' ').collect(); let item_position: Vec<&str> = last_line.split(' ').collect();
@ -70,7 +70,7 @@ impl From<String> 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!( format!(
"ROOM {}\n{}{}{}{}{}\nPAL {}", "ROOM {}\n{}{}{}{}{}\nPAL {}",
self.id, to_base36(self.id),
tiles, tiles,
if self.name.as_ref().is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() }, if self.name.as_ref().is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() },
items, items,
exits, exits,
endings, endings,
self.palette to_base36(self.palette_id)
) )
} }
} }