peachy/src/lib.rs

142 lines
3.1 KiB
Rust
Raw Normal View History

2020-09-02 16:50:13 +00:00
use std::fs;
use std::path::PathBuf;
2020-09-02 16:50:13 +00:00
use serde_derive::{Serialize, Deserialize};
mod colour;
mod config;
mod image;
mod mock;
mod palette;
mod room;
2020-09-02 16:50:13 +00:00
pub use colour::Colour;
pub use palette::Palette;
use crate::config::Config;
2020-09-02 16:50:13 +00:00
#[derive(Eq, Hash, PartialEq)]
pub struct Position {
x: u8,
y: u8,
}
// #[derive(Serialize, Deserialize)]
// pub struct Thing {
// name: Option<String>,
// /// image name
// image: String,
// }
//
// #[derive(Serialize, Deserialize)]
// pub enum DataType {
// Image,
// Integer,
// Palette,
// Room,
// Script,
// String,
// Thing,
// Variable,
// }
//
// /// todo refactor, this is stupid
// #[derive(Serialize, Deserialize)]
// pub struct Value {
// data_type: DataType,
// image: Option<String>,
// integer: Option<u64>,
// palette: Option<String>,
// room: Option<String>,
// script: Option<String>,
// string: Option<String>,
// thing: Option<String>,
// variable: Option<String>,
// }
//
// #[derive(Serialize, Deserialize)]
// pub struct Variable {
// name: String,
// data_type: DataType,
// default: Value,
// }
//
// #[derive(Serialize, Deserialize)]
// pub struct Parameter {
// name: String,
// data_type: DataType,
// default: Value,
// }
//
// #[derive(Serialize, Deserialize)]
// pub struct Script {
// name: Option<String>,
// params: Vec<Parameter>,
// script: String,
// }
//
// #[derive(Serialize, Deserialize)]
// pub struct ScriptInstance {
// script: String,
// params: HashMap<String, Value>,
// }
//
// #[derive(Serialize, Deserialize)]
// pub struct ScriptCollection {
// scripts: Vec<ScriptInstance>,
// /// as well as many named scripts, a trigger can have one anonymous script
// anonymous: Option<String>,
// }
//
// #[derive(Serialize, Deserialize)]
// pub struct Version {
// major: u8,
// minor: u8,
// }
//
// impl Version {
// pub fn default() -> Version {
// Version { major: 0, minor: 1 }
// }
// }
#[derive(Serialize, Deserialize)]
pub struct Game {
config: Config,
// palettes: Vec<Palette>,
// variables: Vec<Variable>,
// triggers: HashMap<String, ScriptCollection>,
}
#[derive(Debug)]
pub struct GameParseError;
2020-09-02 16:50:13 +00:00
impl Game {
pub fn from(path: String) -> Result<Game, GameParseError> {
let path = PathBuf::from(path);
2020-09-02 16:50:13 +00:00
let mut palettes_dir = path.clone();
palettes_dir.push("palettes");
let palette_files = palettes_dir.read_dir()
.expect("couldn't find any palettes");
2020-09-02 16:50:13 +00:00
for file in palette_files {
let file = file.unwrap();
println!("palette found: {:?}", file.file_name());
2020-09-02 16:50:13 +00:00
}
// todo load config
let mut game_config = path.clone();
game_config.push("game.toml");
let config = fs::read_to_string(game_config)
.expect("Couldn't load game config");
let config: Config = toml::from_str(&config)
.expect("Couldn't parse game config");
Ok(
Game {
config,
2020-09-02 16:50:13 +00:00
}
)
2020-09-02 16:50:13 +00:00
}
}