From a719427eb56a297a1c2361d9d8dd82dd5b76d53a Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 13 Mar 2023 02:24:37 +0100 Subject: [PATCH] update --- kubi-server/src/auth.rs | 51 +++++++++++++++++++++------------------ kubi-shared/src/entity.rs | 2 +- kubi-shared/src/player.rs | 2 ++ kubi/src/player.rs | 6 +++++ 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/kubi-server/src/auth.rs b/kubi-server/src/auth.rs index 09b9d67..d912790 100644 --- a/kubi-server/src/auth.rs +++ b/kubi-server/src/auth.rs @@ -1,4 +1,4 @@ -use shipyard::{UniqueView, NonSendSync, EntitiesViewMut, ViewMut, UniqueViewMut}; +use shipyard::{UniqueView, NonSendSync, EntitiesViewMut, ViewMut, UniqueViewMut, AllStoragesView}; use uflow::{server::Event as ServerEvent, SendMode}; use kubi_shared::{ networking::{ @@ -10,8 +10,8 @@ use kubi_shared::{ }, client::{Client, ClientId}, channels::CHANNEL_AUTH }, - player::Player, - transform::Transform + player::{Player, PLAYER_HEALTH}, + transform::Transform, entity::{Entity, Health} }; use crate::{ server::{ServerEvents, UdpServer, IsMessageOfType}, @@ -20,17 +20,14 @@ use crate::{ }; pub fn authenticate_players( - mut entities: EntitiesViewMut, - mut players: ViewMut, - mut clients: ViewMut, - mut client_addrs: ViewMut, - mut transforms: ViewMut, - mut client_entity_map: UniqueViewMut, - mut client_addr_map: UniqueViewMut, - server: NonSendSync>, - events: UniqueView, - config: UniqueView + storages: AllStoragesView, ) { + let mut client_entity_map = storages.borrow::>().unwrap(); + let mut client_addr_map = storages.borrow::>().unwrap(); + let server = storages.borrow::>>().unwrap(); + let events = storages.borrow::>().unwrap(); + let config = storages.borrow::>().unwrap(); + for event in &events.0 { let ServerEvent::Receive(client_addr, data) = event else{ continue @@ -93,17 +90,23 @@ pub fn authenticate_players( }; //Spawn the user - let entity_id = entities.add_entity(( - &mut players, - &mut clients, - &mut client_addrs, - &mut transforms, - ), ( - Player, - Client(client_id), - ClientAddress(*client_addr), - Transform::default(), - )); + let entity_id = { + storages.borrow::().unwrap().add_entity(( + &mut storages.borrow::>().unwrap(), + &mut storages.borrow::>().unwrap(), + &mut storages.borrow::>().unwrap(), + &mut storages.borrow::>().unwrap(), + &mut storages.borrow::>().unwrap(), + &mut storages.borrow::>().unwrap(), + ), ( + Entity, + Player, + Health::new(PLAYER_HEALTH), + Client(client_id), + ClientAddress(*client_addr), + Transform::default(), + )) + }; //Add the user to the ClientIdMap and ClientAddressMap client_entity_map.0.insert(client_id, entity_id); diff --git a/kubi-shared/src/entity.rs b/kubi-shared/src/entity.rs index bf2f183..9c5401d 100644 --- a/kubi-shared/src/entity.rs +++ b/kubi-shared/src/entity.rs @@ -9,7 +9,7 @@ pub struct Health { pub max: u8, } impl Health { - fn new(health: u8) -> Self { + pub fn new(health: u8) -> Self { Self { current: health, max: health diff --git a/kubi-shared/src/player.rs b/kubi-shared/src/player.rs index d2df58c..ea96706 100644 --- a/kubi-shared/src/player.rs +++ b/kubi-shared/src/player.rs @@ -1,4 +1,6 @@ use shipyard::Component; +pub const PLAYER_HEALTH: u8 = 20; + #[derive(Component)] pub struct Player; diff --git a/kubi/src/player.rs b/kubi/src/player.rs index 705d0b6..67d2cae 100644 --- a/kubi/src/player.rs +++ b/kubi/src/player.rs @@ -1,4 +1,8 @@ use shipyard::{Component, AllStoragesViewMut}; +use kubi_shared::{ + entity::{Entity, Health}, + player::PLAYER_HEALTH +}; use crate::{ transform::Transform, camera::Camera, @@ -18,6 +22,8 @@ pub fn spawn_player ( storages.add_entity(( Player, MainPlayer, + Entity, + Health::new(PLAYER_HEALTH), Transform::default(), Camera::default(), FlyController,