diff options
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/src/client.rs b/src/client.rs index b71b83c..aa073ab 100644 --- a/src/client.rs +++ b/src/client.rs @@ -10,6 +10,7 @@ use crate::shared::faction::*; use crate::shared::health::*; use crate::shared::health_event::*; use crate::shared::imperative::*; +use crate::shared::name::*; use crate::shared::player::*; use crate::shared::projectile::*; use crate::shared::shape::*; @@ -36,6 +37,7 @@ pub fn main( champion: Champion, faction: Faction, scale_factor: f32, + name: String, ) { App::new() .add_plugins(DefaultPlugins.set(WindowPlugin { @@ -51,6 +53,7 @@ pub fn main( transport, champion, faction, + name, }) .run(); } @@ -65,6 +68,9 @@ struct MyChampion(pub Champion); struct MyFaction(pub Faction); #[derive(Resource)] +struct MyName(String); + +#[derive(Resource)] struct Attack(Option<AbilitySlot>); #[derive(Resource, Default)] @@ -79,6 +85,7 @@ struct ClientPlugin { pub transport: TransportConfig, pub champion: Champion, pub faction: Faction, + pub name: String, } impl Plugin for ClientPlugin { @@ -86,6 +93,7 @@ impl Plugin for ClientPlugin { app.insert_resource(MyClientId(self.client_id)) .insert_resource(MyChampion(self.champion)) .insert_resource(MyFaction(self.faction)) + .insert_resource(MyName(self.name.clone())) .insert_resource(Attack(None)) .insert_resource(CameraControls::default()) .add_plugins(NetworkPlugin { @@ -150,6 +158,7 @@ fn setup( mut commands: Commands, champion: Res<MyChampion>, faction: Res<MyFaction>, + name: Res<MyName>, mut connection_manager: ResMut<ConnectionManager<MyProtocol>>, ) { commands.spawn(Camera2dBundle::default()); @@ -225,10 +234,11 @@ fn setup( }); client.connect().unwrap(); connection_manager - .send_message::<Input, SelectChampion>(SelectChampion(champion.0)) - .unwrap(); - connection_manager - .send_message::<Input, SelectFaction>(SelectFaction(faction.0)) + .send_message::<Input, Spawn>(Spawn { + champion: champion.0, + faction: faction.0, + name: name.0.clone(), + }) .unwrap(); } @@ -236,17 +246,51 @@ fn render_players( mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>, mut meshes: ResMut<Assets<Mesh>>, - players: Query<(Entity, &PlayerPosition, &PlayerColor, &Shape), Added<PlayerId>>, + players: Query< + ( + Entity, + &PlayerPosition, + &PlayerColor, + &Shape, + &Faction, + Option<&Name_>, + ), + Added<PlayerId>, + >, ) { - for (entity, position, color, shape) in players.iter() { - commands.entity(entity).insert(MaterialMesh2dBundle { - mesh: Mesh2dHandle(meshes.add(Circle { - radius: shape.radius, - })), - material: materials.add(color.0), - transform: Transform::from_xyz(position.0.x, position.0.y, 0.), - ..Default::default() - }); + for (entity, position, color, shape, faction, name) in players.iter() { + commands + .entity(entity) + .insert(SpatialBundle { + transform: Transform::from_xyz(position.0.x, position.0.y, 0.), + ..Default::default() + }) + .with_children(|root| { + root.spawn(MaterialMesh2dBundle { + mesh: Mesh2dHandle(meshes.add(Circle { + radius: shape.radius, + })), + material: materials.add(color.0), + ..Default::default() + }); + match name { + Some(name) => { + root.spawn(Text2dBundle { + text: Text::from_section( + name.0.clone(), + TextStyle { + font_size: 10., + color: faction.to_color(), + ..Default::default() + }, + ), + transform: Transform::from_xyz(0., shape.radius + 12., 0.), + ..Default::default() + }); + } + None => {} + } + }); } } |