From 285e14b8320f681ae6ef8cab755dc5fc870e7b41 Mon Sep 17 00:00:00 2001 From: Mashy Date: Tue, 23 Oct 2018 11:07:27 +1000 Subject: [PATCH] keyboard shortcuts and new battle page --- client/src/components/body.component.jsx | 69 ++++++++++++++++-------- client/src/components/game.jsx | 47 ++++++++++------ client/src/keyboard.jsx | 9 ++++ 3 files changed, 89 insertions(+), 36 deletions(-) mode change 100644 => 100755 client/src/components/body.component.jsx mode change 100644 => 100755 client/src/components/game.jsx mode change 100644 => 100755 client/src/keyboard.jsx diff --git a/client/src/components/body.component.jsx b/client/src/components/body.component.jsx old mode 100644 new mode 100755 index 6c41dfb0..e523325f --- a/client/src/components/body.component.jsx +++ b/client/src/components/body.component.jsx @@ -1,34 +1,61 @@ // eslint-disable-next-line const preact = require('preact'); +const { connect } = require('preact-redux'); +const actions = require('../actions'); const ItemListContainer = require('./item.list.container'); const CrypSpawnContainer = require('./cryp.spawn.container'); const CrypListContainer = require('./cryp.list.container'); const GameContainer = require('./game.container'); -function renderBody() { - return ( -
-
-
- -
-
-
-
- -
-
- +const addState = connect( + function receiveState(state) { + const {game} = state; + return {game}; + }, + function receiveDispatch(dispatch) { + function setGame(game) { + dispatch(actions.setGame(game)) + } + return {setGame} + } +); +function renderBody(props){ + const {game, setGame} = props; + if(game){ + return( +
+ + +
+ ) + }else{ + return( +
+
+
+ +
+
+
+
+ +
+
+ +
-
-
- -
-
- ); + + ) + } } -module.exports = renderBody; +module.exports = addState(renderBody); diff --git a/client/src/components/game.jsx b/client/src/components/game.jsx old mode 100644 new mode 100755 index 39416b19..671e1ac1 --- a/client/src/components/game.jsx +++ b/client/src/components/game.jsx @@ -1,4 +1,5 @@ const preact = require('preact'); +const key = require('keymaster'); function GamePanel(props) { const { @@ -10,7 +11,7 @@ function GamePanel(props) { selectSkillTarget, selectIncomingTarget, account - } = props; + } = props; if (!game) return
...
; @@ -19,6 +20,8 @@ function GamePanel(props) { const playerTeam = game.teams.find(t => t.id === account.id); const incoming = playerTeam.incoming.map(inc => { + key.unbind('1'); + key('1', () => setActiveIncoming(inc.id)); return (
{JSON.stringify(inc)}
@@ -26,13 +29,15 @@ function GamePanel(props) { className="button is-dark is-fullwidth" type="submit" onClick={() => setActiveIncoming(inc.id)}> - {inc.skill} + (1) Block skill: {inc.skill}
); }); function PlayerCrypCard(cryp) { + key.unbind('q'); + key('q', () => setActiveSkill(cryp.id, 'Attack')); if (activeIncoming) console.log('should be a pointer'); return (
setActiveSkill(cryp.id, 'Attack')} > - Attack + (Q) Attack
); @@ -109,7 +114,6 @@ function GamePanel(props) { function OpponentTeam(team) { const cryps = team.cryps.map(OpponentCrypCard); - return (
-
-
{otherTeams.map(OpponentTeam)}
-
-
{game.phase}
+
+
+ {phaseText(game.phase)} +
+
+ {PlayerTeam(playerTeam, setActiveSkill)} +
+
+
+ {otherTeams.map(OpponentTeam)}
-
+
{incoming}
-
{PlayerTeam(playerTeam, setActiveSkill)}
-
-
log
+
+
log
-
+
) } diff --git a/client/src/keyboard.jsx b/client/src/keyboard.jsx old mode 100644 new mode 100755 index dfa58da6..04a53b6b --- a/client/src/keyboard.jsx +++ b/client/src/keyboard.jsx @@ -6,9 +6,18 @@ function setupKeys(store) { const state = store.getState(); key.unbind('esc'); + if (state.activeItem) { key('esc', () => store.dispatch(actions.setActiveItem(null))); } + if (state.activeSkill) { + key('esc', () => store.dispatch(actions.setActiveSkill(null))); + } + if (state.activeIncoming) { + key('esc', () => store.dispatch(actions.setActiveIncoming(null))); + } + + }); }