Created
September 10, 2014 01:32
-
-
Save jasonroelofs/5abe54ddbc1d040aa559 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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