Format Rust code using rustfmt

This commit is contained in:
github-actions[bot] 2020-04-18 15:58:30 +00:00 committed by GitHub
parent 9a5c4df2b1
commit cba6c16414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 956 additions and 394 deletions

View File

@ -1,4 +1,4 @@
use crate::{AnimationFrames, Image, Position, optional_data_line, ToBase36, from_base36}; use crate::{from_base36, optional_data_line, AnimationFrames, Image, Position, ToBase36};
/// avatar is a "sprite" in the game data but with a specific id /// avatar is a "sprite" in the game data but with a specific id
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
@ -12,7 +12,11 @@ pub struct Avatar {
impl Avatar { impl Avatar {
fn room_position_line(&self) -> String { fn room_position_line(&self) -> String {
format!("\nPOS {} {}", self.room_id.to_base36(), self.position.to_string()) format!(
"\nPOS {} {}",
self.room_id.to_base36(),
self.position.to_string()
)
} }
fn colour_line(&self) -> String { fn colour_line(&self) -> String {
@ -58,11 +62,18 @@ impl From<String> for Avatar {
let animation_frames: String = lines.join("\n"); let animation_frames: String = lines.join("\n");
let animation_frames: Vec<&str> = animation_frames.split(">").collect(); let animation_frames: Vec<&str> = animation_frames.split(">").collect();
let animation_frames: Vec<Image> = animation_frames.iter().map(|&frame| { let animation_frames: Vec<Image> = animation_frames
Image::from(frame.to_string()) .iter()
}).collect(); .map(|&frame| Image::from(frame.to_string()))
.collect();
Avatar { animation_frames, name, room_id, position , colour_id } Avatar {
animation_frames,
name,
room_id,
position,
colour_id,
}
} }
} }
@ -81,14 +92,15 @@ impl ToString for Avatar {
#[test] #[test]
fn test_avatar_from_string() { fn test_avatar_from_string() {
let output = Avatar::from( let output = Avatar::from(include_str!("test-resources/avatar").to_string());
include_str!("test-resources/avatar").to_string()
);
assert_eq!(output, crate::mock::avatar()); assert_eq!(output, crate::mock::avatar());
} }
#[test] #[test]
fn test_avatar_to_string() { fn test_avatar_to_string() {
assert_eq!(crate::mock::avatar().to_string(), include_str!("test-resources/avatar")); assert_eq!(
crate::mock::avatar().to_string(),
include_str!("test-resources/avatar")
);
} }

View File

@ -1,32 +1,26 @@
extern crate bitsy_parser; extern crate bitsy_parser;
use std::{env, fs};
use bitsy_parser::game::Game; use bitsy_parser::game::Game;
use bitsy_parser::image::Image; use bitsy_parser::image::Image;
use std::{env, fs};
/// replaces the player avatar with a smiley face. /// replaces the player avatar with a smiley face.
fn main() { fn main() {
let input_file = env::args().nth(1) let input_file = env::args()
.nth(1)
.expect("No input path specified. Usage: `smiley infile outfile`"); .expect("No input path specified. Usage: `smiley infile outfile`");
let output_file = env::args().nth(2) let output_file = env::args()
.nth(2)
.expect("No output path specified. Usage: `smiley infile outfile`"); .expect("No output path specified. Usage: `smiley infile outfile`");
let mut game = Game::from(fs::read_to_string(input_file).unwrap()); let mut game = Game::from(fs::read_to_string(input_file).unwrap());
game.avatar.animation_frames = vec![ game.avatar.animation_frames = vec![Image {
Image {
pixels: vec![ pixels: vec![
0,0,1,1,1,1,0,0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1,
0,1,1,1,1,1,1,0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0,
1,1,0,1,1,0,1,1, 1, 1, 1, 1, 0, 0,
1,1,0,1,1,0,1,1, ],
1,1,1,1,1,1,1,1, }];
1,1,0,1,1,0,1,1,
0,1,1,0,0,1,1,0,
0,0,1,1,1,1,0,0,
]
}
];
fs::write(output_file, &game.to_string()) fs::write(output_file, &game.to_string()).expect("Failed to write to output file");
.expect("Failed to write to output file");
} }

View File

@ -24,19 +24,27 @@ impl ToString for Colour {
} }
} }
#[test] #[test]
fn test_colour_from_string() { fn test_colour_from_string() {
assert_eq!( assert_eq!(
Colour::from("0,255,0".to_string()), Colour::from("0,255,0".to_string()),
Colour { red: 0, green: 255, blue: 0 } Colour {
red: 0,
green: 255,
blue: 0
}
); );
} }
#[test] #[test]
fn test_colour_to_string() { fn test_colour_to_string() {
assert_eq!( assert_eq!(
Colour { red: 22, green: 33, blue: 44 }.to_string(), Colour {
red: 22,
green: 33,
blue: 44
}
.to_string(),
"22,33,44".to_string() "22,33,44".to_string()
); );
} }

View File

@ -25,7 +25,10 @@ impl ToString for Dialogue {
fn test_dialogue_from_string() { fn test_dialogue_from_string() {
assert_eq!( assert_eq!(
Dialogue::from("DLG h\nhello\ngoodbye".to_string()), Dialogue::from("DLG h\nhello\ngoodbye".to_string()),
Dialogue { id: "h".to_string(), contents: "hello\ngoodbye".to_string()} Dialogue {
id: "h".to_string(),
contents: "hello\ngoodbye".to_string()
}
) )
} }
@ -35,7 +38,8 @@ fn test_dialogue_to_string() {
Dialogue { Dialogue {
id: "y".to_string(), id: "y".to_string(),
contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string() contents: "This is a bit of dialogue,\nblah blah\nblah blah".to_string()
}.to_string(), }
.to_string(),
"DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string() "DLG y\nThis is a bit of dialogue,\nblah blah\nblah blah".to_string()
); );
} }

