convert room id and palette id to u64
This commit is contained in:
parent
e249727c3e
commit
53d5a28923
|
@ -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(),
|
||||
|
|
18
src/room.rs
18
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<String>,
|
||||
pub tiles: Vec<String>, // tile ids
|
||||
pub items: Vec<Instance>,
|
||||
|
@ -15,9 +15,9 @@ impl From<String> 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<Instance> = Vec::new();
|
||||
let mut exits: Vec<ExitInstance> = Vec::new();
|
||||
let mut endings: Vec<Instance> = Vec::new();
|
||||
|
@ -28,7 +28,7 @@ impl From<String> 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<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!(
|
||||
"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)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue