team nav
This commit is contained in:
parent
fd7e634d72
commit
0383658360
@ -41,7 +41,7 @@ export const SET_COMBINER = 'SET_COMBINER';
|
|||||||
export const setCombiner = value => ({ type: SET_COMBINER, value: Array.from(value) });
|
export const setCombiner = value => ({ type: SET_COMBINER, value: Array.from(value) });
|
||||||
|
|
||||||
export const SET_SELECTED_CRYPS = 'SET_SELECTED_CRYPS';
|
export const SET_SELECTED_CRYPS = 'SET_SELECTED_CRYPS';
|
||||||
export const setSelectedCryps = value => ({ type: SET_SELECTED_CRYPS, value: Array.from(value) });
|
export const setTeam = value => ({ type: SET_SELECTED_CRYPS, value: Array.from(value) });
|
||||||
|
|
||||||
export const SET_ACTIVE_SKILL = 'SET_ACTIVE_SKILL';
|
export const SET_ACTIVE_SKILL = 'SET_ACTIVE_SKILL';
|
||||||
export const setActiveSkill = (crypId, skill) => ({ type: SET_ACTIVE_SKILL, value: crypId ? { crypId, skill } : null });
|
export const setActiveSkill = (crypId, skill) => ({ type: SET_ACTIVE_SKILL, value: crypId ? { crypId, skill } : null });
|
||||||
|
|||||||
@ -4,7 +4,7 @@ const { Component } = require('preact');
|
|||||||
|
|
||||||
const addState = connect(
|
const addState = connect(
|
||||||
function receiveState(state) {
|
function receiveState(state) {
|
||||||
const { ws, selectedCryps } = state;
|
const { ws, team } = state;
|
||||||
|
|
||||||
function sendInstanceNew(sCryps, name, players) {
|
function sendInstanceNew(sCryps, name, players) {
|
||||||
if (sCryps.length) {
|
if (sCryps.length) {
|
||||||
@ -15,7 +15,7 @@ const addState = connect(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
sendInstanceNew,
|
sendInstanceNew,
|
||||||
selectedCryps,
|
team,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -45,12 +45,12 @@ class InstanceCreateForm extends Component {
|
|||||||
|
|
||||||
handleSubmit(event) {
|
handleSubmit(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.sendInstanceNew(this.props.selectedCryps, this.state.name, this.state.players);
|
this.sendInstanceNew(this.props.team, this.state.name, this.state.players);
|
||||||
this.setState({ name: '', players: 2 });
|
this.setState({ name: '', players: 2 });
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const disabled = !this.props.selectedCryps.every(c => c);
|
const disabled = !this.props.team.every(c => c);
|
||||||
|
|
||||||
const classes = `create-form ${disabled ? 'disabled' : ''}`;
|
const classes = `create-form ${disabled ? 'disabled' : ''}`;
|
||||||
return (
|
return (
|
||||||
|
|||||||
103
client/src/components/list.jsx
Normal file
103
client/src/components/list.jsx
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
const { connect } = require('preact-redux');
|
||||||
|
const preact = require('preact');
|
||||||
|
|
||||||
|
const { NULL_UUID } = require('./../utils');
|
||||||
|
const actions = require('./../actions');
|
||||||
|
const InstanceCreateForm = require('./instance.create.form');
|
||||||
|
|
||||||
|
const addState = connect(
|
||||||
|
function receiveState(state) {
|
||||||
|
const { ws, cryps, team, instances, account } = state;
|
||||||
|
|
||||||
|
function sendInstanceJoin(instance) {
|
||||||
|
if (team.length) {
|
||||||
|
return ws.sendInstanceJoin(instance.id, team);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendInstanceState(instance) {
|
||||||
|
return ws.sendInstanceState(instance.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendInstanceList() {
|
||||||
|
return ws.sendAccountInstances();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
account,
|
||||||
|
cryps,
|
||||||
|
team,
|
||||||
|
sendInstanceJoin,
|
||||||
|
sendInstanceState,
|
||||||
|
sendInstanceList,
|
||||||
|
instances,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
function List(args) {
|
||||||
|
const {
|
||||||
|
account,
|
||||||
|
team,
|
||||||
|
sendInstanceState,
|
||||||
|
sendInstanceJoin,
|
||||||
|
sendInstanceList,
|
||||||
|
instances,
|
||||||
|
} = args;
|
||||||
|
|
||||||
|
function instanceList() {
|
||||||
|
if (!instances) return <div>...</div>;
|
||||||
|
|
||||||
|
const instancePanels = instances.map(instance => {
|
||||||
|
const player = instance.players.find(p => p.id === account.id);
|
||||||
|
const scoreText = player
|
||||||
|
? `${player.score.wins} : ${player.score.losses}`
|
||||||
|
: '';
|
||||||
|
|
||||||
|
function instanceClick() {
|
||||||
|
if (!player) return sendInstanceJoin(instance);
|
||||||
|
return sendInstanceState(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tr key={instance.id}
|
||||||
|
className="right"
|
||||||
|
onClick={instanceClick} >
|
||||||
|
<td>{instance.name}</td>
|
||||||
|
<td>{instance.players.length} / {instance.max_players}</td>
|
||||||
|
<td>{scoreText}</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="menu-instance-list" >
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>instance name</th>
|
||||||
|
<th>players</th>
|
||||||
|
<th>status</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{instancePanels}
|
||||||
|
<tr className="right" onClick={() => sendInstanceList()}>
|
||||||
|
<td colSpan={3} >↺</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<InstanceCreateForm />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="menu">
|
||||||
|
{instanceList()}
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = addState(List);
|
||||||
@ -3,9 +3,10 @@ const preact = require('preact');
|
|||||||
const { connect } = require('preact-redux');
|
const { connect } = require('preact-redux');
|
||||||
|
|
||||||
const LoginContainer = require('./login.container');
|
const LoginContainer = require('./login.container');
|
||||||
const MenuContainer = require('./menu.container');
|
|
||||||
const GameContainer = require('./game.container');
|
const GameContainer = require('./game.container');
|
||||||
const InstanceContainer = require('./instance.container');
|
const InstanceContainer = require('./instance.container');
|
||||||
|
const Team = require('./team');
|
||||||
|
const List = require('./list');
|
||||||
|
|
||||||
const addState = connect(
|
const addState = connect(
|
||||||
state => {
|
state => {
|
||||||
@ -42,10 +43,11 @@ function renderBody(props) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (nav === 'list')
|
if (nav === 'team') return <Team />;
|
||||||
|
if (nav === 'list') return <List />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuContainer />
|
<Team />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,8 +20,8 @@ function Menu(args) {
|
|||||||
const {
|
const {
|
||||||
account,
|
account,
|
||||||
cryps,
|
cryps,
|
||||||
selectedCryps,
|
team,
|
||||||
setSelectedCryps,
|
setTeam,
|
||||||
sendInstanceState,
|
sendInstanceState,
|
||||||
sendPlayerMmCrypsSet,
|
sendPlayerMmCrypsSet,
|
||||||
sendInstanceJoin,
|
sendInstanceJoin,
|
||||||
@ -55,7 +55,7 @@ function Menu(args) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const instanceJoinHidden = !selectedCryps.every(c => !!c);
|
const instanceJoinHidden = !team.every(c => !!c);
|
||||||
|
|
||||||
// const mmSet = (
|
// const mmSet = (
|
||||||
// <button
|
// <button
|
||||||
@ -95,21 +95,21 @@ function Menu(args) {
|
|||||||
// so much for dumb components
|
// so much for dumb components
|
||||||
function selectCryp(id) {
|
function selectCryp(id) {
|
||||||
// remove
|
// remove
|
||||||
const i = selectedCryps.findIndex(sid => sid === id);
|
const i = team.findIndex(sid => sid === id);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
selectedCryps[i] = null;
|
team[i] = null;
|
||||||
return setSelectedCryps(selectedCryps);
|
return setTeam(team);
|
||||||
}
|
}
|
||||||
|
|
||||||
// window insert
|
// window insert
|
||||||
const insert = selectedCryps.findIndex(j => j === null);
|
const insert = team.findIndex(j => j === null);
|
||||||
if (insert === -1) return setSelectedCryps([id, null, null]);
|
if (insert === -1) return setTeam([id, null, null]);
|
||||||
selectedCryps[insert] = id;
|
team[insert] = id;
|
||||||
return setSelectedCryps(selectedCryps);
|
return setTeam(team);
|
||||||
}
|
}
|
||||||
|
|
||||||
const crypPanels = cryps.sort(idSort).map(cryp => {
|
const crypPanels = cryps.sort(idSort).map(cryp => {
|
||||||
const colour = selectedCryps.indexOf(cryp.id);
|
const colour = team.indexOf(cryp.id);
|
||||||
const selected = colour > -1;
|
const selected = colour > -1;
|
||||||
|
|
||||||
const borderColour = selected ? COLOURS[colour] : '#000000';
|
const borderColour = selected ? COLOURS[colour] : '#000000';
|
||||||
|
|||||||
@ -5,18 +5,18 @@ const actions = require('./../actions');
|
|||||||
|
|
||||||
const addState = connect(
|
const addState = connect(
|
||||||
function receiveState(state) {
|
function receiveState(state) {
|
||||||
const { ws, cryps, selectedCryps, instances, account } = state;
|
const { ws, cryps, team, instances, account } = state;
|
||||||
|
|
||||||
function sendInstanceJoin(instance) {
|
function sendInstanceJoin(instance) {
|
||||||
if (selectedCryps.length) {
|
if (team.length) {
|
||||||
return ws.sendInstanceJoin(instance.id, selectedCryps);
|
return ws.sendInstanceJoin(instance.id, team);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPlayerMmCrypsSet() {
|
function sendPlayerMmCrypsSet() {
|
||||||
if (selectedCryps.length) {
|
if (team.length) {
|
||||||
return ws.sendPlayerMmCrypsSet(selectedCryps);
|
return ws.sendPlayerMmCrypsSet(team);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ const addState = connect(
|
|||||||
return {
|
return {
|
||||||
account,
|
account,
|
||||||
cryps,
|
cryps,
|
||||||
selectedCryps,
|
team,
|
||||||
sendInstanceJoin,
|
sendInstanceJoin,
|
||||||
sendInstanceState,
|
sendInstanceState,
|
||||||
sendInstanceList,
|
sendInstanceList,
|
||||||
@ -47,12 +47,12 @@ const addState = connect(
|
|||||||
},
|
},
|
||||||
|
|
||||||
function receiveDispatch(dispatch) {
|
function receiveDispatch(dispatch) {
|
||||||
function setSelectedCryps(crypIds) {
|
function setTeam(crypIds) {
|
||||||
dispatch(actions.setSelectedCryps(crypIds));
|
dispatch(actions.setTeam(crypIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setSelectedCryps,
|
setTeam,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@ -11,6 +11,7 @@ const addState = connect(
|
|||||||
ws,
|
ws,
|
||||||
account,
|
account,
|
||||||
instances,
|
instances,
|
||||||
|
team,
|
||||||
cryps,
|
cryps,
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
@ -21,6 +22,8 @@ const addState = connect(
|
|||||||
return {
|
return {
|
||||||
account,
|
account,
|
||||||
instances,
|
instances,
|
||||||
|
team,
|
||||||
|
cryps,
|
||||||
sendInstanceState,
|
sendInstanceState,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -49,6 +52,8 @@ function Nav(args) {
|
|||||||
const {
|
const {
|
||||||
account,
|
account,
|
||||||
sendInstanceState,
|
sendInstanceState,
|
||||||
|
team,
|
||||||
|
cryps,
|
||||||
instances,
|
instances,
|
||||||
|
|
||||||
navTo,
|
navTo,
|
||||||
@ -57,17 +62,23 @@ function Nav(args) {
|
|||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
const joined = instances.map((i, j) => (
|
const joined = instances.map((i, j) => (
|
||||||
<button key={j} onClick={() => sendInstanceState(i)} >{i.name}</button>
|
<button key={i.id} onClick={() => sendInstanceState(i)} >{i.name}</button>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
const teamElements = team.map((c, i) => {
|
||||||
|
if (c) {
|
||||||
|
const cryp = cryps.find(f => f.id === c);
|
||||||
|
return <button key={c} onClick={() => navTo('team')}>{cryp.name}</button>;
|
||||||
|
}
|
||||||
|
return <button key={i} onClick={() => navTo('team')}>+</button>;
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav>
|
<nav>
|
||||||
<h2>Team</h2>
|
<h2>Team</h2>
|
||||||
<button onClick={() => navTo('team')}>spawn</button>
|
{teamElements}
|
||||||
<button onClick={() => navTo('team')}>select</button>
|
|
||||||
<h2>Instances</h2>
|
<h2>Instances</h2>
|
||||||
<button onClick={() => navTo('instances')}>list</button>
|
<button onClick={() => navTo('list')}>list</button>
|
||||||
<button onClick={() => navTo('instances')}>new</button>
|
|
||||||
<hr />
|
<hr />
|
||||||
{joined}
|
{joined}
|
||||||
<h2>Hax</h2>
|
<h2>Hax</h2>
|
||||||
|
|||||||
108
client/src/components/team.jsx
Normal file
108
client/src/components/team.jsx
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
const preact = require('preact');
|
||||||
|
const { connect } = require('preact-redux');
|
||||||
|
const range = require('lodash/range');
|
||||||
|
|
||||||
|
const actions = require('./../actions');
|
||||||
|
const { NULL_UUID } = require('./../utils');
|
||||||
|
const { stringSort, crypAvatar } = require('./../utils');
|
||||||
|
const SpawnButton = require('./spawn.button');
|
||||||
|
|
||||||
|
const idSort = stringSort('id');
|
||||||
|
|
||||||
|
const COLOURS = [
|
||||||
|
'#a52a2a',
|
||||||
|
'#1FF01F',
|
||||||
|
'#3498db',
|
||||||
|
];
|
||||||
|
|
||||||
|
const addState = connect(
|
||||||
|
function receiveState(state) {
|
||||||
|
const { ws, cryps, team, account } = state;
|
||||||
|
|
||||||
|
function sendCrypSpawn(name) {
|
||||||
|
return ws.sendCrypSpawn(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
account,
|
||||||
|
cryps,
|
||||||
|
team,
|
||||||
|
sendCrypSpawn,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
function receiveDispatch(dispatch) {
|
||||||
|
function setTeam(crypIds) {
|
||||||
|
dispatch(actions.setTeam(crypIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
setTeam,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
function Team(args) {
|
||||||
|
const {
|
||||||
|
account,
|
||||||
|
cryps,
|
||||||
|
team,
|
||||||
|
|
||||||
|
setTeam,
|
||||||
|
sendCrypSpawn,
|
||||||
|
} = args;
|
||||||
|
|
||||||
|
if (!cryps) return <div></div>;
|
||||||
|
|
||||||
|
// redux limitation + suggested workaround
|
||||||
|
// so much for dumb components
|
||||||
|
function selectCryp(id) {
|
||||||
|
// remove
|
||||||
|
const i = team.findIndex(sid => sid === id);
|
||||||
|
if (i > -1) {
|
||||||
|
team[i] = null;
|
||||||
|
return setTeam(team);
|
||||||
|
}
|
||||||
|
|
||||||
|
// window insert
|
||||||
|
const insert = team.findIndex(j => j === null);
|
||||||
|
if (insert === -1) return setTeam([id, null, null]);
|
||||||
|
team[insert] = id;
|
||||||
|
return setTeam(team);
|
||||||
|
}
|
||||||
|
|
||||||
|
const crypPanels = cryps.sort(idSort).map(cryp => {
|
||||||
|
const colour = team.indexOf(cryp.id);
|
||||||
|
const selected = colour > -1;
|
||||||
|
|
||||||
|
const borderColour = selected ? COLOURS[colour] : '#000000';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={cryp.id}
|
||||||
|
className="menu-cryp-ctr">
|
||||||
|
<div
|
||||||
|
className="menu-cryp"
|
||||||
|
style={ { 'border-color': borderColour || 'whitesmoke' } }
|
||||||
|
onClick={() => selectCryp(cryp.id)} >
|
||||||
|
{crypAvatar(cryp.name)}
|
||||||
|
<h2>{cryp.name}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const spawnButtonsNum = (3 - cryps.length % 3);
|
||||||
|
|
||||||
|
const spawnButtons = range(spawnButtonsNum)
|
||||||
|
.map(i => <SpawnButton key={i} i={i} spawn={name => sendCrypSpawn(name)} />);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="menu-cryps">
|
||||||
|
{crypPanels}
|
||||||
|
{spawnButtons}
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = addState(Team);
|
||||||
@ -28,7 +28,7 @@ module.exports = {
|
|||||||
player: createReducer(null, actions.SET_PLAYER),
|
player: createReducer(null, actions.SET_PLAYER),
|
||||||
reclaiming: createReducer(false, actions.SET_RECLAIMING),
|
reclaiming: createReducer(false, actions.SET_RECLAIMING),
|
||||||
resolution: createReducer(null, actions.SET_RESOLUTION),
|
resolution: createReducer(null, actions.SET_RESOLUTION),
|
||||||
selectedCryps: createReducer([null, null, null], actions.SET_SELECTED_CRYPS),
|
team: createReducer([null, null, null], actions.SET_SELECTED_CRYPS),
|
||||||
showLog: createReducer(false, actions.SET_SHOW_LOG),
|
showLog: createReducer(false, actions.SET_SHOW_LOG),
|
||||||
vboxHidden: createReducer(false, actions.SET_VBOX_HIDDEN),
|
vboxHidden: createReducer(false, actions.SET_VBOX_HIDDEN),
|
||||||
vboxHighlight: createReducer([], actions.SET_VBOX_HIGHLIGHT),
|
vboxHighlight: createReducer([], actions.SET_VBOX_HIGHLIGHT),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user