implement optional palette id for room
This commit is contained in:
18
src/room.rs
18
src/room.rs
@@ -3,7 +3,7 @@ use crate::{Exit, ExitInstance, Instance, Position, from_base36, ToBase36, optio
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Room {
|
||||
pub id: u64,
|
||||
pub palette_id: u64, // id
|
||||
pub palette_id: Option<u64>, // optional in very early versions
|
||||
pub name: Option<String>,
|
||||
pub tiles: Vec<String>, // tile ids
|
||||
pub items: Vec<Instance>,
|
||||
@@ -25,6 +25,14 @@ impl Room {
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn palette_line(&self) -> String {
|
||||
if self.palette_id.is_some() {
|
||||
optional_data_line("PAL", Some(self.palette_id.unwrap().to_base36()))
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Room {
|
||||
@@ -34,7 +42,7 @@ impl From<String> for Room {
|
||||
let mut lines: Vec<&str> = string.lines().collect();
|
||||
let id = from_base36(&lines[0]);
|
||||
let mut name = None;
|
||||
let mut palette_id = 0;
|
||||
let mut palette_id = None;
|
||||
let mut items: Vec<Instance> = Vec::new();
|
||||
let mut exits: Vec<ExitInstance> = Vec::new();
|
||||
let mut endings: Vec<Instance> = Vec::new();
|
||||
@@ -50,7 +58,7 @@ impl From<String> for Room {
|
||||
} else if last_line.starts_with("NAME") {
|
||||
name = Some(last_line.replace("NAME ", "").to_string());
|
||||
} else if last_line.starts_with("PAL") {
|
||||
palette_id = from_base36(&last_line.replace("PAL ", ""));
|
||||
palette_id = Some(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();
|
||||
@@ -152,7 +160,7 @@ impl ToString for Room {
|
||||
}
|
||||
|
||||
format!(
|
||||
"ROOM {}\n{}{}{}{}{}{}\nPAL {}",
|
||||
"ROOM {}\n{}{}{}{}{}{}{}",
|
||||
self.id.to_base36(),
|
||||
tiles,
|
||||
self.name_line(),
|
||||
@@ -160,7 +168,7 @@ impl ToString for Room {
|
||||
items,
|
||||
exits,
|
||||
endings,
|
||||
self.palette_id.to_base36()
|
||||
self.palette_line()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user