phase end

This commit is contained in:
ntr 2019-05-01 13:03:26 +10:00
parent 2dfdd0d09c
commit 7319b4b2ba
5 changed files with 74 additions and 14 deletions

View File

@ -338,7 +338,6 @@ header {
flex-flow: row; flex-flow: row;
flex: 0 0 100%; flex: 0 0 100%;
margin-bottom: 1em;
} }
.instance-info { .instance-info {
@ -378,6 +377,49 @@ header {
box-shadow: inset -0.5em 0 0 0 forestgreen; box-shadow: inset -0.5em 0 0 0 forestgreen;
} }
progress {
/* Dimensions */
width: 100%;
height: .25em;
/* Reset the apperance */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* Get rid of the default border in Firefox/Opera. */
border: none;
/* For Firefox/IE10+ */
background-color: transparent;
/* For IE10+, color of the progress bar */
color: forestgreen;
margin: 0.5em 0;
}
progress::-webkit-progress-bar {
background-color: forestgreen;
}
.progress-container {
width: 100%;
background-color: transparent;
position: fixed;
top: 0;
left: 0;
height: .25em;
display: block;
}
.progress-bar {
background-color: forestgreen;
width: 50%;
display: block;
height: inherit;
}
.instance-ui-btn { .instance-ui-btn {
font-size: 100%; font-size: 100%;
padding: 0; padding: 0;

View File

@ -78,6 +78,18 @@ function GamePanel(props) {
</div> </div>
); );
const timerPct = (Date.parse(game.phase_start) + 1000 * 60 * 60) - Date.now();
console.log(Date.now(), Date.parse(game.phase_start));
console.log(timerPct);
const timer = (
<progress value="100">
<div className="progress-container">
<span className="progress-bar"></span>
</div>
</progress>
);
function findCryp(id) { function findCryp(id) {
const team = game.players.find(t => t.cryps.find(c => c.id === id)); const team = game.players.find(t => t.cryps.find(c => c.id === id));
if (team) return team.cryps.find(c => c.id === id); if (team) return team.cryps.find(c => c.id === id);
@ -173,6 +185,7 @@ function GamePanel(props) {
return ( return (
<main className="game" onClick={() => setActiveCryp(null)} > <main className="game" onClick={() => setActiveCryp(null)} >
{header} {header}
{timer}
{PlayerTeam(playerTeam, setActiveSkill)} {PlayerTeam(playerTeam, setActiveSkill)}
<div className="mobile-skills"> <div className="mobile-skills">
{mobileSkills} {mobileSkills}

View File

@ -37,7 +37,7 @@ pub struct Game {
pub resolved: Vec<Resolution>, pub resolved: Vec<Resolution>,
pub log: Vec<String>, pub log: Vec<String>,
pub instance: Option<Uuid>, pub instance: Option<Uuid>,
phase_start: DateTime<Utc>, phase_end: DateTime<Utc>,
} }
impl Game { impl Game {
@ -52,7 +52,7 @@ impl Game {
resolved: vec![], resolved: vec![],
log: vec![], log: vec![],
instance: None, instance: None,
phase_start: Utc::now(), phase_end: Utc::now(),
}; };
} }
@ -163,7 +163,9 @@ impl Game {
} }
fn skill_phase_start(mut self) -> Game { fn skill_phase_start(mut self) -> Game {
self.phase_start = Utc::now(); self.phase_end = Utc::now()
.checked_add_signed(Duration::seconds(60))
.expect("could not set phase end");
for player in self.players.iter_mut() { for player in self.players.iter_mut() {
if player.skills_required() != 0 { if player.skills_required() != 0 {
@ -562,7 +564,7 @@ impl Game {
} }
fn phase_timed_out(&self) -> bool { fn phase_timed_out(&self) -> bool {
Utc::now().signed_duration_since(self.phase_start).num_seconds() > 60 !Utc::now().signed_duration_since(self.phase_end).is_zero()
} }
pub fn upkeep(mut self) -> Game { pub fn upkeep(mut self) -> Game {
@ -1309,7 +1311,7 @@ mod tests {
fn upkeep_test() { fn upkeep_test() {
let mut game = create_2v2_test_game(); let mut game = create_2v2_test_game();
game.players[0].set_ready(true); game.players[0].set_ready(true);
game.phase_start = Utc::now().checked_sub_signed(Duration::seconds(61)).unwrap(); game.phase_end = Utc::now().checked_sub_signed(Duration::seconds(61)).unwrap();
game = game.upkeep(); game = game.upkeep();
assert!(game.players[1].warnings == 1); assert!(game.players[1].warnings == 1);
} }

View File

@ -48,7 +48,7 @@ pub struct Instance {
max_rounds: usize, max_rounds: usize,
password: Option<String>, password: Option<String>,
pub name: String, pub name: String,
phase_start: DateTime<Utc>, phase_end: DateTime<Utc>,
} }
impl Instance { impl Instance {
@ -63,7 +63,7 @@ impl Instance {
max_rounds: 16, max_rounds: 16,
name: String::new(), name: String::new(),
password: None, password: None,
phase_start: Utc::now(), phase_end: Utc::now(),
} }
} }
@ -78,12 +78,12 @@ impl Instance {
max_rounds: 1, max_rounds: 1,
name: "Global Matchmaking".to_string(), name: "Global Matchmaking".to_string(),
password: None, password: None,
phase_start: Utc::now(), phase_end: Utc::now(),
} }
} }
fn phase_timed_out(&self) -> bool { fn phase_timed_out(&self) -> bool {
Utc::now().signed_duration_since(self.phase_start).num_seconds() > 60 !Utc::now().signed_duration_since(self.phase_end).is_zero()
} }
fn timed_out_players(&self) -> Vec<Uuid> { fn timed_out_players(&self) -> Vec<Uuid> {
@ -270,7 +270,10 @@ impl Instance {
fn next_round(&mut self) -> &mut Instance { fn next_round(&mut self) -> &mut Instance {
self.phase = InstancePhase::InProgress; self.phase = InstancePhase::InProgress;
self.phase_start = Utc::now(); self.phase_end = Utc::now()
.checked_add_signed(Duration::seconds(60))
.expect("could not set phase end");
if self.rounds.len() >= self.max_rounds { if self.rounds.len() >= self.max_rounds {
return self.finish(); return self.finish();
@ -811,7 +814,7 @@ mod tests {
instance.player_ready(a_id).expect("a ready"); instance.player_ready(a_id).expect("a ready");
instance.player_ready(b_id).expect("b ready"); instance.player_ready(b_id).expect("b ready");
instance.phase_start = Utc::now().checked_sub_signed(Duration::seconds(61)).unwrap(); instance.phase_end = Utc::now().checked_sub_signed(Duration::seconds(61)).unwrap();
let (mut instance, new_games) = instance.upkeep(); let (mut instance, new_games) = instance.upkeep();

View File

@ -333,9 +333,9 @@ fn get_combos() -> Vec<Combo> {
let mut combinations = vec![ let mut combinations = vec![
Combo { units: vec![Var::Buff, Var::Red, Var::Red], var: Var::Empower }, Combo { units: vec![Var::Buff, Var::Red, Var::Red], var: Var::Empower },
Combo { units: vec![Var::Buff, Var::Green, Var::Green], var: Var::Triage }, Combo { units: vec![Var::Buff, Var::Green, Var::Green], var: Var::Triage },
Combo { units: vec![Var::Buff, Var::Blue, Var::Blue], var: Var::Hostility }, Combo { units: vec![Var::Buff, Var::Blue, Var::Blue], var: Var::Amplify },
Combo { units: vec![Var::Buff, Var::Red, Var::Green], var: Var::Clutch }, Combo { units: vec![Var::Buff, Var::Red, Var::Green], var: Var::Clutch },
Combo { units: vec![Var::Buff, Var::Green, Var::Blue], var: Var::Amplify }, Combo { units: vec![Var::Buff, Var::Green, Var::Blue], var: Var::Hostility },
Combo { units: vec![Var::Buff, Var::Red, Var::Blue], var: Var::Haste }, Combo { units: vec![Var::Buff, Var::Red, Var::Blue], var: Var::Haste },
Combo { units: vec![Var::Debuff, Var::Red, Var::Red], var: Var::Snare }, Combo { units: vec![Var::Debuff, Var::Red, Var::Red], var: Var::Snare },