game controls

This commit is contained in:
ntr
2019-08-08 20:20:11 +10:00
parent d74ca61d57
commit 4b5aa62140
10 changed files with 108 additions and 36 deletions
+33
View File
@@ -0,0 +1,33 @@
const preact = require('preact');
const { connect } = require('preact-redux');
const addState = connect(
function receiveState(state) {
const {
ws,
game
} = state;
function sendGameReady() {
document.activeElement.blur()
return ws.sendGameReady(game.id);
}
return { game, sendGameReady };
},
);
function Controls(args) {
const {
game,
sendGameReady
} = args;
return (
<div class="controls">
<button class="ready" onClick={() => sendGameReady()}>Ready</button>
</div>
);
}
module.exports = addState(Controls);
+7
View File
@@ -8,14 +8,19 @@ const { ConstructAvatar } = require('./construct');
const addState = connect(
function receiveState(state) {
const {
ws,
instance,
account,
} = state;
function sendInstanceReady() {
return ws.sendInstanceReady(instance.id);
}
return {
instance,
account,
sendInstanceReady,
};
},
);
@@ -37,6 +42,7 @@ function Faceoff(props) {
const {
instance,
account,
sendInstanceReady,
} = props;
if (!instance) return <div>...</div>;
@@ -75,6 +81,7 @@ function Faceoff(props) {
{OpponentTeam(otherTeam)}
{PlayerTeam(playerTeam)}
<h1 class={`player-name ${playerTeam.ready ? 'ready' : ''}`}>{playerTeam.name}</h1>
<button class="ready" onClick={() => sendInstanceReady()} >Ready</button>
</main>
);
}
+2
View File
@@ -5,6 +5,7 @@ const actions = require('../actions');
const GameConstruct = require('./game.construct');
const Targeting = require('./targeting.arrows');
const Controls = require('./controls');
const addState = connect(
function receiveState(state) {
@@ -100,6 +101,7 @@ function Game(props) {
{otherTeams.map(OpponentTeam)}
<Targeting />
{PlayerTeam(playerTeam, setActiveSkill)}
<Controls />
</main>
);
}
@@ -63,7 +63,6 @@ function Instance(args) {
<main class={instanceClasses} onClick={instanceClick} onMouseOver={() => setInfo(null)} >
<Vbox />
<InfoContainer />
<hr />
<InstanceConstructsContainer />
</main>
);
+1 -1
View File
@@ -47,12 +47,12 @@ function ScoreBoard(args) {
return (
<div class="scoreboard">
<button class="ready" onClick={() => sendInstanceReady()}>Ready</button>
<table>
<tbody>
{players}
</tbody>
</table>
<button class="ready" onClick={() => sendInstanceReady}>Ready</button>
</div>
);
}