item id to u64; item.dialogue -> item.dialogue_id
This commit is contained in:
parent
c7f1d7220c
commit
45ee94aae9
18
src/item.rs
18
src/item.rs
|
@ -1,20 +1,20 @@
|
||||||
use crate::{AnimationFrames, Image, mock};
|
use crate::{AnimationFrames, Image, mock, from_base36, ToBase36};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub id: String,
|
pub id: u64,
|
||||||
pub animation_frames: Vec<Image>,
|
pub animation_frames: Vec<Image>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub dialogue: Option<String>, // dialogue id
|
pub dialogue_id: Option<String>, // dialogue id
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
let id = lines[0].replace("ITM ", "");
|
let id = from_base36(&lines[0].replace("ITM ", ""));
|
||||||
let mut name = None;
|
let mut name = None;
|
||||||
let mut dialogue = None;
|
let mut dialogue_id = None;
|
||||||
|
|
||||||
for _ in 0..2 {
|
for _ in 0..2 {
|
||||||
let last_line = lines.pop().unwrap();
|
let last_line = lines.pop().unwrap();
|
||||||
|
@ -22,7 +22,7 @@ impl From<String> for Item {
|
||||||
if last_line.starts_with("NAME") {
|
if last_line.starts_with("NAME") {
|
||||||
name = Some(last_line.replace("NAME ", "").to_string());
|
name = Some(last_line.replace("NAME ", "").to_string());
|
||||||
} else if last_line.starts_with("DLG") {
|
} else if last_line.starts_with("DLG") {
|
||||||
dialogue = Some(last_line.replace("DLG ", "").to_string());
|
dialogue_id = Some(last_line.replace("DLG ", "").to_string());
|
||||||
} else {
|
} else {
|
||||||
lines.push(last_line);
|
lines.push(last_line);
|
||||||
break;
|
break;
|
||||||
|
@ -36,7 +36,7 @@ impl From<String> for Item {
|
||||||
Image::from(frame.to_string())
|
Image::from(frame.to_string())
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
Item { id, name, animation_frames, dialogue }
|
Item { id, name, animation_frames, dialogue_id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ impl ToString for Item {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
format!(
|
format!(
|
||||||
"ITM {}\n{}{}{}",
|
"ITM {}\n{}{}{}",
|
||||||
self.id,
|
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() },
|
if self.name.is_some() { format!("\nNAME {}", self.name.as_ref().unwrap()) } else { "".to_string() },
|
||||||
if self.dialogue.is_some() { format!("\nDLG {}", self.dialogue.as_ref().unwrap()) } else { "".to_string() },
|
if self.dialogue_id.is_some() { format!("\nDLG {}", self.dialogue_id.as_ref().unwrap()) } else { "".to_string() },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ pub fn sprite() -> Sprite {
|
||||||
|
|
||||||
pub fn item() -> Item {
|
pub fn item() -> Item {
|
||||||
Item {
|
Item {
|
||||||
id: "6".to_string(),
|
id: 6,
|
||||||
animation_frames: vec![
|
animation_frames: vec![
|
||||||
Image {
|
Image {
|
||||||
pixels: vec![
|
pixels: vec![
|
||||||
|
@ -112,7 +112,7 @@ pub fn item() -> Item {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
name: Some("door".to_string()),
|
name: Some("door".to_string()),
|
||||||
dialogue: Some("ITM_2".to_string())
|
dialogue_id: Some("ITM_2".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ pub fn game_default() -> Game {
|
||||||
],
|
],
|
||||||
items: vec![
|
items: vec![
|
||||||
Item {
|
Item {
|
||||||
id: "0".to_string(),
|
id: 0,
|
||||||
animation_frames: vec![
|
animation_frames: vec![
|
||||||
Image {
|
Image {
|
||||||
pixels: vec![
|
pixels: vec![
|
||||||
|
@ -286,7 +286,7 @@ pub fn game_default() -> Game {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
name: Some("tea".to_string()),
|
name: Some("tea".to_string()),
|
||||||
dialogue: Some("ITM_0".to_string())
|
dialogue_id: Some("ITM_0".to_string())
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
dialogues: vec![
|
dialogues: vec![
|
||||||
|
|
Loading…
Reference in New Issue