keyboard shortcuts and new battle page
This commit is contained in:
parent
89ffc2fca3
commit
285e14b832
39
client/src/components/body.component.jsx
Normal file → Executable file
39
client/src/components/body.component.jsx
Normal file → Executable file
@ -1,12 +1,41 @@
|
|||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const preact = require('preact');
|
const preact = require('preact');
|
||||||
|
const { connect } = require('preact-redux');
|
||||||
|
const actions = require('../actions');
|
||||||
|
|
||||||
const ItemListContainer = require('./item.list.container');
|
const ItemListContainer = require('./item.list.container');
|
||||||
const CrypSpawnContainer = require('./cryp.spawn.container');
|
const CrypSpawnContainer = require('./cryp.spawn.container');
|
||||||
const CrypListContainer = require('./cryp.list.container');
|
const CrypListContainer = require('./cryp.list.container');
|
||||||
const GameContainer = require('./game.container');
|
const GameContainer = require('./game.container');
|
||||||
|
|
||||||
function renderBody() {
|
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(
|
||||||
|
<div>
|
||||||
|
<GameContainer />
|
||||||
|
<button
|
||||||
|
className="button is-dark is-fullwidth"
|
||||||
|
type="submit"
|
||||||
|
onClick={() => setGame(null)}
|
||||||
|
>
|
||||||
|
Return to Main Menu
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}else{
|
||||||
return(
|
return(
|
||||||
<section className="columns">
|
<section className="columns">
|
||||||
<div className="column is-4">
|
<div className="column is-4">
|
||||||
@ -24,11 +53,9 @@ function renderBody() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="column">
|
|
||||||
<GameContainer />
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
);
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = renderBody;
|
module.exports = addState(renderBody);
|
||||||
|
|||||||
45
client/src/components/game.jsx
Normal file → Executable file
45
client/src/components/game.jsx
Normal file → Executable file
@ -1,4 +1,5 @@
|
|||||||
const preact = require('preact');
|
const preact = require('preact');
|
||||||
|
const key = require('keymaster');
|
||||||
|
|
||||||
function GamePanel(props) {
|
function GamePanel(props) {
|
||||||
const {
|
const {
|
||||||
@ -19,6 +20,8 @@ function GamePanel(props) {
|
|||||||
const playerTeam = game.teams.find(t => t.id === account.id);
|
const playerTeam = game.teams.find(t => t.id === account.id);
|
||||||
|
|
||||||
const incoming = playerTeam.incoming.map(inc => {
|
const incoming = playerTeam.incoming.map(inc => {
|
||||||
|
key.unbind('1');
|
||||||
|
key('1', () => setActiveIncoming(inc.id));
|
||||||
return (
|
return (
|
||||||
<div className="tile is-child" key={inc.id}>
|
<div className="tile is-child" key={inc.id}>
|
||||||
<div>{JSON.stringify(inc)}</div>
|
<div>{JSON.stringify(inc)}</div>
|
||||||
@ -26,13 +29,15 @@ function GamePanel(props) {
|
|||||||
className="button is-dark is-fullwidth"
|
className="button is-dark is-fullwidth"
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={() => setActiveIncoming(inc.id)}>
|
onClick={() => setActiveIncoming(inc.id)}>
|
||||||
{inc.skill}
|
(1) Block skill: {inc.skill}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
function PlayerCrypCard(cryp) {
|
function PlayerCrypCard(cryp) {
|
||||||
|
key.unbind('q');
|
||||||
|
key('q', () => setActiveSkill(cryp.id, 'Attack'));
|
||||||
if (activeIncoming) console.log('should be a pointer');
|
if (activeIncoming) console.log('should be a pointer');
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -64,7 +69,7 @@ function GamePanel(props) {
|
|||||||
type="submit"
|
type="submit"
|
||||||
onClick={() => setActiveSkill(cryp.id, 'Attack')}
|
onClick={() => setActiveSkill(cryp.id, 'Attack')}
|
||||||
>
|
>
|
||||||
Attack
|
(Q) Attack
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -109,7 +114,6 @@ function GamePanel(props) {
|
|||||||
|
|
||||||
function OpponentTeam(team) {
|
function OpponentTeam(team) {
|
||||||
const cryps = team.cryps.map(OpponentCrypCard);
|
const cryps = team.cryps.map(OpponentCrypCard);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="tile"
|
className="tile"
|
||||||
@ -121,23 +125,36 @@ function GamePanel(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// style={{ "min-height": "100%" }}
|
// style={{ "min-height": "100%" }}
|
||||||
|
function phaseText(phase){
|
||||||
|
switch(phase){
|
||||||
|
case 'Skill':
|
||||||
|
return "Choose abilities"
|
||||||
|
case 'Target':
|
||||||
|
return "Block abilities"
|
||||||
|
case 'Finish':
|
||||||
|
return "Game over"
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="tile is-ancestor">
|
<section className="columns">
|
||||||
<div className="tile is-parent is-vertical">
|
<div className="column is-2 title is-1">
|
||||||
<div className="tile is-parent">{otherTeams.map(OpponentTeam)}</div>
|
{phaseText(game.phase)}
|
||||||
<div className="tile">
|
|
||||||
<div className="title is-1">{game.phase}</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="tile">
|
<div className="column is-4">
|
||||||
|
{PlayerTeam(playerTeam, setActiveSkill)}
|
||||||
|
</div>
|
||||||
|
<div className="column is-4">
|
||||||
|
<div>
|
||||||
|
{otherTeams.map(OpponentTeam)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
{incoming}
|
{incoming}
|
||||||
</div>
|
</div>
|
||||||
<div className="tile is-parent footer" >{PlayerTeam(playerTeam, setActiveSkill)}</div>
|
|
||||||
</div>
|
|
||||||
<div className="tile is-parent is-4">
|
|
||||||
<div className="tile" >log</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div className="column is-2">
|
||||||
|
<div className="title is-4">log</div>
|
||||||
</div>
|
</div>
|
||||||
|
</section>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
client/src/keyboard.jsx
Normal file → Executable file
9
client/src/keyboard.jsx
Normal file → Executable file
@ -6,9 +6,18 @@ function setupKeys(store) {
|
|||||||
const state = store.getState();
|
const state = store.getState();
|
||||||
|
|
||||||
key.unbind('esc');
|
key.unbind('esc');
|
||||||
|
|
||||||
if (state.activeItem) {
|
if (state.activeItem) {
|
||||||
key('esc', () => store.dispatch(actions.setActiveItem(null)));
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user