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::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, Part, Player}; 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, STARGUIDE_LAYER}; 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, } 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())); }) .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) .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, asset_server: Res, ) { 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); /*let mut heart_sprite = Sprite::from_image(asset_server.load("sprites/hearty_heart.png")); heart_sprite.custom_size = Some(Vec2::new( part.strong_config.physics.width, part.strong_config.physics.height, )); heart_sprite.color = Color::srgb(20.0, 0.0, 0.0); commands.spawn(( ChildOf(entity), heart_sprite, Transform::from_xyz(0.0, 0.0, 10.0), )); */ } }