|
@@ -11,6 +11,7 @@ use rand::seq::SliceRandom;
|
|
use crate::game;
|
|
use crate::game;
|
|
use crate::websocket;
|
|
use crate::websocket;
|
|
use crate::websocket::*;
|
|
use crate::websocket::*;
|
|
|
|
+use crate::datasource;
|
|
|
|
|
|
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
|
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
|
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
|
|
const CLIENT_TIMEOUT: Duration = Duration::from_secs(10);
|
|
@@ -145,7 +146,8 @@ pub struct GameLobby {
|
|
game: game::Game,
|
|
game: game::Game,
|
|
waiting_players: BTreeMap<String, Addr<GameConnection>>,
|
|
waiting_players: BTreeMap<String, Addr<GameConnection>>,
|
|
ready_players: Vec<String>,
|
|
ready_players: Vec<String>,
|
|
- lobby_state: LobbyState
|
|
|
|
|
|
+ lobby_state: LobbyState,
|
|
|
|
+ data_source: Box<dyn datasource::DataSource<String>>,
|
|
}
|
|
}
|
|
|
|
|
|
impl Actor for GameLobby {
|
|
impl Actor for GameLobby {
|
|
@@ -228,10 +230,17 @@ impl GameLobby {
|
|
waiting_players: BTreeMap::new(),
|
|
waiting_players: BTreeMap::new(),
|
|
ready_players: Vec::new(),
|
|
ready_players: Vec::new(),
|
|
lobby_state: LobbyState::Starting,
|
|
lobby_state: LobbyState::Starting,
|
|
|
|
+ data_source: Box::new(datasource::ArraySource::create(vec![
|
|
|
|
+ "Delikatessfutter für Hunde".to_owned(),
|
|
|
|
+ "Ein Hotel für die ganze Familie".to_owned(),
|
|
|
|
+ "Brasilianischer Superstar".to_owned(),
|
|
|
|
+ "Buchstabe des griechischen Alphabets".to_owned(),
|
|
|
|
+ ]))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
fn set_state(&mut self, new_state: LobbyState) {
|
|
fn set_state(&mut self, new_state: LobbyState) {
|
|
|
|
+
|
|
match new_state {
|
|
match new_state {
|
|
LobbyState::Starting => {
|
|
LobbyState::Starting => {
|
|
for (nick, _addr) in &self.waiting_players {
|
|
for (nick, _addr) in &self.waiting_players {
|
|
@@ -241,7 +250,12 @@ impl GameLobby {
|
|
self.ready_players.clear();
|
|
self.ready_players.clear();
|
|
},
|
|
},
|
|
LobbyState::Creating => {
|
|
LobbyState::Creating => {
|
|
- self.game.start_round();
|
|
|
|
|
|
+ let ds = &self.data_source;
|
|
|
|
+ let mut index = 0;
|
|
|
|
+ self.game.start_round(|| {
|
|
|
|
+ index += 1;
|
|
|
|
+ ds.get_ith(index - 1).unwrap().clone()
|
|
|
|
+ });
|
|
},
|
|
},
|
|
_ => {}
|
|
_ => {}
|
|
}
|
|
}
|
|
@@ -262,9 +276,8 @@ impl GameLobby {
|
|
.map(|p| p.submitted_word.clone().unwrap())
|
|
.map(|p| p.submitted_word.clone().unwrap())
|
|
.collect::<Vec<_>>();
|
|
.collect::<Vec<_>>();
|
|
let questions = self.game.players.iter()
|
|
let questions = self.game.players.iter()
|
|
- .map(|x| x.creating_exercise.as_ref().unwrap())
|
|
|
|
- .chain(self.game.additional_questions.iter())
|
|
|
|
- .map(|x| x.question.clone())
|
|
|
|
|
|
+ .map(|x| x.creating_exercise.as_ref().unwrap().question.clone())
|
|
|
|
+ .chain(self.game.additional_questions.clone().into_iter())
|
|
.collect::<Vec<_>>();
|
|
.collect::<Vec<_>>();
|
|
let solutions = words.iter()
|
|
let solutions = words.iter()
|
|
.map(|x| x.clone())
|
|
.map(|x| x.clone())
|
|
@@ -331,7 +344,7 @@ impl GameLobby {
|
|
.map(|p| p.creating_exercise.clone().unwrap().question)
|
|
.map(|p| p.creating_exercise.clone().unwrap().question)
|
|
.collect::<Vec<_>>();
|
|
.collect::<Vec<_>>();
|
|
questions.append(&mut self.game.additional_questions.iter()
|
|
questions.append(&mut self.game.additional_questions.iter()
|
|
- .map(|x| x.question.clone())
|
|
|
|
|
|
+ .map(|x| x.clone())
|
|
.collect::<Vec<_>>()
|
|
.collect::<Vec<_>>()
|
|
);
|
|
);
|
|
|
|
|