use built-in debug macros

This commit is contained in:
Max Bradbury 2020-04-05 23:02:03 +01:00
parent 47a9259526
commit 9e7dffa516
1 changed files with 11 additions and 50 deletions

View File

@ -4,26 +4,26 @@ use std::collections::HashMap;
const IMAGE_DIMENSION_SD: usize = 8;
const IMAGE_DIMENSION_HD: usize = 16;
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Colour {
red: u8,
green: u8,
blue: u8,
}
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Palette {
id: String, // base36 string (why??)
name: Option<String>,
colours: Vec<Colour>,
}
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Image {
pixels: Vec<u8>, // 64 for SD, 256 for HD
}
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Tile {
id: String, // base36 string
name: Option<String>,
@ -38,13 +38,13 @@ struct Position {
y: u8,
}
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Dialogue {
id: String,
contents: String,
}
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Sprite {
id: String, // lowercase base36
name: Option<String>,
@ -54,13 +54,13 @@ struct Sprite {
}
/// avatar is a "sprite" in the game data but with a specific ID
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Avatar {
animation_frames: Vec<Image>,
position: Position,
}
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Item {
id: String,
animation_frames: Vec<Image>,
@ -68,7 +68,7 @@ struct Item {
dialogue: Option<Dialogue>,
}
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Exit {
/// destination
room: String, /// id
@ -76,12 +76,12 @@ struct Exit {
}
// same as a dialogue basically
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Ending {
contents: String,
}
#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
struct Room {
id: String,
palette: String, /// id
@ -100,45 +100,6 @@ struct Game {
palettes: Vec<Palette>,
}
impl fmt::Debug for Colour {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Colour")
.field("red", &self.red)
.field("green", &self.green)
.field("blue", &self.blue)
.finish()
}
}
impl fmt::Debug for Palette {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Palette")
.field("id", &self.id)
.field("name", &self.name)
.field("colours", &self.colours)
.finish()
}
}
impl fmt::Debug for Image {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Image")
.field("pixels", &self.pixels)
.finish()
}
}
impl fmt::Debug for Tile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Tile")
.field("id", &self.id)
.field("name", &self.name)
.field("wall", &self.wall)
.field("animation_frames", &self.animation_frames)
.finish()
}
}
fn image_from_string(string: String) -> Image {
let string = string.replace("\n", "");
let pixels: Vec<&str> = string.split("").collect();