function for optional lines of game data
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{AnimationFrames, Image, Position, mock, from_base36, ToBase36};
|
||||
use crate::{AnimationFrames, Image, Position, mock, from_base36, ToBase36, optional_data_line};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Sprite {
|
||||
@@ -10,6 +10,16 @@ pub struct Sprite {
|
||||
pub position: Position,
|
||||
}
|
||||
|
||||
impl Sprite {
|
||||
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 Sprite {
|
||||
fn from(string: String) -> Sprite {
|
||||
let mut lines: Vec<&str> = string.lines().collect();
|
||||
@@ -59,8 +69,8 @@ impl ToString for Sprite {
|
||||
"SPR {}\n{}{}{}\nPOS {} {}",
|
||||
self.id.to_base36(),
|
||||
self.animation_frames.to_string(),
|
||||
if self.name.as_ref().is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() },
|
||||
if self.dialogue_id.as_ref().is_some() { format!("\nDLG {}", self.dialogue_id.as_ref().unwrap()) } else { "".to_string() },
|
||||
self.name_line(),
|
||||
self.dialogue_line(),
|
||||
self.room_id.to_base36(),
|
||||
self.position.to_string(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user