From 95e5d493af481b1cb6c6f39d102e81365322afc7 Mon Sep 17 00:00:00 2001 From: ntr Date: Fri, 26 Apr 2019 13:08:08 +1000 Subject: [PATCH] client niceness" --- client/cryps.css | 36 +++++++++--- client/src/components/info.component.jsx | 15 +++-- .../src/components/instance.create.form.jsx | 2 +- client/src/components/menu.component.jsx | 29 +++++++--- client/src/reducers.jsx | 2 +- server/src/instance.rs | 10 ++-- server/src/main.rs | 1 + server/src/names.rs | 55 +++++++++++++++++++ 8 files changed, 121 insertions(+), 29 deletions(-) create mode 100644 server/src/names.rs diff --git a/client/cryps.css b/client/cryps.css index ac43f5c6..e17c3cc9 100644 --- a/client/cryps.css +++ b/client/cryps.css @@ -66,6 +66,17 @@ main { align-items: flex-start; } +tr.right:focus, tr.right:hover { + box-shadow: inset -0.5em 0 0 0 whitesmoke; +} + +tr { + transition-property: all; + transition-duration: 0.5s; + transition-delay: 0; + transition-timing-function: ease; +} + button, input { font-family: 'Jura'; color: whitesmoke; @@ -320,24 +331,30 @@ header { flex: 1 0 25%; } -.ready-btn { - flex: 1 0 50%; -} /* nav hidden on desktop */ .nav-btn { display: none; } +.ready-btn { + flex: 1 0 50%; +} + .ready-btn:hover { transition-property: all; - transition-duration: 2s; + transition-duration: 0.5s; transition-timing-function: ease; color: forestgreen; border-color: forestgreen; /*box-shadow: inset -0.5em 0 0 0 forestgreen;*/ } +.ready { + color: forestgreen; + box-shadow: inset -0.5em 0 0 0 forestgreen; +} + .instance-ui-btn { font-size: 100%; padding: 0; @@ -395,32 +412,33 @@ header { color: black; } -.vbox-table { +table { table-layout: fixed; width: 100%; } -.vbox-table td { +table td { border: 1px solid whitesmoke; padding: 0.2em; text-align: center; height: 40px; cursor: pointer; text-transform: uppercase; +} +.vbox-table td { transition-property: all; transition-duration: 0.5s; transition-delay: 0; transition-timing-function: ease; - } -.vbox-table td:active { +table td:active { background-color: whitesmoke; color: black; } -.vbox-table td svg { +table td svg { stroke-width: 2px; height: 96%; vertical-align: text-bottom; diff --git a/client/src/components/info.component.jsx b/client/src/components/info.component.jsx index c6e27fa0..ade31874 100644 --- a/client/src/components/info.component.jsx +++ b/client/src/components/info.component.jsx @@ -155,7 +155,8 @@ function Info(args) { function scoreBoard() { const players = instance.players.map((p, i) => - + {p.name} {p.score.wins} / {p.score.losses} {p.ready ? 'ready' : ''} @@ -163,7 +164,7 @@ function Info(args) { ); return ( - +
{players} @@ -171,19 +172,23 @@ function Info(args) { ); } + const scoreBoardEl = activeCryp || info[0] + ? null + : scoreBoard(); + const infoCryp = activeCryp ? infoCrypElement(player.cryps.find(c => c.id === activeCryp.id)) : null; - const otherInfo = info.length + const otherInfo = !info[0] ? infoVar(info) : null; - const instanceInfoClass = `instance-info ${info.length ? '' : 'hidden'}`; + const instanceInfoClass = `instance-info ${!info[0] ? '' : 'hidden'}`; return (
- {scoreBoard()} + {scoreBoardEl} {infoCryp} {otherInfo}
diff --git a/client/src/components/instance.create.form.jsx b/client/src/components/instance.create.form.jsx index 617afacf..c26b3111 100644 --- a/client/src/components/instance.create.form.jsx +++ b/client/src/components/instance.create.form.jsx @@ -59,7 +59,7 @@ class InstanceCreateForm extends Component { diff --git a/client/src/components/menu.component.jsx b/client/src/components/menu.component.jsx index 366978d7..4fbb32e3 100644 --- a/client/src/components/menu.component.jsx +++ b/client/src/components/menu.component.jsx @@ -36,9 +36,8 @@ function Menu(args) { const instancePanels = instances.map(instance => { const player = instance.players.find(p => p.id === account.id); const scoreText = player - ? `| ${player.score.wins} : ${player.score.losses}` + ? `${player.score.wins} : ${player.score.losses}` : ''; - const name = `${instance.name} ${scoreText}`; function instanceClick() { if (!player) return sendInstanceJoin(instance); @@ -46,12 +45,13 @@ function Menu(args) { } return ( - + + + + + ); }); @@ -68,7 +68,18 @@ function Menu(args) { return (
- {instancePanels} +
{instance.name}{instance.players.length} / {instance.max_players}{scoreText}
+ + + + + + + + + {instancePanels} + +
instance nameplayersstatus
{mmSet} diff --git a/client/src/reducers.jsx b/client/src/reducers.jsx index c40d3dff..f5c49c94 100644 --- a/client/src/reducers.jsx +++ b/client/src/reducers.jsx @@ -150,7 +150,7 @@ function wsReducer(state = defaultWs, action) { } } -const defaultInfo = []; +const defaultInfo = [null, null]; function infoReducer(state = defaultInfo, action) { switch (action.type) { case actions.SET_INFO: diff --git a/server/src/instance.rs b/server/src/instance.rs index e3dc14ce..d3c19517 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -17,6 +17,7 @@ use mob::{instance_mobs}; use game::{Game, Phase, Team, game_get, game_write, game_instance_new, game_instance_join, game_global_get, game_global_set}; use vbox::{Var}; use rpc::{RpcResult}; +use names::{name}; #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] enum InstancePhase { @@ -94,7 +95,7 @@ impl Instance { self.players = iter::repeat_with(|| { let bot_id = Uuid::new_v4(); let cryps = instance_mobs(bot_id); - let mut p = Player::new(bot_id, self.id, &bot_id.to_string(), cryps).set_bot(true); + let mut p = Player::new(bot_id, self.id, &name(), cryps).set_bot(true); p.set_ready(true); p }) @@ -105,7 +106,7 @@ impl Instance { fn add_player(&mut self, player: Player) -> Result<&mut Instance, Error> { match self.players.iter().find(|p| p.id == player.id) { - Some(p) => return Err(err_msg("already joined")), + Some(_p) => return Err(err_msg("already joined")), None => (), }; @@ -138,11 +139,12 @@ impl Instance { .position(|p| p.id == player_id) .ok_or(err_msg("player_id not found"))?; - if self.players[i].cryps.iter().all(|c| c.skills.len() == 0) { + if self.phase != InstancePhase::Lobby && self.players[i].cryps.iter().all(|c| c.skills.len() == 0) { return Err(err_msg("your cryps have no skills")); } - self.players[i].set_ready(true); + let v = !self.players[i].ready; + self.players[i].set_ready(v); if self.phase == InstancePhase::Lobby && self.can_start() { self.start(); diff --git a/server/src/main.rs b/server/src/main.rs index 89ca846c..8fa4a8b1 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -24,6 +24,7 @@ mod net; mod skill; mod spec; // mod passives; +mod names; mod rpc; mod account; mod instance; diff --git a/server/src/names.rs b/server/src/names.rs new file mode 100644 index 00000000..6c5f748b --- /dev/null +++ b/server/src/names.rs @@ -0,0 +1,55 @@ +use rand::prelude::*; +use rand::{thread_rng}; + +const FIRSTS: [&'static str; 17] = [ + "fierce", + "obscure", + "mighty", + "rogue", + "inverted", + "recalcitrant", + "subterranean", + "brewing", + "nocturnal", + "convex", + "concave", + "piscine", + "dub", + "borean", + "lurking", + "leafy", + "nutritious", +]; + +const LASTS: [&'static str; 16] = [ + "kaffe", + "river", + "oak", + "replicant", + "mechanism", + "function", + "shape", + "form", + "poseidon", + "mountain", + "river", + "forest", + "problem", + "warning", + "information", + "witness", +]; + +pub fn name() -> String { + let mut rng = thread_rng(); + + let first = rng.gen_range(0, FIRSTS.len() - 1); + let last = rng.gen_range(0, LASTS.len() - 1); + + let mut s = String::new(); + s.push_str(FIRSTS[first]); + s.push(' '); + s.push_str(LASTS[last]); + + s +} \ No newline at end of file