~starkingdoms/starkingdoms

ref: e2c74ff0a4af609afb2869c59835838dd76f639c starkingdoms/crates/unified/src/client/mod.rs -rw-r--r-- 3.0 KiB
e2c74ff0 — core Revert "aaa ??? ?? ? ?? ???????????????????????????????????????????? i would like to explosion" 9 days 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
82
83
84
85
86
87
88
89
use crate::client::key_input::key_input_plugin;
use crate::client::parts::parts_plugin;
use crate::client::planet::indicators::indicators_plugin;
use crate::client::starfield::starfield_plugin;
use crate::client::starguide::orbit::starguide_orbit_plugin;
use crate::client::ui::ui_plugin;
use crate::client::zoom::zoom_plugin;
use crate::client::starguide::init::starguide_init_plugin;
use crate::client::starguide::input::starguide_input_plugin;
use crate::ecs::{Hi, StarguideGizmos};
use aeronet_websocket::client::WebSocketClient;
use bevy::dev_tools::picking_debug::DebugPickingMode;
use crate::prelude::*;
use planet::incoming_planets::incoming_planets_plugin;
use crate::client::ship::attachment::client_attachment_plugin;
use crate::ecs::{Me, GameplayState};

pub mod colors;
pub mod key_input;
pub mod net;
pub mod particles;
pub mod parts;
pub mod planet;
pub mod starfield;
pub mod ui;
pub mod zoom;
pub mod ship;
pub mod rendering;
pub mod input;
pub mod starguide;

pub struct ClientPlugin {
    pub server: Option<String>,
}
impl Plugin for ClientPlugin {
    fn build(&self, app: &mut App) {
        let server = self.server.clone();
        app

            .add_systems(Startup, move |mut commands: Commands| {
                let Some(server) = server.as_ref() else { return };
                let config = net::websocket_config();

                commands
                    .spawn(Name::new("default-session"))
                    .queue(WebSocketClient::connect(config, server.clone()));
            })
            .init_gizmo_group::<StarguideGizmos>()
            .add_plugins(rendering::render_plugin)
            .add_plugins(input::input_plugin)
            .add_plugins(ship::thrusters::client_thrusters_plugin)
            .add_systems(Update, find_me)
            .add_systems(Update, net::set_config)
            .add_plugins((incoming_planets_plugin, indicators_plugin))
            .add_plugins(parts_plugin)
            .add_plugins(key_input_plugin)
            .add_plugins(starfield_plugin)
            .add_plugins(ui_plugin)
            .add_plugins(zoom_plugin)
            .add_plugins(client_attachment_plugin)
            .add_plugins(starguide_init_plugin)
            .add_plugins(starguide_input_plugin)
            .add_plugins(starguide_orbit_plugin)
            .insert_state(GameplayState::Main)
            .insert_resource(DebugPickingMode::Disabled);

        // These are only needed if we're actually doing network things
        if self.server.is_some() {
            app.add_observer(net::on_connecting)
                .add_observer(net::on_connected)
                .add_observer(net::on_disconnected);
        }
    }
}



fn find_me(
    mut commands: Commands,
    mut reader: MessageReader<Hi>,
) {
    for msg in reader.read() {
        info!("^^^^^^^^^^^ IGNORE THESE WARNINGS ^^^^^^^^^^^^^^");
        info!("they are normal! and are from the world state being replicated as it is sent over the network");
        info!(?msg, "finding me: got hello from server");
        commands.entity(msg.you_are).insert(Me);
    }
}