added load_data for image
This commit is contained in:
parent
2ee1c46cb9
commit
a8aecacbdf
|
@ -14,10 +14,10 @@ fn main() {
|
||||||
|
|
||||||
impl Game for World {
|
impl Game for World {
|
||||||
fn new(window_state: &mut WindowState) -> Self {
|
fn new(window_state: &mut WindowState) -> Self {
|
||||||
window_state.scramble_palette();
|
|
||||||
window_state.set_palette(0, 0xc0, 0xf0, 0xd0);
|
window_state.set_palette(0, 0xc0, 0xf0, 0xd0);
|
||||||
|
window_state.scramble_palette();
|
||||||
Self {
|
Self {
|
||||||
img: Image::load("examples/assets/test.gif"),
|
img: Image::load_data(include_bytes!("assets/test.gif")),
|
||||||
pos: Vec2::zero(),
|
pos: Vec2::zero(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::vec2::Vec2;
|
use crate::vec2::Vec2;
|
||||||
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
//todo: make dynamically different bitdepths
|
//todo: make dynamically different bitdepths
|
||||||
|
@ -16,10 +17,13 @@ impl Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(path: &str) -> Self {
|
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();
|
let mut options = gif::DecodeOptions::new();
|
||||||
options.set_color_output(gif::ColorOutput::Indexed);
|
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 x = decoder.width();
|
||||||
let y = decoder.height();
|
let y = decoder.height();
|
||||||
|
|
|
@ -103,8 +103,12 @@ pub fn run<T: Game + 'static>(width: i32, height: i32) {
|
||||||
WindowEvent::Focused(_) => {}
|
WindowEvent::Focused(_) => {}
|
||||||
WindowEvent::KeyboardInput { input, .. } => {
|
WindowEvent::KeyboardInput { input, .. } => {
|
||||||
//todo: actually do input handling
|
//todo: actually do input handling
|
||||||
if input.virtual_keycode.unwrap() == Escape {
|
if let Some(k) = input.virtual_keycode {
|
||||||
|
if k == Escape {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if *control_flow == ControlFlow::Exit {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue