Make use of states in char-selection

Former-commit-id: f74d4811bebb0e60093a96d70feeedaae8bc6c04
This commit is contained in:
timokoesters 2019-05-19 20:22:45 +02:00
parent 7d683affe9
commit ad5dcb4158
4 changed files with 9 additions and 4 deletions

View File

@ -102,6 +102,7 @@ impl Client {
pub fn register(&mut self, player: comp::Player) { pub fn register(&mut self, player: comp::Player) {
self.postbox.send_message(ClientMsg::Register { player }); self.postbox.send_message(ClientMsg::Register { player });
self.pending_state_request = true;
} }
pub fn request_character(&mut self, name: String, body: comp::Body) { pub fn request_character(&mut self, name: String, body: comp::Body) {

View File

@ -1,5 +1,5 @@
use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
use crate::state::Time; use crate::state::Time;
use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Health { pub struct Health {

View File

@ -5,7 +5,7 @@ use vek::*;
// Crate // Crate
use crate::{ use crate::{
comp::{phys::Pos, Action, Actions, Control, Stats}, comp::{phys::Pos, Action, Actions, Control, Stats},
state::{Time, DeltaTime}, state::{DeltaTime, Time},
}; };
// Basic ECS AI agent system // Basic ECS AI agent system

View File

@ -8,7 +8,7 @@ use crate::{
Direction, GlobalState, PlayState, PlayStateResult, Direction, GlobalState, PlayState, PlayStateResult,
}; };
use client::{self, Client}; use client::{self, Client};
use common::{clock::Clock, comp, msg::ClientMsg}; use common::{clock::Clock, comp, msg::ClientMsg, msg::ClientState};
use scene::Scene; use scene::Scene;
use std::{cell::RefCell, rc::Rc, time::Duration}; use std::{cell::RefCell, rc::Rc, time::Duration};
use ui::CharSelectionUi; use ui::CharSelectionUi;
@ -46,7 +46,9 @@ impl PlayState for CharSelectionState {
// Set up an fps clock. // Set up an fps clock.
let mut clock = Clock::new(); let mut clock = Clock::new();
loop { while self.client.borrow().is_request_pending()
|| self.client.borrow().get_client_state() == Some(ClientState::Registered)
{
// Handle window events. // Handle window events.
for event in global_state.window.fetch_events() { for event in global_state.window.fetch_events() {
match event { match event {
@ -122,6 +124,8 @@ impl PlayState for CharSelectionState {
// Wait for the next tick. // Wait for the next tick.
clock.tick(Duration::from_millis(1000 / FPS)); clock.tick(Duration::from_millis(1000 / FPS));
} }
PlayStateResult::Pop
} }
fn name(&self) -> &'static str { fn name(&self) -> &'static str {