dedupe optional lines for item
This commit is contained in:
parent
ba6d4e8b40
commit
6dc9bbcc2d
15
src/item.rs
15
src/item.rs
|
@ -1,4 +1,4 @@
|
||||||
use crate::{AnimationFrames, Image, mock, from_base36, ToBase36};
|
use crate::{AnimationFrames, Image, mock, from_base36, ToBase36, optional_data_line};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
|
@ -8,6 +8,15 @@ pub struct Item {
|
||||||
pub dialogue_id: Option<String>,
|
pub dialogue_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<String> for Item {
|
impl From<String> for Item {
|
||||||
fn from(string: String) -> Item {
|
fn from(string: String) -> Item {
|
||||||
let mut lines: Vec<&str> = string.lines().collect();
|
let mut lines: Vec<&str> = string.lines().collect();
|
||||||
|
@ -47,8 +56,8 @@ impl ToString for Item {
|
||||||
"ITM {}\n{}{}{}",
|
"ITM {}\n{}{}{}",
|
||||||
self.id.to_base36(),
|
self.id.to_base36(),
|
||||||
self.animation_frames.to_string(),
|
self.animation_frames.to_string(),
|
||||||
if self.name.is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() },
|
self.name_line(),
|
||||||
if self.dialogue_id.is_some() { format!("\nDLG {}", self.dialogue_id.as_ref().unwrap()) } else { "".to_string() },
|
self.dialogue_line(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue