Skip to content

Instantly share code, notes, and snippets.

@jasonroelofs
Created September 10, 2014 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonroelofs/5abe54ddbc1d040aa559 to your computer and use it in GitHub Desktop.
Save jasonroelofs/5abe54ddbc1d040aa559 to your computer and use it in GitHub Desktop.
/// All config-related options handled here
extern crate serialize;
use std::collections::HashMap;
use std::path::posix::Path;
use std::io::File;
use serialize::json;
#[deriving(Decodable, Encodable, Show)]
pub struct Keybindings {
pub key_maps : HashMap<String, String>
}
#[deriving(Decodable, Encodable, Show)]
pub struct WindowOptions {
pub width: u32,
pub height: u32,
pub fullscreen: bool,
}
#[deriving(Decodable, Encodable, Show)]
pub struct GameConfig {
pub input : Keybindings,
pub window : WindowOptions
}
impl GameConfig {
pub fn new(json_file: Path) -> GameConfig {
let json_contents = File::open(&json_file).read_to_end();
let config : GameConfig = json::decode(&json_contents);
println!("{}", config);
config
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment