implement ToBase36 for u64; room id to u64; sprite id to u64; tile id to u64; sprite.dialogue -> sprite.dialogue_id

This commit is contained in:
2020-04-13 14:43:23 +01:00
parent f424c49301
commit c7f1d7220c
7 changed files with 48 additions and 37 deletions

View File

@@ -1,10 +1,10 @@
use crate::AnimationFrames;
use crate::{AnimationFrames, from_base36, ToBase36};
use crate::image::Image;
use crate::mock;
#[derive(Debug, Eq, PartialEq)]
pub struct Tile {
pub id: String, // base36 string
pub id: u64,
pub name: Option<String>,
pub wall: bool,
pub animation_frames: Vec<Image>,
@@ -15,7 +15,7 @@ impl From<String> for Tile {
fn from(string: String) -> Tile {
let mut lines: Vec<&str> = string.lines().collect();
let id = lines[0].replace("TIL ", "");
let id = from_base36(&lines[0].replace("TIL ", ""));
let last_line = lines.pop().unwrap();
let wall = match last_line == "WAL true" {
@@ -50,7 +50,7 @@ impl ToString for Tile {
fn to_string(&self) -> String {
format!(
"TIL {}\n{}{}{}",
self.id,
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.wall {"\nWAL true"} else {""}
@@ -63,7 +63,7 @@ fn test_tile_from_string() {
let output = Tile::from(include_str!("../test/resources/tile").to_string());
let expected = Tile {
id: "z".to_string(),
id: 35,
name: Some("concrete 1".to_string()),
wall: true,
animation_frames: vec![
@@ -79,7 +79,7 @@ fn test_tile_from_string() {
#[test]
fn test_tile_to_string() {
let output = Tile {
id: "7a".to_string(),
id: 262,
name: Some("chequers".to_string()),
wall: false,
animation_frames: vec![