diff --git a/examples/test.rs b/examples/test.rs index 71ca54a..167f420 100644 --- a/examples/test.rs +++ b/examples/test.rs @@ -14,10 +14,10 @@ fn main() { impl Game for World { fn new(window_state: &mut WindowState) -> Self { - window_state.scramble_palette(); window_state.set_palette(0, 0xc0, 0xf0, 0xd0); + window_state.scramble_palette(); Self { - img: Image::load("examples/assets/test.gif"), + img: Image::load_data(include_bytes!("assets/test.gif")), pos: Vec2::zero(), } } diff --git a/src/image.rs b/src/image.rs index 5210581..6a9749d 100644 --- a/src/image.rs +++ b/src/image.rs @@ -1,4 +1,5 @@ use crate::vec2::Vec2; +use std::fs; use std::fs::File; //todo: make dynamically different bitdepths @@ -16,10 +17,13 @@ impl Image { } pub fn load(path: &str) -> Self { - let input = File::open(path).unwrap(); + Self::load_data(fs::read(path).unwrap().as_slice()) + } + + pub fn load_data(data: &[u8]) -> Self { let mut options = gif::DecodeOptions::new(); options.set_color_output(gif::ColorOutput::Indexed); - let mut decoder = options.read_info(input).unwrap(); + let mut decoder = options.read_info(data).unwrap(); let x = decoder.width(); let y = decoder.height(); diff --git a/src/window.rs b/src/window.rs index 4680787..e971f44 100644 --- a/src/window.rs +++ b/src/window.rs @@ -103,8 +103,12 @@ pub fn run(width: i32, height: i32) { WindowEvent::Focused(_) => {} WindowEvent::KeyboardInput { input, .. } => { //todo: actually do input handling - if input.virtual_keycode.unwrap() == Escape { - *control_flow = ControlFlow::Exit; + if let Some(k) = input.virtual_keycode { + if k == Escape { + *control_flow = ControlFlow::Exit; + } + }; + if *control_flow == ControlFlow::Exit { return; } }