Merge branch 'battleui'

This commit is contained in:
ntr 2018-10-24 15:13:42 +11:00
commit 5886f9413b
3 changed files with 74 additions and 21 deletions

39
client/src/components/body.component.jsx Normal file → Executable file
View File

@ -1,5 +1,7 @@
// 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');
@ -7,13 +9,41 @@ const GameJoinButton = require('./game.join.button');
const CrypListContainer = require('./cryp.list.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>
)
}
return (
<section className="columns">
<div className="column is-4">
<div className="column">
<CrypSpawnContainer />
<GameJoinButton />
<CrypSpawnContainer />
</div>
<div className="column">
<div className="columns">
@ -26,11 +56,8 @@ function renderBody() {
</div>
</div>
</div>
<div className="column">
<GameContainer />
</div>
</section>
);
}
module.exports = renderBody;
module.exports = addState(renderBody);

47
client/src/components/game.jsx Normal file → Executable file
View File

@ -1,4 +1,5 @@
const preact = require('preact');
const key = require('keymaster');
function GamePanel(props) {
const {
@ -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 (
<div className="tile is-child" key={inc.id}>
<div>{JSON.stringify(inc)}</div>
@ -26,13 +29,16 @@ function GamePanel(props) {
className="button is-dark is-fullwidth"
type="submit"
onClick={() => setActiveIncoming(inc.id)}>
{inc.skill}
(1) Block skill: {inc.skill}
</button>
</div>
);
});
function PlayerCrypCard(cryp) {
key.unbind('q');
key('q', () => setActiveSkill(cryp.id, 'Attack'));
if (activeIncoming) console.log('should be a pointer');
return (
<div
key={cryp.id}
@ -63,7 +69,7 @@ function GamePanel(props) {
type="submit"
onClick={() => setActiveSkill(cryp.id, 'Attack')}
>
Attack
(Q) Attack
</button>
</div>
);
@ -108,7 +114,6 @@ function GamePanel(props) {
function OpponentTeam(team) {
const cryps = team.cryps.map(OpponentCrypCard);
return (
<div
className="tile"
@ -120,24 +125,36 @@ function GamePanel(props) {
}
// 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 (
<div className="tile is-ancestor">
<div className="tile is-parent is-vertical">
<div className="tile is-parent">{otherTeams.map(OpponentTeam)}</div>
<div className="tile is-child">
<div className="title">{game.phase}</div>
<div className="subtitle">{game.id}</div>
<section className="columns">
<div className="column is-2 title is-1">
{phaseText(game.phase)}
</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}
</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 className="column is-2">
<div className="title is-4">log</div>
</div>
</section>
)
}

9
client/src/keyboard.jsx Normal file → Executable file
View File

@ -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)));
}
});
}