The 'GameState' resource stores the state of the whole game (of a single client/player) so this is a better name for this.master
| @@ -10,7 +10,7 @@ use specs::{prelude::*, ReadExpect, ReadStorage, System, World, WriteExpect}; | |||||
| use crate::{ | use crate::{ | ||||
| misc::{HorizontalAlign, Text, TextManager, VerticalAlign}, | misc::{HorizontalAlign, Text, TextManager, VerticalAlign}, | ||||
| resources::{Camera, Geometry, PlayerState}, | |||||
| resources::{Camera, GameState, Geometry}, | |||||
| Error, | Error, | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ pub struct Fleets { | |||||
| #[derive(SystemData)] | #[derive(SystemData)] | ||||
| pub struct FleetData<'a> { | pub struct FleetData<'a> { | ||||
| player_state: ReadExpect<'a, PlayerState>, | |||||
| game_state: ReadExpect<'a, GameState>, | |||||
| geometry: WriteExpect<'a, Geometry>, | geometry: WriteExpect<'a, Geometry>, | ||||
| camera: ReadExpect<'a, Camera>, | camera: ReadExpect<'a, Camera>, | ||||
| positions: ReadStorage<'a, Position>, | positions: ReadStorage<'a, Position>, | ||||
| @@ -51,7 +51,7 @@ impl<'a> System<'a> for Fleets { | |||||
| fn run(&mut self, data: Self::SystemData) { | fn run(&mut self, data: Self::SystemData) { | ||||
| let FleetData { | let FleetData { | ||||
| player_state, | |||||
| game_state, | |||||
| mut geometry, | mut geometry, | ||||
| camera, | camera, | ||||
| positions, | positions, | ||||
| @@ -60,7 +60,7 @@ impl<'a> System<'a> for Fleets { | |||||
| fleets, | fleets, | ||||
| } = data; | } = data; | ||||
| let player = return_if_none!(players.get(player_state.player_id)); | |||||
| let player = return_if_none!(players.get(game_state.player_id)); | |||||
| gl::enable(gl::BLEND); | gl::enable(gl::BLEND); | ||||
| @@ -14,7 +14,7 @@ pub use error::Error; | |||||
| use debug::{Fleets as DebugFleets, Ships as DebugShips, Summary as DebugSummary}; | use debug::{Fleets as DebugFleets, Ships as DebugShips, Summary as DebugSummary}; | ||||
| use misc::{Events, TextManager, Window}; | use misc::{Events, TextManager, Window}; | ||||
| use render::{Asteroids, FleetSelect, Init, Planets, Ships}; | use render::{Asteroids, FleetSelect, Init, Planets, Ships}; | ||||
| use resources::{Camera, Config, Geometry, InputState, PlayerState, Uniform}; | |||||
| use resources::{Camera, Config, GameState, Geometry, InputState, Uniform}; | |||||
| use systems::{FleetControl, StateUpdate}; | use systems::{FleetControl, StateUpdate}; | ||||
| pub struct App<'a, 'b> { | pub struct App<'a, 'b> { | ||||
| @@ -34,7 +34,7 @@ impl<'a, 'b> App<'a, 'b> { | |||||
| let uniform = Uniform::new()?; | let uniform = Uniform::new()?; | ||||
| let geometry = Geometry::new(world)?; | let geometry = Geometry::new(world)?; | ||||
| let input_state = InputState::default(); | let input_state = InputState::default(); | ||||
| let player_state = PlayerState::new(player_id); | |||||
| let game_state = GameState::new(player_id); | |||||
| camera.update(Matrix4f::scale(0.25))?; | camera.update(Matrix4f::scale(0.25))?; | ||||
| @@ -43,7 +43,7 @@ impl<'a, 'b> App<'a, 'b> { | |||||
| world.insert(uniform); | world.insert(uniform); | ||||
| world.insert(geometry); | world.insert(geometry); | ||||
| world.insert(input_state); | world.insert(input_state); | ||||
| world.insert(player_state); | |||||
| world.insert(game_state); | |||||
| let text_manager = TextManager::new(world)?; | let text_manager = TextManager::new(world)?; | ||||
| @@ -28,7 +28,7 @@ use crate::{ | |||||
| misc::{ | misc::{ | ||||
| HorizontalAlign, MouseEvent, Text, TextCache, TextManager, VerticalAlign, WorldHelper as _, | HorizontalAlign, MouseEvent, Text, TextCache, TextManager, VerticalAlign, WorldHelper as _, | ||||
| }, | }, | ||||
| resources::{Camera, Config, Geometry, InputState, PlayerState, Selection}, | |||||
| resources::{Camera, Config, GameState, Geometry, InputState, Selection}, | |||||
| Error, | Error, | ||||
| }; | }; | ||||
| @@ -71,7 +71,7 @@ enum SelectMode { | |||||
| #[derive(SystemData)] | #[derive(SystemData)] | ||||
| pub struct FleetSelectData<'a> { | pub struct FleetSelectData<'a> { | ||||
| player_state: WriteExpect<'a, PlayerState>, | |||||
| game_state: WriteExpect<'a, GameState>, | |||||
| camera: ReadExpect<'a, Camera>, | camera: ReadExpect<'a, Camera>, | ||||
| mouse_events: ReadExpect<'a, EventChannel<MouseEvent>>, | mouse_events: ReadExpect<'a, EventChannel<MouseEvent>>, | ||||
| @@ -89,10 +89,10 @@ pub struct FleetSelectData<'a> { | |||||
| macro_rules! selection { | macro_rules! selection { | ||||
| (&$data:expr) => { | (&$data:expr) => { | ||||
| return_if_none!(&$data.player_state.selection) | |||||
| return_if_none!(&$data.game_state.selection) | |||||
| }; | }; | ||||
| (&mut $data:expr) => { | (&mut $data:expr) => { | ||||
| return_if_none!(&mut $data.player_state.selection) | |||||
| return_if_none!(&mut $data.game_state.selection) | |||||
| }; | }; | ||||
| } | } | ||||
| @@ -192,17 +192,17 @@ impl FleetSelect { | |||||
| match event { | match event { | ||||
| MouseEvent::ButtonDown(button) if button == &d.config.input.fleet_select_button => { | MouseEvent::ButtonDown(button) if button == &d.config.input.fleet_select_button => { | ||||
| let pos = d.camera.view_to_world(d.input_state.mouse_pos); | let pos = d.camera.view_to_world(d.input_state.mouse_pos); | ||||
| let selection = d.player_state.selection.take(); | |||||
| let selection = d.game_state.selection.take(); | |||||
| for (position, orbit) in (&d.positions, &d.orbits).join() { | for (position, orbit) in (&d.positions, &d.orbits).join() { | ||||
| let r = orbit.max * orbit.max; | let r = orbit.max * orbit.max; | ||||
| if (position.pos - pos).length_sqr() <= r { | if (position.pos - pos).length_sqr() <= r { | ||||
| let player_id = d.player_state.player_id; | |||||
| let player_id = d.game_state.player_id; | |||||
| let player = player!(&d, player_id); | let player = player!(&d, player_id); | ||||
| let player_index = player.index; | let player_index = player.index; | ||||
| let fleet_id = continue_if_none!(orbit.fleets.get(player_index)); | let fleet_id = continue_if_none!(orbit.fleets.get(player_index)); | ||||
| let fleet_id = *continue_if_none!(fleet_id); | let fleet_id = *continue_if_none!(fleet_id); | ||||
| d.player_state.selection = match selection { | |||||
| d.game_state.selection = match selection { | |||||
| Some(s) if s.fleet == fleet_id => { | Some(s) if s.fleet == fleet_id => { | ||||
| self.is_new_selection = false; | self.is_new_selection = false; | ||||
| @@ -3,7 +3,7 @@ | |||||
| use space_crush_common::components::ShipCount; | use space_crush_common::components::ShipCount; | ||||
| use specs::Entity; | use specs::Entity; | ||||
| pub struct PlayerState { | |||||
| pub struct GameState { | |||||
| pub player_id: Entity, | pub player_id: Entity, | ||||
| pub selection: Option<Selection>, | pub selection: Option<Selection>, | ||||
| } | } | ||||
| @@ -13,7 +13,7 @@ pub struct Selection { | |||||
| pub count: ShipCount, | pub count: ShipCount, | ||||
| } | } | ||||
| impl PlayerState { | |||||
| impl GameState { | |||||
| pub fn new(player_id: Entity) -> Self { | pub fn new(player_id: Entity) -> Self { | ||||
| Self { | Self { | ||||
| player_id, | player_id, | ||||
| @@ -1,13 +1,13 @@ | |||||
| pub mod camera; | pub mod camera; | ||||
| pub mod config; | pub mod config; | ||||
| pub mod game_state; | |||||
| pub mod geometry; | pub mod geometry; | ||||
| pub mod input_state; | pub mod input_state; | ||||
| pub mod player_state; | |||||
| pub mod uniform; | pub mod uniform; | ||||
| pub use camera::Camera; | pub use camera::Camera; | ||||
| pub use config::Config; | pub use config::Config; | ||||
| pub use game_state::{GameState, Selection}; | |||||
| pub use geometry::Geometry; | pub use geometry::Geometry; | ||||
| pub use input_state::InputState; | pub use input_state::InputState; | ||||
| pub use player_state::{PlayerState, Selection}; | |||||
| pub use uniform::Uniform; | pub use uniform::Uniform; | ||||
| @@ -8,7 +8,7 @@ use specs::{prelude::*, Entity, ReadStorage, System, World, WriteStorage}; | |||||
| use crate::{ | use crate::{ | ||||
| misc::MouseEvent, | misc::MouseEvent, | ||||
| resources::{Camera, Config, InputState, PlayerState}, | |||||
| resources::{Camera, Config, GameState, InputState}, | |||||
| Error, | Error, | ||||
| }; | }; | ||||
| @@ -19,7 +19,7 @@ pub struct FleetControl { | |||||
| #[derive(SystemData)] | #[derive(SystemData)] | ||||
| pub struct FleetControlData<'a> { | pub struct FleetControlData<'a> { | ||||
| player_state: WriteExpect<'a, PlayerState>, | |||||
| game_state: WriteExpect<'a, GameState>, | |||||
| mouse_events: ReadExpect<'a, EventChannel<MouseEvent>>, | mouse_events: ReadExpect<'a, EventChannel<MouseEvent>>, | ||||
| input_state: ReadExpect<'a, InputState>, | input_state: ReadExpect<'a, InputState>, | ||||
| camera: ReadExpect<'a, Camera>, | camera: ReadExpect<'a, Camera>, | ||||
| @@ -50,7 +50,7 @@ impl<'a> System<'a> for FleetControl { | |||||
| fn run(&mut self, data: Self::SystemData) { | fn run(&mut self, data: Self::SystemData) { | ||||
| let FleetControlData { | let FleetControlData { | ||||
| mut player_state, | |||||
| mut game_state, | |||||
| mouse_events, | mouse_events, | ||||
| input_state, | input_state, | ||||
| camera, | camera, | ||||
| @@ -71,7 +71,7 @@ impl<'a> System<'a> for FleetControl { | |||||
| for (position, orbit) in (&positions, &orbits).join() { | for (position, orbit) in (&positions, &orbits).join() { | ||||
| let r = orbit.max * orbit.max; | let r = orbit.max * orbit.max; | ||||
| if (position.pos - pos).length_sqr() <= r { | if (position.pos - pos).length_sqr() <= r { | ||||
| let player_id = player_state.player_id; | |||||
| let player_id = game_state.player_id; | |||||
| let player = continue_if_none!(players.get(player_id)); | let player = continue_if_none!(players.get(player_id)); | ||||
| let fleet_id = continue_if_none!(orbit.fleets.get(player.index)); | let fleet_id = continue_if_none!(orbit.fleets.get(player.index)); | ||||
| let fleet_id = *continue_if_none!(fleet_id); | let fleet_id = *continue_if_none!(fleet_id); | ||||
| @@ -83,7 +83,7 @@ impl<'a> System<'a> for FleetControl { | |||||
| } | } | ||||
| } | } | ||||
| MouseEvent::ButtonUp(button) if button == &config.input.fleet_move_button => { | MouseEvent::ButtonUp(button) if button == &config.input.fleet_move_button => { | ||||
| let selection = player_state.selection.take(); | |||||
| let selection = game_state.selection.take(); | |||||
| let target_fleet = continue_if_none!(self.target_fleet.take()); | let target_fleet = continue_if_none!(self.target_fleet.take()); | ||||
| let mut selection = continue_if_none!(selection); | let mut selection = continue_if_none!(selection); | ||||
| let fleet = continue_if_none!(fleets.get(selection.fleet)); | let fleet = continue_if_none!(fleets.get(selection.fleet)); | ||||