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, } 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) -> anyhow::Result { 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>, state: Option, } impl App { pub fn new(#[cfg(target_arch = "wasm32")] event_loop: &EventLoop) -> Self { #[cfg(target_arch = "wasm32")] let proxy = Some(event_loop.create_proxy()); Self { state: None, #[cfg(target_arch = "wasm32")] proxy, } } }