From 09b5b329f417d87cb2a25317f3fb366a46039447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9amus=20Knightly?= Date: Tue, 4 Aug 2026 13:49:48 +0100 Subject: [PATCH] Added State and App Structs --- src/main.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..1b63e1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,53 @@ -fn main() { - println!("Hello, world!"); +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, + } + } }