item colour id
This commit is contained in:
parent
b4e05cdc1b
commit
5d1c515192
18
src/item.rs
18
src/item.rs
|
@ -6,15 +6,21 @@ pub struct Item {
|
|||
pub animation_frames: Vec<Image>,
|
||||
pub name: Option<String>,
|
||||
pub dialogue_id: Option<String>,
|
||||
pub colour_id: Option<u64>,
|
||||
}
|
||||
|
||||
impl Item {
|
||||
fn name_line(&self) -> String {
|
||||
optional_data_line("NAME", self.name.as_ref())
|
||||
}
|
||||
|
||||
fn dialogue_line(&self) -> String {
|
||||
optional_data_line("DLG", self.dialogue_id.as_ref())
|
||||
}
|
||||
|
||||
fn colour_line(&self) -> String {
|
||||
optional_data_line("COL", self.colour_id.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Item {
|
||||
|
@ -24,14 +30,17 @@ impl From<String> for Item {
|
|||
let id = from_base36(&lines[0].replace("ITM ", ""));
|
||||
let mut name = None;
|
||||
let mut dialogue_id = None;
|
||||
let mut colour_id: Option<u64> = None;
|
||||
|
||||
for _ in 0..2 {
|
||||
loop {
|
||||
let last_line = lines.pop().unwrap();
|
||||
|
||||
if last_line.starts_with("NAME") {
|
||||
name = Some(last_line.replace("NAME ", "").to_string());
|
||||
} else if last_line.starts_with("DLG") {
|
||||
dialogue_id = Some(last_line.replace("DLG ", "").to_string());
|
||||
} else if last_line.starts_with("COL") {
|
||||
colour_id = Some(last_line.replace("COL ", "").parse().unwrap());
|
||||
} else {
|
||||
lines.push(last_line);
|
||||
break;
|
||||
|
@ -40,12 +49,12 @@ impl From<String> for Item {
|
|||
|
||||
// todo dedupe
|
||||
let animation_frames = lines[1..].join("");
|
||||
let animation_frames: Vec<&str> = animation_frames.split("\n>\n").collect();
|
||||
let animation_frames: Vec<&str> = animation_frames.split(">").collect();
|
||||
let animation_frames: Vec<Image> = animation_frames.iter().map(|&frame| {
|
||||
Image::from(frame.to_string())
|
||||
}).collect();
|
||||
|
||||
Item { id, name, animation_frames, dialogue_id }
|
||||
Item { id, name, animation_frames, dialogue_id, colour_id }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,11 +62,12 @@ impl ToString for Item {
|
|||
#[inline]
|
||||
fn to_string(&self) -> String {
|
||||
format!(
|
||||
"ITM {}\n{}{}{}",
|
||||
"ITM {}\n{}{}{}{}",
|
||||
self.id.to_base36(),
|
||||
self.animation_frames.to_string(),
|
||||
self.name_line(),
|
||||
self.dialogue_line(),
|
||||
self.colour_line(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue