From 45ee94aae96f6cafc642da937e5d4e6522ae32b0 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Mon, 13 Apr 2020 14:47:15 +0100 Subject: [PATCH] item id to u64; item.dialogue -> item.dialogue_id --- src/item.rs | 18 +++++++++--------- src/mock.rs | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/item.rs b/src/item.rs index c92ecaf..a4100cd 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1,20 +1,20 @@ -use crate::{AnimationFrames, Image, mock}; +use crate::{AnimationFrames, Image, mock, from_base36, ToBase36}; #[derive(Debug, Eq, PartialEq)] pub struct Item { - pub id: String, + pub id: u64, pub animation_frames: Vec, pub name: Option, - pub dialogue: Option, // dialogue id + pub dialogue_id: Option, // dialogue id } impl From for Item { fn from(string: String) -> Item { 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 dialogue = None; + let mut dialogue_id = None; for _ in 0..2 { let last_line = lines.pop().unwrap(); @@ -22,7 +22,7 @@ impl From for Item { if last_line.starts_with("NAME") { name = Some(last_line.replace("NAME ", "").to_string()); } 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 { lines.push(last_line); break; @@ -36,7 +36,7 @@ impl From for Item { Image::from(frame.to_string()) }).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 { format!( "ITM {}\n{}{}{}", - self.id, + self.id.to_base36(), self.animation_frames.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() }, ) } } diff --git a/src/mock.rs b/src/mock.rs index 19a87d9..7914b4a 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -96,7 +96,7 @@ pub fn sprite() -> Sprite { pub fn item() -> Item { Item { - id: "6".to_string(), + id: 6, animation_frames: vec![ Image { pixels: vec![ @@ -112,7 +112,7 @@ pub fn item() -> Item { } ], 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![ Item { - id: "0".to_string(), + id: 0, animation_frames: vec![ Image { pixels: vec![ @@ -286,7 +286,7 @@ pub fn game_default() -> Game { }, ], name: Some("tea".to_string()), - dialogue: Some("ITM_0".to_string()) + dialogue_id: Some("ITM_0".to_string()) }, ], dialogues: vec![