2020-04-13 13:30:08 +01:00
|
|
|
use radix_fmt::radix_36;
|
|
|
|
|
|
2020-04-12 13:41:27 +01:00
|
|
|
pub mod avatar;
|
2020-04-12 12:22:20 +01:00
|
|
|
pub mod colour;
|
2020-04-12 13:26:33 +01:00
|
|
|
pub mod dialogue;
|
2020-04-12 13:52:36 +01:00
|
|
|
pub mod ending;
|
2020-04-12 13:49:19 +01:00
|
|
|
pub mod exit;
|
2020-04-12 14:38:07 +01:00
|
|
|
pub mod game;
|
2020-04-12 12:48:07 +01:00
|
|
|
pub mod image;
|
2020-04-12 13:46:55 +01:00
|
|
|
pub mod item;
|
2020-04-12 13:50:07 +01:00
|
|
|
pub mod mock;
|
2020-04-18 15:58:30 +00:00
|
|
|
pub mod palette;
|
2020-04-12 13:21:27 +01:00
|
|
|
pub mod position;
|
2020-04-12 14:28:11 +01:00
|
|
|
pub mod room;
|
2020-04-12 13:35:17 +01:00
|
|
|
pub mod sprite;
|
2020-04-18 15:58:30 +00:00
|
|
|
pub mod text;
|
2020-04-12 12:53:11 +01:00
|
|
|
pub mod tile;
|
2020-04-12 14:20:53 +01:00
|
|
|
pub mod variable;
|
2020-04-12 12:22:20 +01:00
|
|
|
|
2020-04-12 13:41:27 +01:00
|
|
|
use avatar::Avatar;
|
2020-04-12 12:35:39 +01:00
|
|
|
use colour::Colour;
|
2020-04-12 13:26:33 +01:00
|
|
|
use dialogue::Dialogue;
|
2020-04-12 13:52:36 +01:00
|
|
|
use ending::Ending;
|
2020-04-18 15:58:30 +00:00
|
|
|
use exit::{Exit, Transition};
|
2020-04-18 11:03:24 +01:00
|
|
|
use game::{Game, Version};
|
2020-04-12 12:48:07 +01:00
|
|
|
use image::Image;
|
2020-04-12 13:46:55 +01:00
|
|
|
use item::Item;
|
2020-04-18 15:58:30 +00:00
|
|
|
use palette::Palette;
|
2020-04-12 13:21:27 +01:00
|
|
|
use position::Position;
|
2020-04-12 14:28:11 +01:00
|
|
|
use room::Room;
|
2020-04-12 13:35:17 +01:00
|
|
|
use sprite::Sprite;
|
2020-04-18 15:58:30 +00:00
|
|
|
use std::fmt::Display;
|
|
|
|
|
use text::{Font, TextDirection};
|
2020-04-12 12:53:11 +01:00
|
|
|
use tile::Tile;
|
2020-04-12 14:20:53 +01:00
|
|
|
use variable::Variable;
|
2020-04-05 18:58:04 +01:00
|
|
|
|
2020-04-10 16:27:23 +01:00
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
2020-04-12 12:53:11 +01:00
|
|
|
pub struct Instance {
|
2020-04-10 16:27:23 +01:00
|
|
|
position: Position,
|
2020-04-12 13:52:36 +01:00
|
|
|
id: String, // item / ending.rs id
|
2020-04-10 16:27:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
2020-04-12 12:53:11 +01:00
|
|
|
pub struct ExitInstance {
|
2020-04-10 16:27:23 +01:00
|
|
|
position: Position,
|
|
|
|
|
exit: Exit,
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-12 11:22:14 +01:00
|
|
|
pub trait AnimationFrames {
|
|
|
|
|
fn to_string(&self) -> String;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AnimationFrames for Vec<Image> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
|
let mut string = String::new();
|
|
|
|
|
let last_frame = self.len() - 1;
|
2020-04-06 07:23:20 +01:00
|
|
|
|
2020-04-12 11:22:14 +01:00
|
|
|
for (i, frame) in self.into_iter().enumerate() {
|
|
|
|
|
string.push_str(&frame.to_string());
|
2020-04-06 07:23:20 +01:00
|
|
|
|
2020-04-12 11:22:14 +01:00
|
|
|
if i < last_frame {
|
|
|
|
|
string.push_str(&"\n>\n".to_string());
|
|
|
|
|
}
|
2020-04-06 07:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-12 11:22:14 +01:00
|
|
|
string
|
|
|
|
|
}
|
2020-04-06 07:23:20 +01:00
|
|
|
}
|
2020-04-13 13:30:08 +01:00
|
|
|
|
|
|
|
|
fn from_base36(str: &str) -> u64 {
|
|
|
|
|
u64::from_str_radix(str, 36).unwrap()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_from_base36() {
|
|
|
|
|
assert_eq!(from_base36("0"), 0);
|
|
|
|
|
assert_eq!(from_base36("0z"), 35);
|
|
|
|
|
assert_eq!(from_base36("11"), 37);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 14:43:23 +01:00
|
|
|
/// this doesn't work inside ToBase36 for some reason
|
|
|
|
|
fn to_base36(int: u64) -> String {
|
|
|
|
|
format!("{}", radix_36(int))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait ToBase36 {
|
|
|
|
|
fn to_base36(&self) -> String;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ToBase36 for u64 {
|
|
|
|
|
fn to_base36(&self) -> String {
|
|
|
|
|
to_base36(*self)
|
|
|
|
|
}
|
2020-04-13 13:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_to_base36() {
|
2020-04-13 14:43:23 +01:00
|
|
|
assert_eq!((37 as u64).to_base36(), "11");
|
2020-04-13 13:30:08 +01:00
|
|
|
}
|
2020-04-13 19:08:21 +01:00
|
|
|
|
|
|
|
|
/// e.g. `\nNAME DLG_0`
|
|
|
|
|
fn optional_data_line<T: Display>(label: &str, item: Option<T>) -> String {
|
|
|
|
|
if item.is_some() {
|
|
|
|
|
format!("\n{} {}", label, item.unwrap())
|
|
|
|
|
} else {
|
|
|
|
|
"".to_string()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_optional_data_line() {
|
|
|
|
|
let output = optional_data_line("NAME", mock::item().name);
|
|
|
|
|
assert_eq!(output, "\nNAME door".to_string());
|
|
|
|
|
}
|