54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
use std::sync::Arc;
|
|
|
|
use winit::{
|
|
application::ApplicationHandler, event::*, event_loop::{ActiveEventLoop, EventLoop}, keyboard::{KeyCode, PhysicalKey}, window::Window
|
|
};
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
use wasm_bindgen::prelude::*;
|
|
#[cfg(target_arch = "wasm32")]
|
|
use winit::platform::web::EventLoopExtWebSys;
|
|
|
|
// This will store the state of our game
|
|
pub struct State {
|
|
window: Arc<Window>,
|
|
}
|
|
|
|
impl State {
|
|
// We don't need this to be async right now,
|
|
// but we will in the next tutorial
|
|
pub async fn new(window: Arc<Window>) -> anyhow::Result<Self> {
|
|
Ok(Self {
|
|
window,
|
|
})
|
|
}
|
|
|
|
pub fn resize(&mut self, _width: u32, _height: u32) {
|
|
// We'll do stuff here in the next tutorial
|
|
}
|
|
|
|
pub fn render(&mut self) {
|
|
self.window.request_redraw();
|
|
|
|
// We'll do more stuff here in the next tutorial
|
|
}
|
|
}
|
|
|
|
pub struct App {
|
|
#[cfg(target_arch = "wasm32")]
|
|
proxy: Option<winit::event_loop::EventLoopProxy<State>>,
|
|
state: Option<State>,
|
|
}
|
|
|
|
impl App {
|
|
pub fn new(#[cfg(target_arch = "wasm32")] event_loop: &EventLoop<State>) -> Self {
|
|
#[cfg(target_arch = "wasm32")]
|
|
let proxy = Some(event_loop.create_proxy());
|
|
Self {
|
|
state: None,
|
|
#[cfg(target_arch = "wasm32")]
|
|
proxy,
|
|
}
|
|
}
|
|
}
|