use std::ops::Add;
use std::time::Duration;
use bevy_ecs::event::Events;
use bevy_ecs::schedule::Schedule;
use bevy_ecs::world::World;
use egui::Context;
use tracing::info;
use web_time::Instant;
use winit::event_loop::{ControlFlow, EventLoop};
use crate::ecs::{Camera, Position, Scale, SpriteBundle, SpriteTexture};
use crate::input::MouseWheelEvent;
use crate::rendering::App;
use crate::rendering::ui::UiRenderable;
#[cfg(target_arch = "wasm32")]
#[path = "wasm/mod.rs"]
pub mod platform;
#[cfg(not(target_arch = "wasm32"))]
#[path = "native/mod.rs"]
pub mod platform;
pub mod ecs;
pub mod input;
pub mod rendering;
// Hi, you've found the real main function! This is called AFTER platform-specific initialization code.
pub fn start() {
info!("Hello, world! StarKingdoms.TK v{} says hello, running on {}", env!("CARGO_PKG_VERSION"), if cfg!(target_arch = "wasm32") { "wasm" } else { "native" });
info!("Creating the ECS world...");
let mut world = World::new();
world.insert_resource::<Events<MouseWheelEvent>>(Events::default());
world.insert_resource(Camera {
x: 0.0,
y: 0.0,
zoom: 1.0,
});
let mut start_schedule = Schedule::default();
// Add startup things here
// Caution: This will run before there are things on-screen
start_schedule.run(&mut world);
let mut update_schedule = Schedule::default();
// Add things to run every frame here
// Caution: This will run once before there are things on screen
world.spawn(SpriteBundle {
position: Position { x: 0.0, y: 0.0 },
scale: Scale { width: 50.0, height: 50.0 },
texture: SpriteTexture { texture: "happy-tree".to_string() },
});
let event_loop = EventLoop::new().unwrap();
event_loop.set_control_flow(ControlFlow::Poll);
event_loop.run_app(&mut App::new(
world,
update_schedule,
Gui {}
)).unwrap();
}
pub struct Gui {}
impl UiRenderable for Gui {
fn render(&mut self, ctx: &Context, world: &mut World) {
egui::Window::new("Main Menu")
.resizable(false)
.show(ctx, |ui| {
ui.heading("StarKingdoms.TK");
ui.label("A game about floating through space");
});
}
}