~starkingdoms/starkingdoms

ref: efdb9b1995399003b2f5cba85c1513ce3ec32504 starkingdoms/starkingdoms-client/src/lib.rs -rw-r--r-- 2.2 KiB
efdb9b19 — core add things 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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");
            });
    }
}