~starkingdoms/starkingdoms

ref: e378598a9c714b9d9fbb7d33947bae464c4f1aaa starkingdoms/crates/client/src/lib.rs -rw-r--r-- 2.1 KiB
e378598a — core asset system cleanup 8 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
76
77
78
79
80
81
use bevy_ecs::{event::Events, world::World};
use components::{Camera, Chat, Part, Player, RecvPacket, SendPacket, Texture, Transform};
use nalgebra::{Rotation2, Scale3, Translation3};
use networking::ws::Ws;
use rendering::App;
use platform::assets::Assets;
use tracing::info;
use winit::event_loop::{ControlFlow, EventLoop};
use crate::components::PlayerResources;
use rendering::assets::AssetLoader;

#[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 components;
pub mod networking;
pub mod rendering;
pub mod ui;

// 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(Camera {
        x: 0.0,
        y: 0.0,
        zoom: 1.0,
        width: 0,
        height: 0,
    });

    world.insert_resource(Assets::new());
    world.insert_resource(Ws::new());
    world.insert_resource(PlayerResources {
        fuel_amount: 0,
        fuel_max: 0,
    });
    world.insert_resource(Chat {
        messages: vec![
        ],
        textbox: String::new(),
    });

    let send_packet_events = Events::<SendPacket>::default();
    let recv_packet_events = Events::<RecvPacket>::default();

    world.spawn((
        Transform {
            translation: Translation3::new(0.0, 0.0, 0.0),
            rotation: Rotation2::new(0.0),
            scale: Scale3::new(25.0, 25.0, 1.0),
        },
        Texture {
            name: "hearty.svg".to_string(),
        },
        Player,
        Part(false),
    ));

    let event_loop = EventLoop::new().unwrap();
    event_loop.set_control_flow(ControlFlow::Wait);

    event_loop
        .run_app(&mut App::new(world, send_packet_events, recv_packet_events))
        .unwrap();
}