use bevy::prelude::*; use bevy_rapier2d::prelude::{AdditionalMassProperties, Collider, ReadMassProperties, RigidBody}; use bevy_replicon::prelude::{ConnectedClient, Replicated}; use crate::ecs::{Part, PartBundle}; use crate::server::world_config::WorldConfigResource; pub fn player_management_plugin(mut app: &mut App) { app.add_systems(Update, handle_new_players); } fn handle_new_players(mut commands: Commands, q_new_clients: Query>, world_config: Res) { let Some(wc) = &world_config.config else { return; }; for joined_player in &q_new_clients { commands.entity(joined_player) .insert(PartBundle { part: Part { sprite: "textures/hearty.png".to_string(), width: wc.part.default_width, height: wc.part.default_height, mass: wc.part.default_mass }, transform: Transform::from_xyz(500.0, 0.0, 0.0), // todo, collider: Collider::cuboid(wc.part.default_width / 2.0, wc.part.default_height / 2.0), additional_mass_properties: AdditionalMassProperties::Mass(wc.part.default_mass) }) .insert(ReadMassProperties::default()) .insert(RigidBody::Dynamic) .insert(Replicated); } }