View File

@ -16,7 +16,8 @@ impl From<String> for Ending {
id_dialogue[1] id_dialogue[1]
} else { } else {
"" ""
}.to_string(); }
.to_string();
Ending { id, dialogue } Ending { id, dialogue }
} }
@ -46,7 +47,8 @@ fn test_ending_to_string() {
Ending { Ending {
id: "7".to_string(), id: "7".to_string(),
dialogue: "This is another long ending. So long, farewell, etc.".to_string() dialogue: "This is another long ending. So long, farewell, etc.".to_string()
}.to_string(), }
.to_string(),
"END 7\nThis is another long ending. So long, farewell, etc.".to_string() "END 7\nThis is another long ending. So long, farewell, etc.".to_string()
); );
} }

View File

@ -1,4 +1,4 @@
use crate::{Position, from_base36, ToBase36}; use crate::{from_base36, Position, ToBase36};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub enum Transition { pub enum Transition {
@ -41,14 +41,16 @@ impl ToString for Transition {
Transition::SlideLeft => " FX slide_l", Transition::SlideLeft => " FX slide_l",
Transition::SlideRight => " FX slide_r", Transition::SlideRight => " FX slide_r",
Transition::None => "", Transition::None => "",
}.to_string() }
.to_string()
} }
} }
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub struct Exit { pub struct Exit {
/// destination /// destination
pub room_id: u64, /// id pub room_id: u64,
/// id
pub position: Position, pub position: Position,
pub effect: Transition, pub effect: Transition,
} }
@ -66,7 +68,11 @@ impl From<String> for Exit {
Transition::None Transition::None
}; };
Exit { room_id, position, effect } Exit {
room_id,
position,
effect,
}
} }
} }
@ -85,7 +91,11 @@ impl ToString for Exit {
fn test_exit_from_string() { fn test_exit_from_string() {
assert_eq!( assert_eq!(
Exit::from("a 12,13".to_string()), Exit::from("a 12,13".to_string()),
Exit { room_id: 10, position: Position { x: 12, y: 13 }, effect: Transition::None } Exit {
room_id: 10,
position: Position { x: 12, y: 13 },
effect: Transition::None
}
); );
} }
@ -93,14 +103,23 @@ fn test_exit_from_string() {
fn test_exit_from_string_with_fx() { fn test_exit_from_string_with_fx() {
assert_eq!( assert_eq!(
Exit::from("a 12,13 FX slide_u".to_string()), Exit::from("a 12,13 FX slide_u".to_string()),
Exit { room_id: 10, position: Position { x: 12, y: 13 }, effect: Transition::SlideUp } Exit {
room_id: 10,
position: Position { x: 12, y: 13 },
effect: Transition::SlideUp
}
); );
} }
#[test] #[test]
fn test_exit_to_string() { fn test_exit_to_string() {
assert_eq!( assert_eq!(
Exit { room_id: 8, position: Position { x: 5, y: 6 }, effect: Transition::None}.to_string(), Exit {
room_id: 8,
position: Position { x: 5, y: 6 },
effect: Transition::None
}
.to_string(),
"8 5,6".to_string() "8 5,6".to_string()
); );
} }
@ -112,7 +131,8 @@ fn test_exit_to_string_with_fx() {
room_id: 8, room_id: 8,
position: Position { x: 5, y: 6 }, position: Position { x: 5, y: 6 },
effect: Transition::FadeToWhite effect: Transition::FadeToWhite
}.to_string(), }
.to_string(),
"8 5,6 FX fade_w".to_string() "8 5,6 FX fade_w".to_string()
); );
} }

View File

@ -1,4 +1,7 @@
use crate::{Avatar, Dialogue, Ending, Font, Item, Palette, Room, Sprite, TextDirection, Tile, Variable, optional_data_line, ToBase36}; use crate::{
optional_data_line, Avatar, Dialogue, Ending, Font, Item, Palette, Room, Sprite, TextDirection,
Tile, ToBase36, Variable,
};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub struct Version { pub struct Version {
@ -10,7 +13,10 @@ impl Version {
fn from(str: &str) -> Version { fn from(str: &str) -> Version {
let parts: Vec<&str> = str.split(".").collect(); let parts: Vec<&str> = str.split(".").collect();
assert_eq!(parts.len(), 2); assert_eq!(parts.len(), 2);
Version { major: parts[0].parse().unwrap(), minor: parts[1].parse().unwrap() } Version {
major: parts[0].parse().unwrap(),
minor: parts[1].parse().unwrap(),
}
} }
} }
@ -76,10 +82,8 @@ impl From<String> for Game {
} }
} }
let dialogue_segments = format!( let dialogue_segments =
"\n\nDLG{}", format!("\n\nDLG{}", dialogues_endings_variables.trim_matches('\n'));
dialogues_endings_variables.trim_matches('\n')
);
let dialogue_segments: Vec<&str> = dialogue_segments.split("\n\nDLG").collect(); let dialogue_segments: Vec<&str> = dialogue_segments.split("\n\nDLG").collect();
for segment in dialogue_segments[1..].to_owned() { for segment in dialogue_segments[1..].to_owned() {
@ -233,7 +237,7 @@ impl ToString for Game {
impl Game { impl Game {
pub fn tile_ids(&self) -> Vec<u64> { pub fn tile_ids(&self) -> Vec<u64> {
self.tiles.iter().map(|tile| {tile.id}).collect() self.tiles.iter().map(|tile| tile.id).collect()
} }
/// first available tile ID. /// first available tile ID.
@ -264,7 +268,10 @@ impl Game {
} }
fn version_line(&self) -> String { fn version_line(&self) -> String {
format!("\n# BITSY VERSION {}.{}", self.version.major, self.version.minor) format!(
"\n# BITSY VERSION {}.{}",
self.version.major, self.version.minor
)
} }
fn room_format_line(&self) -> String { fn room_format_line(&self) -> String {
@ -284,15 +291,17 @@ impl Game {
} }
fn text_direction_line(&self) -> &str { fn text_direction_line(&self) -> &str {
if self.text_direction == TextDirection::RightToLeft {"\n\nTEXT_DIRECTION RTL"} else {""} if self.text_direction == TextDirection::RightToLeft {
"\n\nTEXT_DIRECTION RTL"
} else {
""
}
} }
} }
#[test] #[test]
fn test_game_from_string() { fn test_game_from_string() {
let output = Game::from( let output = Game::from(include_str!["test-resources/default.bitsy"].to_string());
include_str!["test-resources/default.bitsy"].to_string()
);
let expected = crate::mock::game_default(); let expected = crate::mock::game_default();
@ -356,34 +365,26 @@ fn test_bitsy_omnibus() {
let acceptable_failures: Vec<String> = vec![ let acceptable_failures: Vec<String> = vec![
// fails because of sprite colours but also because a tile contains "NaN" // fails because of sprite colours but also because a tile contains "NaN"
"src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(), "src/test-resources/omnibus/DA88C287.bitsy.txt".to_string(),
// SET instead of ROOM? todo investigate // SET instead of ROOM? todo investigate
"src/test-resources/omnibus/1998508E.bitsy.txt".to_string(), "src/test-resources/omnibus/1998508E.bitsy.txt".to_string(),
"src/test-resources/omnibus/046871F8.bitsy.txt".to_string(), "src/test-resources/omnibus/046871F8.bitsy.txt".to_string(),
// not sure about this one but it uses room wall array // not sure about this one but it uses room wall array
"src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(), "src/test-resources/omnibus/748F77B5.bitsy.txt".to_string(),
// bad game data // bad game data
"src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(), "src/test-resources/omnibus/14C48FA0.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(), "src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(), "src/test-resources/omnibus/C63A0633.bitsy.txt".to_string(),
"src/test-resources/omnibus/013B3CDE.bitsy.txt".to_string(), // NaN in image "src/test-resources/omnibus/013B3CDE.bitsy.txt".to_string(), // NaN in image
// this one has font data appended to the end of the game data - is this valid? // this one has font data appended to the end of the game data - is this valid?
"src/test-resources/omnibus/4B4EB988.bitsy.txt".to_string(), "src/test-resources/omnibus/4B4EB988.bitsy.txt".to_string(),
// has an ending position of -1 // has an ending position of -1
"src/test-resources/omnibus/593BD9A6.bitsy.txt".to_string(), "src/test-resources/omnibus/593BD9A6.bitsy.txt".to_string(),
// extra line between dialogues // extra line between dialogues
"src/test-resources/omnibus/DB59A848.bitsy.txt".to_string(), "src/test-resources/omnibus/DB59A848.bitsy.txt".to_string(),
// something going on with dialogues? todo investigate // something going on with dialogues? todo investigate
"src/test-resources/omnibus/807805CC.bitsy.txt".to_string(), "src/test-resources/omnibus/807805CC.bitsy.txt".to_string(),
"src/test-resources/omnibus/C36E27E5.bitsy.txt".to_string(), "src/test-resources/omnibus/C36E27E5.bitsy.txt".to_string(),
"src/test-resources/omnibus/354DA56F.bitsy.txt".to_string(), "src/test-resources/omnibus/354DA56F.bitsy.txt".to_string(),
// this avatar has `ITM 0 1` - can the player start with an item? todo investigate // this avatar has `ITM 0 1` - can the player start with an item? todo investigate
"src/test-resources/omnibus/CC5085BE.bitsy.txt".to_string(), "src/test-resources/omnibus/CC5085BE.bitsy.txt".to_string(),
"src/test-resources/omnibus/20D06BD1.bitsy.txt".to_string(), "src/test-resources/omnibus/20D06BD1.bitsy.txt".to_string(),
@ -412,7 +413,10 @@ fn test_bitsy_omnibus() {
println!("Testing: {}...", path.display()); println!("Testing: {}...", path.display());
let game_data = std::fs::read_to_string(path).unwrap(); let game_data = std::fs::read_to_string(path).unwrap();
let game = Game::from(game_data.clone()); let game = Game::from(game_data.clone());
assert_eq!(game.to_string().trim_matches('\n'), game_data.trim_matches('\n')); assert_eq!(
game.to_string().trim_matches('\n'),
game_data.trim_matches('\n')
);
passes += 1; passes += 1;
println!("Success! {} passes, {} skips.", passes, skips); println!("Success! {} passes, {} skips.", passes, skips);
} }

View File

@ -10,9 +10,10 @@ impl From<String> for Image {
let pixels: Vec<&str> = string.split("").collect(); let pixels: Vec<&str> = string.split("").collect();
// the above seems to add an extra "" at the start and end of the vec, so strip them below // the above seems to add an extra "" at the start and end of the vec, so strip them below
let pixels = &pixels[1..(pixels.len() - 1)]; let pixels = &pixels[1..(pixels.len() - 1)];
let pixels: Vec<u32> = pixels.iter().map(|&pixel| { let pixels: Vec<u32> = pixels
pixel.parse::<u32>().unwrap() .iter()
}).collect(); .map(|&pixel| pixel.parse::<u32>().unwrap())
.collect();
Image { pixels } Image { pixels }
} }
@ -43,15 +44,10 @@ fn test_image_from_string() {
let expected = Image { let expected = Image {
pixels: vec![ pixels: vec![
1,1,1,1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,1,0,0,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,0,1,1,1,1,1,1, 1, 1, 1, 1, 1, 1,
1,1,1,1,1,1,1,1, ],
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
]
}; };
assert_eq!(output, expected) assert_eq!(output, expected)

View File

@ -1,4 +1,4 @@
use crate::{AnimationFrames, Image, from_base36, ToBase36, optional_data_line}; use crate::{from_base36, optional_data_line, AnimationFrames, Image, ToBase36};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub struct Item { pub struct Item {
@ -50,11 +50,18 @@ impl From<String> for Item {
// todo dedupe // todo dedupe
let animation_frames = lines[1..].join(""); let animation_frames = lines[1..].join("");
let animation_frames: Vec<&str> = animation_frames.split(">").collect(); let animation_frames: Vec<&str> = animation_frames.split(">").collect();
let animation_frames: Vec<Image> = animation_frames.iter().map(|&frame| { let animation_frames: Vec<Image> = animation_frames
Image::from(frame.to_string()) .iter()
}).collect(); .map(|&frame| Image::from(frame.to_string()))
.collect();
Item { id, name, animation_frames, dialogue_id, colour_id } Item {
id,
name,
animation_frames,
dialogue_id,
colour_id,
}
} }
} }

View File

@ -5,15 +5,15 @@ pub mod colour;
pub mod dialogue; pub mod dialogue;
pub mod ending; pub mod ending;
pub mod exit; pub mod exit;
pub mod text;
pub mod game; pub mod game;
pub mod palette;
pub mod image; pub mod image;
pub mod item; pub mod item;
pub mod mock; pub mod mock;
pub mod palette;
pub mod position; pub mod position;
pub mod room; pub mod room;
pub mod sprite; pub mod sprite;
pub mod text;
pub mod tile; pub mod tile;
pub mod variable; pub mod variable;
@ -21,18 +21,18 @@ use avatar::Avatar;
use colour::Colour; use colour::Colour;
use dialogue::Dialogue; use dialogue::Dialogue;
use ending::Ending; use ending::Ending;
use exit::{Transition, Exit}; use exit::{Exit, Transition};
use text::{Font, TextDirection};
use game::{Game, Version}; use game::{Game, Version};
use palette::Palette;
use image::Image; use image::Image;
use item::Item; use item::Item;
use palette::Palette;
use position::Position; use position::Position;
use room::Room; use room::Room;
use sprite::Sprite; use sprite::Sprite;
use std::fmt::Display;
use text::{Font, TextDirection};
use tile::Tile; use tile::Tile;
use variable::Variable; use variable::Variable;
use std::fmt::Display;
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub struct Instance { pub struct Instance {

View File

@ -6,30 +6,20 @@ pub mod image {
pub(crate) fn chequers_1() -> Image { pub(crate) fn chequers_1() -> Image {
Image { Image {
pixels: vec![ pixels: vec![
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1,
0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0, ],
0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1,
]
} }
} }
pub fn chequers_2() -> Image { pub fn chequers_2() -> Image {
Image { Image {
pixels: vec![ pixels: vec![
0,1,0,1,0,1,0,1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0,
1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0,1,0,1,0,1,0,1, ],
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
]
} }
} }
} }
@ -39,27 +29,17 @@ pub fn avatar() -> Avatar {
animation_frames: vec![ animation_frames: vec![
Image { Image {
pixels: vec![ pixels: vec![
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1,
0,0,1,1,1,1,0,0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0,1,1,1,1,1,1,0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0,
1,1,1,0,1,1,1,0, ],
1,0,0,1,1,0,0,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
0,1,1,1,1,1,1,0,
]
}, },
Image { Image {
pixels: vec![ pixels: vec![
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1,
0,0,0,0,0,0,0,0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1,
0,0,1,1,1,1,0,0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0,
0,1,1,1,1,1,1,0, ],
1,1,1,0,1,1,1,0,
1,0,0,1,1,0,0,1,
1,1,1,1,1,1,1,1,
0,1,1,1,0,1,1,0,
]
}, },
], ],
name: None, name: None,
@ -74,21 +54,14 @@ pub fn tile_default() -> Tile {
id: 10, id: 10,
name: None, name: None,
wall: None, wall: None,
animation_frames: vec![ animation_frames: vec![Image {
Image {
pixels: vec![ pixels: vec![
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,
1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,
1,0,0,1,1,0,0,1,
1,0,0,1,1,0,0,1,
1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,
]
}
], ],
colour_id: None }],
colour_id: None,
} }
} }
@ -96,20 +69,13 @@ pub fn sprite() -> Sprite {
Sprite { Sprite {
id: 10, id: 10,
name: Some("hatch".to_string()), name: Some("hatch".to_string()),
animation_frames: vec![ animation_frames: vec![Image {
Image {
pixels: vec![ pixels: vec![
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1,
0,1,1,1,1,0,0,0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0,
0,1,0,0,1,0,0,0,
0,0,1,1,1,1,0,0,
0,0,1,1,1,1,0,0,
0,1,0,1,1,1,1,0,
0,1,0,1,1,1,1,0,
0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1,
]
}
], ],
}],
dialogue_id: Some("SPR_0".to_string()), dialogue_id: Some("SPR_0".to_string()),
room_id: Some(4), room_id: Some(4),
position: Some(Position { x: 9, y: 7 }), position: Some(Position { x: 9, y: 7 }),
@ -120,23 +86,16 @@ pub fn sprite() -> Sprite {
pub fn item() -> Item { pub fn item() -> Item {
Item { Item {
id: 6, id: 6,
animation_frames: vec![ animation_frames: vec![Image {
Image {
pixels: vec![ pixels: vec![
0,1,0,0,0,0,0,0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,1,0,0,
0,0,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
]
}
], ],
}],
name: Some("door".to_string()), name: Some("door".to_string()),
dialogue_id: Some("ITM_2".to_string()), dialogue_id: Some("ITM_2".to_string()),
colour_id: None colour_id: None,
} }
} }
@ -146,43 +105,297 @@ pub fn room() -> Room {
palette_id: Some(9), palette_id: Some(9),
name: Some("cellar 7".to_string()), name: Some("cellar 7".to_string()),
tiles: vec![ tiles: vec![
"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"1l".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(), "0".to_string(),
"y".to_string(),"x".to_string(),"0".to_string(),"0".to_string(),"1j".to_string(),"0".to_string(),"0".to_string(),"1j".to_string(),"1l".to_string(),"0".to_string(),"1j".to_string(),"0".to_string(),"0".to_string(),"1j".to_string(),"0".to_string(),"0".to_string(), "0".to_string(),
"y".to_string(),"y".to_string(),"x".to_string(),"k".to_string(),"k".to_string(),"1c".to_string(),"1x".to_string(),"1y".to_string(),"1m".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(), "0".to_string(),
"y".to_string(),"y".to_string(),"y".to_string(),"x".to_string(),"k".to_string(),"s".to_string(),"s".to_string(),"s".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"1g".to_string(),"1f".to_string(),"k".to_string(), "0".to_string(),
"k".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"1i".to_string(),"1u".to_string(),"1u".to_string(),"1u".to_string(),"1v".to_string(),"11".to_string(),"19".to_string(),"1b".to_string(),"1a".to_string(),"1e".to_string(),"10".to_string(),"k".to_string(), "0".to_string(),
"k".to_string(),"z".to_string(),"z".to_string(),"11".to_string(),"12".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"10".to_string(),"17".to_string(),"z".to_string(),"18".to_string(),"1e".to_string(),"12".to_string(),"k".to_string(), "0".to_string(),
"k".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"1k".to_string(),"14".to_string(),"15".to_string(),"16".to_string(),"1h".to_string(),"z".to_string(),"k".to_string(), "0".to_string(),
"k".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"10".to_string(),"1d".to_string(),"1v".to_string(),"1r".to_string(),"1s".to_string(),"1r".to_string(),"1q".to_string(),"1z".to_string(),"k".to_string(), "0".to_string(),
"k".to_string(),"z".to_string(),"z".to_string(),"12".to_string(),"10".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"1i".to_string(),"1n".to_string(),"1o".to_string(),"1o".to_string(),"1o".to_string(),"1p".to_string(),"z".to_string(),"k".to_string(), "1l".to_string(),
"k".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"10".to_string(),"z".to_string(),"z".to_string(),"k".to_string(), "0".to_string(),
"k".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"11".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"k".to_string(), "0".to_string(),
"k".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"z".to_string(),"12".to_string(),"z".to_string(),"z".to_string(),"10".to_string(),"12".to_string(),"k".to_string(), "0".to_string(),
"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(),"k".to_string(), "0".to_string(),
"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string() "0".to_string(),
"y".to_string(),
"x".to_string(),
"0".to_string(),
"0".to_string(),
"1j".to_string(),
"0".to_string(),
"0".to_string(),
"1j".to_string(),
"1l".to_string(),
"0".to_string(),
"1j".to_string(),
"0".to_string(),
"0".to_string(),
"1j".to_string(),
"0".to_string(),
"0".to_string(),
"y".to_string(),
"y".to_string(),
"x".to_string(),
"k".to_string(),
"k".to_string(),
"1c".to_string(),
"1x".to_string(),
"1y".to_string(),
"1m".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"y".to_string(),
"y".to_string(),
"y".to_string(),
"x".to_string(),
"k".to_string(),
"s".to_string(),
"s".to_string(),
"s".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"1g".to_string(),
"1f".to_string(),
"k".to_string(),
"k".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"1i".to_string(),
"1u".to_string(),
"1u".to_string(),
"1u".to_string(),
"1v".to_string(),
"11".to_string(),
"19".to_string(),
"1b".to_string(),
"1a".to_string(),
"1e".to_string(),
"10".to_string(),
"k".to_string(),
"k".to_string(),
"z".to_string(),
"z".to_string(),
"11".to_string(),
"12".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"10".to_string(),
"17".to_string(),
"z".to_string(),
"18".to_string(),
"1e".to_string(),
"12".to_string(),
"k".to_string(),
"k".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"1k".to_string(),
"14".to_string(),
"15".to_string(),
"16".to_string(),
"1h".to_string(),
"z".to_string(),
"k".to_string(),
"k".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"10".to_string(),
"1d".to_string(),
"1v".to_string(),
"1r".to_string(),
"1s".to_string(),
"1r".to_string(),
"1q".to_string(),
"1z".to_string(),
"k".to_string(),
"k".to_string(),
"z".to_string(),
"z".to_string(),
"12".to_string(),
"10".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"1i".to_string(),
"1n".to_string(),
"1o".to_string(),
"1o".to_string(),
"1o".to_string(),
"1p".to_string(),
"z".to_string(),
"k".to_string(),
"k".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"10".to_string(),
"z".to_string(),
"z".to_string(),
"k".to_string(),
"k".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"11".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"k".to_string(),
"k".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"z".to_string(),
"12".to_string(),
"z".to_string(),
"z".to_string(),
"10".to_string(),
"12".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"k".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
], ],
items: vec![ items: vec![
Instance {position: Position { x: 11, y: 5}, id: "d".to_string()}, Instance {
Instance {position: Position { x: 8, y: 3}, id: "e".to_string()}, position: Position { x: 11, y: 5 },
Instance {position: Position { x: 1, y: 0}, id: "5".to_string()}, id: "d".to_string(),
Instance {position: Position { x: 2, y: 1}, id: "6".to_string()}, },
Instance {position: Position { x: 3, y: 2}, id: "6".to_string()}, Instance {
position: Position { x: 8, y: 3 },
id: "e".to_string(),
},
Instance {
position: Position { x: 1, y: 0 },
id: "5".to_string(),
},
Instance {
position: Position { x: 2, y: 1 },
id: "6".to_string(),
},
Instance {
position: Position { x: 3, y: 2 },
id: "6".to_string(),
},
], ],
exits: vec![ exits: vec![ExitInstance {
ExitInstance {
position: Position { x: 3, y: 3 }, position: Position { x: 3, y: 3 },
exit: Exit { exit: Exit {
room_id: 3, room_id: 3,
position: Position { x: 10, y: 6 }, position: Position { x: 10, y: 6 },
effect: Transition::None effect: Transition::None,
}
}, },
], }],
endings: vec![ endings: vec![Instance {
Instance{position: Position { x: 8, y: 7 }, id: "undefined".to_string()}, position: Position { x: 8, y: 7 },
], id: "undefined".to_string(),
}],
walls: vec![], walls: vec![],
} }
} }
@ -195,115 +408,336 @@ pub fn game_default() -> Game {
font: Font::AsciiSmall, font: Font::AsciiSmall,
custom_font: None, custom_font: None,
text_direction: TextDirection::LeftToRight, text_direction: TextDirection::LeftToRight,
palettes: vec![ palettes: vec![Palette {
Palette {
id: 0, id: 0,
name: None, name: None,
colours: vec![ colours: vec![
Colour {red: 0, green: 82, blue: 204 }, Colour {
Colour {red: 128, green: 159, blue: 255 }, red: 0,
Colour {red: 255, green: 255, blue: 255 }, green: 82,
] blue: 204,
} },
Colour {
red: 128,
green: 159,
blue: 255,
},
Colour {
red: 255,
green: 255,
blue: 255,
},
], ],
rooms: vec![ }],
Room { rooms: vec![Room {
id: 0, id: 0,
palette_id: Some(0), palette_id: Some(0),
name: None, name: None,
tiles: vec![ tiles: vec![
"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"a".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(),"0".to_string(), "0".to_string(),
"0".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"a".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
"0".to_string(),
], ],
items: vec![], items: vec![],
exits: vec![], exits: vec![],
endings: vec![], endings: vec![],
walls: vec![] walls: vec![],
} }],
], tiles: vec![self::tile_default()],
tiles: vec![
self::tile_default(),
],
avatar: Avatar { avatar: Avatar {
animation_frames: vec![ animation_frames: vec![Image {
Image {
pixels: vec![ pixels: vec![
0,0,0,1,1,0,0,0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
0,0,0,1,1,0,0,0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0,
0,0,0,1,1,0,0,0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
0,0,1,1,1,1,0,0,
0,1,1,1,1,1,1,0,
1,0,1,1,1,1,0,1,
0,0,1,0,0,1,0,0,
0,0,1,0,0,1,0,0,
]
}
], ],
}],
name: None, name: None,
room_id: 0, room_id: 0,
position: Position { x: 4, y: 4 }, position: Position { x: 4, y: 4 },
colour_id: None, colour_id: None,
}, },
sprites: vec![ sprites: vec![Sprite {
Sprite {
id: 10, id: 10,
name: None, name: None,
animation_frames: vec![ animation_frames: vec![Image {
Image {
pixels: vec![ pixels: vec![
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1,
0,0,0,0,0,0,0,0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1,
0,1,0,1,0,0,0,1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
0,1,1,1,0,0,0,1,
0,1,1,1,0,0,1,0,
0,1,1,1,1,1,0,0,
0,0,1,1,1,1,0,0,
0,0,1,0,0,1,0,0,
]
}
], ],
}],
dialogue_id: Some("SPR_0".to_string()), dialogue_id: Some("SPR_0".to_string()),
room_id: Some(0), room_id: Some(0),
position: Some(Position { x: 8, y: 12 }), position: Some(Position { x: 8, y: 12 }),
colour_id: None, colour_id: None,
} }],
], items: vec![Item {
items: vec![
Item {
id: 0, id: 0,
animation_frames: vec![ animation_frames: vec![Image {
Image {
pixels: vec![ pixels: vec![
0,0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,0,0,0,0,0,0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1,
0,0,0,0,0,0,0,0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,0,1,1,1,1,0,0,
0,1,1,0,0,1,0,0,
0,0,1,0,0,1,0,0,
0,0,0,1,1,0,0,0,
0,0,0,0,0,0,0,0,
]
},
], ],
}],
name: Some("tea".to_string()), name: Some("tea".to_string()),
dialogue_id: Some("ITM_0".to_string()), dialogue_id: Some("ITM_0".to_string()),
colour_id: None colour_id: None,
}, }],
],
dialogues: vec![ dialogues: vec![
Dialogue { Dialogue {
id: "SPR_0".to_string(), id: "SPR_0".to_string(),
@ -315,8 +749,9 @@ pub fn game_default() -> Game {
}, },
], ],
endings: vec![], endings: vec![],
variables: vec![ variables: vec![Variable {
Variable { id: "a".to_string(), initial_value: "42".to_string() } id: "a".to_string(),
], initial_value: "42".to_string(),
}],
} }
} }

View File

@ -21,9 +21,10 @@ impl From<String> for Palette {
let colour_start_index = if name.is_some() { 2 } else { 1 }; let colour_start_index = if name.is_some() { 2 } else { 1 };
let colours = lines[colour_start_index..].iter().map(|&line| { let colours = lines[colour_start_index..]
Colour::from(line.to_string()) .iter()
}).collect(); .map(|&line| Colour::from(line.to_string()))
.collect();
Palette { id, name, colours } Palette { id, name, colours }
} }
@ -50,17 +51,27 @@ impl ToString for Palette {
#[test] #[test]
fn test_palette_from_string() { fn test_palette_from_string() {
let output = Palette::from( let output = Palette::from("PAL 1\nNAME lamplight\n45,45,59\n66,60,39\n140,94,1".to_string());
"PAL 1\nNAME lamplight\n45,45,59\n66,60,39\n140,94,1".to_string()
);
let expected = Palette { let expected = Palette {
id: 1, id: 1,
name: Some("lamplight".to_string()), name: Some("lamplight".to_string()),
colours: vec![ colours: vec![
Colour {red: 45, green: 45, blue: 59}, Colour {
Colour {red: 66, green: 60, blue: 39}, red: 45,
Colour {red: 140, green: 94, blue: 1 }, green: 45,
blue: 59,
},
Colour {
red: 66,
green: 60,
blue: 39,
},
Colour {
red: 140,
green: 94,
blue: 1,
},
], ],
}; };
@ -69,17 +80,27 @@ fn test_palette_from_string() {
#[test] #[test]
fn test_palette_from_string_no_name() { fn test_palette_from_string_no_name() {
let output = Palette::from( let output = Palette::from("PAL 9\n45,45,59\n66,60,39\n140,94,1".to_string());
"PAL 9\n45,45,59\n66,60,39\n140,94,1".to_string()
);
let expected = Palette { let expected = Palette {
id: 9, id: 9,
name: None, name: None,
colours: vec![ colours: vec![
Colour {red: 45, green: 45, blue: 59}, Colour {
Colour {red: 66, green: 60, blue: 39}, red: 45,
Colour {red: 140, green: 94, blue: 1 }, green: 45,
blue: 59,
},
Colour {
red: 66,
green: 60,
blue: 39,
},
Colour {
red: 140,
green: 94,
blue: 1,
},
], ],
}; };
@ -92,11 +113,24 @@ fn test_palette_to_string() {
id: 16, id: 16,
name: Some("moss".to_string()), name: Some("moss".to_string()),
colours: vec![ colours: vec![
Colour {red: 1, green: 2, blue: 3 }, Colour {
Colour {red: 255, green: 254, blue: 253}, red: 1,
Colour {red: 126, green: 127, blue: 128}, green: 2,
] blue: 3,
}.to_string(); },
Colour {
red: 255,
green: 254,
blue: 253,
},
Colour {
red: 126,
green: 127,
blue: 128,
},
],
}
.to_string();
let expected = "PAL g\nNAME moss\n1,2,3\n255,254,253\n126,127,128".to_string(); let expected = "PAL g\nNAME moss\n1,2,3\n255,254,253\n126,127,128".to_string();
assert_eq!(output, expected); assert_eq!(output, expected);
} }

View File

@ -31,7 +31,10 @@ impl ToString for Position {
#[test] #[test]
fn test_position_from_string() { fn test_position_from_string() {
assert_eq!(Position::from("4,12".to_string()).unwrap(), Position { x: 4, y: 12 }); assert_eq!(
Position::from("4,12".to_string()).unwrap(),
Position { x: 4, y: 12 }
);
} }
#[test] #[test]

View File

@ -1,4 +1,4 @@
use crate::{Exit, ExitInstance, Instance, Position, from_base36, ToBase36, optional_data_line}; use crate::{from_base36, optional_data_line, Exit, ExitInstance, Instance, Position, ToBase36};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub struct Room { pub struct Room {
@ -66,7 +66,10 @@ impl From<String> for Room {
let position = item_position[1]; let position = item_position[1];
let position = Position::from(position.to_string()).unwrap(); let position = Position::from(position.to_string()).unwrap();
items.push(Instance { position, id: item_id.to_string() }); items.push(Instance {
position,
id: item_id.to_string(),
});
} else if last_line.starts_with("EXT") { } else if last_line.starts_with("EXT") {
let last_line = last_line.replace("EXT ", ""); let last_line = last_line.replace("EXT ", "");
let parts: Vec<&str> = last_line.split(' ').collect(); let parts: Vec<&str> = last_line.split(' ').collect();
@ -81,7 +84,10 @@ impl From<String> for Room {
let position = ending_position[1].to_string(); let position = ending_position[1].to_string();
let position = Position::from(position).unwrap(); let position = Position::from(position).unwrap();
endings.push(Instance { position, id: ending }); endings.push(Instance {
position,
id: ending,
});
} else { } else {
lines.push(last_line); lines.push(last_line);
break; break;
@ -95,7 +101,8 @@ impl From<String> for Room {
for line in lines.into_iter() { for line in lines.into_iter() {
let line: Vec<&str> = if line.contains(",") { let line: Vec<&str> = if line.contains(",") {
line.split(",").collect() line.split(",").collect()
} else { // old room format } else {
// old room format
line.split("").collect() line.split("").collect()
}; };
@ -108,7 +115,16 @@ impl From<String> for Room {
exits.reverse(); exits.reverse();
endings.reverse(); endings.reverse();
Room { id, palette_id, name, tiles, items, exits, endings, walls } Room {
id,
palette_id,
name,
tiles,
items,
exits,
endings,
walls,
}
} }
} }
@ -138,25 +154,27 @@ impl ToString for Room {
tiles.pop(); // remove trailing newline tiles.pop(); // remove trailing newline
for instance in &self.items { for instance in &self.items {
items.push_str( items.push_str(&format!(
&format!("\nITM {} {}", instance.id, instance.position.to_string()) "\nITM {} {}",
); instance.id,
instance.position.to_string()
));
} }
for instance in &self.exits { for instance in &self.exits {
exits.push_str( exits.push_str(&format!(
&format!(
"\nEXT {} {}", "\nEXT {} {}",
instance.position.to_string(), instance.position.to_string(),
instance.exit.to_string(), instance.exit.to_string(),
) ));
);
} }
for instance in &self.endings { for instance in &self.endings {
endings.push_str( endings.push_str(&format!(
&format!("\nEND {} {}", instance.id, instance.position.to_string()) "\nEND {} {}",
); instance.id,
instance.position.to_string()
));
} }
format!( format!(
@ -175,14 +193,15 @@ impl ToString for Room {
#[test] #[test]
fn test_room_to_string() { fn test_room_to_string() {
assert_eq!(crate::mock::room().to_string(), include_str!("test-resources/room").to_string()); assert_eq!(
crate::mock::room().to_string(),
include_str!("test-resources/room").to_string()
);
} }
#[test] #[test]
fn test_room_walls_array() { fn test_room_walls_array() {
let output = Room::from( let output = Room::from(include_str!("test-resources/room-with-walls").to_string());
include_str!("test-resources/room-with-walls").to_string()
);
assert_eq!(output.walls, vec![10, 15]); assert_eq!(output.walls, vec![10, 15]);
} }

View File

@ -1,4 +1,4 @@
use crate::{AnimationFrames, Image, Position, from_base36, ToBase36, optional_data_line}; use crate::{from_base36, optional_data_line, AnimationFrames, Image, Position, ToBase36};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub struct Sprite { pub struct Sprite {
@ -22,7 +22,11 @@ impl Sprite {
fn room_position_line(&self) -> String { fn room_position_line(&self) -> String {
if self.room_id.is_some() && self.position.is_some() { if self.room_id.is_some() && self.position.is_some() {
format!("\nPOS {} {}", self.room_id.unwrap().to_base36(), self.position.as_ref().unwrap().to_string()) format!(
"\nPOS {} {}",
self.room_id.unwrap().to_base36(),
self.position.as_ref().unwrap().to_string()
)
} else { } else {
"".to_string() "".to_string()
} }
@ -72,11 +76,20 @@ impl From<String> for Sprite {
// todo dedupe // todo dedupe
let animation_frames = lines[1..].join(""); let animation_frames = lines[1..].join("");
let animation_frames: Vec<&str> = animation_frames.split(">").collect(); let animation_frames: Vec<&str> = animation_frames.split(">").collect();
let animation_frames: Vec<Image> = animation_frames.iter().map(|&frame| { let animation_frames: Vec<Image> = animation_frames
Image::from(frame.to_string()) .iter()
}).collect(); .map(|&frame| Image::from(frame.to_string()))
.collect();
Sprite { id, name, animation_frames, dialogue_id, room_id, position, colour_id } Sprite {
id,
name,
animation_frames,
dialogue_id,
room_id,
position,
colour_id,
}
} }
} }
@ -97,9 +110,7 @@ impl ToString for Sprite {
#[test] #[test]
fn test_sprite_from_string() { fn test_sprite_from_string() {
let output = Sprite::from( let output = Sprite::from(include_str!("test-resources/sprite").to_string());
include_str!("test-resources/sprite").to_string()
);
let expected = crate::mock::sprite(); let expected = crate::mock::sprite();

View File

@ -1,4 +1,4 @@
use crate::{AnimationFrames, Image, from_base36, ToBase36, optional_data_line}; use crate::{from_base36, optional_data_line, AnimationFrames, Image, ToBase36};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub struct Tile { pub struct Tile {
@ -59,11 +59,18 @@ impl From<String> for Tile {
let animation_frames = lines[1..].join(""); let animation_frames = lines[1..].join("");
let animation_frames: Vec<&str> = animation_frames.split(">").collect(); let animation_frames: Vec<&str> = animation_frames.split(">").collect();
let animation_frames: Vec<Image> = animation_frames.iter().map(|&frame| { let animation_frames: Vec<Image> = animation_frames
Image::from(frame.to_string()) .iter()
}).collect(); .map(|&frame| Image::from(frame.to_string()))
.collect();
Tile { id, name, wall, animation_frames, colour_id } Tile {
id,
name,
wall,
animation_frames,
colour_id,
}
} }
} }
@ -89,12 +96,10 @@ fn test_tile_from_string() {
id: 35, id: 35,
name: Some("concrete 1".to_string()), name: Some("concrete 1".to_string()),
wall: Some(true), wall: Some(true),
animation_frames: vec![ animation_frames: vec![Image {
Image { pixels: vec![1; 64],
pixels: vec![1; 64] }],
} colour_id: None,
],
colour_id: None
}; };
assert_eq!(output, expected); assert_eq!(output, expected);
@ -110,8 +115,9 @@ fn test_tile_to_string() {
crate::mock::image::chequers_1(), crate::mock::image::chequers_1(),
crate::mock::image::chequers_2(), crate::mock::image::chequers_2(),
], ],
colour_id: None colour_id: None,
}.to_string(); }
.to_string();
let expected = include_str!("test-resources/tile-chequers").to_string(); let expected = include_str!("test-resources/tile-chequers").to_string();

View File

@ -25,13 +25,20 @@ impl ToString for Variable {
fn test_variable_from_string() { fn test_variable_from_string() {
assert_eq!( assert_eq!(
Variable::from("VAR a\n42".to_string()), Variable::from("VAR a\n42".to_string()),
Variable { id: "a".to_string(), initial_value: "42".to_string()} Variable {
id: "a".to_string(),
initial_value: "42".to_string()
}
); );
} }
#[test] #[test]
fn test_variable_to_string() { fn test_variable_to_string() {
let output = Variable { id: "c".to_string(), initial_value: "57".to_string() }.to_string(); let output = Variable {
id: "c".to_string(),
initial_value: "57".to_string(),
}
.to_string();
let expected = "VAR c\n57".to_string(); let expected = "VAR c\n57".to_string();
assert_eq!(output, expected); assert_eq!(output, expected);
} }