log panel

This commit is contained in:
ntr 2019-04-03 22:19:54 +11:00
parent 0839cd5efc
commit a08a05a575
10 changed files with 64 additions and 60 deletions

View File

@ -153,7 +153,7 @@ header {
} }
.header-username { .header-username {
letter-spacing: 0.25em; letter-spacing: 0.05em;
font-size: 2em; font-size: 2em;
display: inline; display: inline;
} }
@ -485,10 +485,7 @@ header {
} }
.logs { .logs {
padding-left: 2em; flex: 0 0 100%;
display: flex;
flex-flow: row wrap;
flex: 0 0 20%;
} }
.selected-skills { .selected-skills {

View File

@ -13,6 +13,9 @@ export const setInstance = value => ({ type: SET_INSTANCE, value });
export const SET_GAME = 'SET_GAME'; export const SET_GAME = 'SET_GAME';
export const setGame = value => ({ type: SET_GAME, value }); export const setGame = value => ({ type: SET_GAME, value });
export const SET_SHOW_LOG = 'SET_SHOW_LOG';
export const setShowLog = value => ({ type: SET_SHOW_LOG, value });
export const SET_COMBINER = 'SET_COMBINER'; 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) });

View File

@ -1,9 +1,9 @@
const preact = require('preact'); const preact = require('preact');
const { Component } = require('preact');
const range = require('lodash/range'); const range = require('lodash/range');
const { stringSort } = require('./../utils'); const { stringSort } = require('./../utils');
const molecule = require('./molecule'); const molecule = require('./molecule');
const SpawnButton = require('./spawn.button');
const idSort = stringSort('id'); const idSort = stringSort('id');
@ -13,40 +13,6 @@ const COLOURS = [
'#3498db', '#3498db',
]; ];
class SpawnButton extends Component {
toggle(e) {
this.setState({ enabled: e });
}
render({ spawn }, { enabled }) {
let spawnName = null;
return (
<div
className="menu-cryp-ctr spawn-btn">
<div
className="menu-cryp"
onClick={() => this.toggle(!this.enabled)} >
<h2>+</h2>
<input
className="login-input"
type="text"
disabled={!enabled}
placeholder="name"
onChange={e => spawnName = e.target.value}
/>
<button
className="login-btn"
disabled={!enabled}
onClick={() => spawn(spawnName)}
type="submit">
spawn
</button>
</div>
</div>
);
}
}
function CrypList(args) { function CrypList(args) {
const { const {
cryps, cryps,
@ -79,6 +45,7 @@ function CrypList(args) {
const instanceJoin = ( const instanceJoin = (
<button <button
className={`menu-instance-btn full right ${instanceJoinHidden ? 'hidden' : ''}`} className={`menu-instance-btn full right ${instanceJoinHidden ? 'hidden' : ''}`}
disabled={instanceJoinHidden}
onClick={() => sendInstanceJoin()}> onClick={() => sendInstanceJoin()}>
Join New Instance Join New Instance
</button> </button>
@ -113,7 +80,7 @@ function CrypList(args) {
: 1; : 1;
const spawnButtons = range(spawnButtonsNum) const spawnButtons = range(spawnButtonsNum)
.map(() => <SpawnButton key={Date.now()} spawn={name => sendCrypSpawn(name)} />); .map(i => <SpawnButton key={i} i={i} spawn={name => sendCrypSpawn(name)} />);
return ( return (
<div className="menu-cryps"> <div className="menu-cryps">

View File

@ -16,11 +16,43 @@ function GamePanel(props) {
setActiveSkill, setActiveSkill,
selectSkillTarget, selectSkillTarget,
account, account,
showLog,
toggleLog,
quit, quit,
} = props; } = props;
if (!game) return <div>...</div>; if (!game) return <div>...</div>;
const header = (
<div className="instance-hdr">
<button
className="game-back-btn instance-btn instance-ui-btn left"
onClick={quit}>
Back
</button>
<div className="spacer">
<div>&nbsp;</div>
</div>
<button
className="game-back-btn instance-btn instance-ui-btn left"
onClick={() => toggleLog(!showLog)}>
{showLog ? 'Game' : 'Log'}
</button>
</div>
);
if (showLog) {
const logs = game.log.map((l, i) => (<div key={i}>{l}</div>)).reverse();
return (
<main>
{header}
<div className="logs">
{logs}
</div>
</main>
);
}
function findCryp(id) { function findCryp(id) {
const team = game.teams.find(t => t.cryps.find(c => c.id === id)); const team = game.teams.find(t => t.cryps.find(c => c.id === id));
if (team) return team.cryps.find(c => c.id === id); if (team) return team.cryps.find(c => c.id === id);
@ -166,20 +198,10 @@ function GamePanel(props) {
const selectedSkills = playerTeam.cryps.map((c, i) => stackElement(c, i)); const selectedSkills = playerTeam.cryps.map((c, i) => stackElement(c, i));
const logs = game.log.map((l, i) => (<div key={i}>{l}</div>)).reverse();
return ( return (
<main> <main>
<div className="instance-hdr"> {header}
<button
className="game-back-btn instance-btn instance-ui-btn left"
onClick={quit}>
Back
</button>
<div className="spacer">
<div>&nbsp;</div>
</div>
</div>
{PlayerTeam(playerTeam, setActiveSkill)} {PlayerTeam(playerTeam, setActiveSkill)}
<div className="selected-skills"> <div className="selected-skills">
{selectedSkills} {selectedSkills}
@ -187,9 +209,6 @@ function GamePanel(props) {
<div className="team-opponent"> <div className="team-opponent">
{otherTeams.map(OpponentTeam)} {otherTeams.map(OpponentTeam)}
</div> </div>
<div className="logs">
{logs}
</div>
</main> </main>
); );
} }

View File

@ -11,7 +11,7 @@ const particlesJS = window.particlesJS;
const addState = connect( const addState = connect(
function receiveState(state) { function receiveState(state) {
const { ws, game, account, activeSkill, activeIncoming } = state; const { ws, game, account, showLog, activeSkill, activeIncoming } = state;
function selectSkillTarget(targetCrypId) { function selectSkillTarget(targetCrypId) {
if (activeSkill) { if (activeSkill) {
@ -32,7 +32,7 @@ const addState = connect(
return false; return false;
} }
return { game, account, activeSkill, activeIncoming, selectSkillTarget, selectIncomingTarget }; return { game, showLog, account, activeSkill, activeIncoming, selectSkillTarget, selectIncomingTarget };
}, },
function receiveDispatch(dispatch) { function receiveDispatch(dispatch) {
@ -49,7 +49,12 @@ const addState = connect(
dispatch(actions.setGame(null)); dispatch(actions.setGame(null));
} }
return { setActiveSkill, setActiveIncoming, quit }; function toggleLog(v) {
dispatch(actions.setShowLog(v));
}
return { setActiveSkill, setActiveIncoming, quit, toggleLog };
} }
); );

View File

@ -22,6 +22,7 @@ function Info(args) {
</div> </div>
); );
} }
if (info.type === 'cryp') { if (info.type === 'cryp') {
const stats = [ const stats = [
{ stat: 'hp', disp: 'Hp', colour: '#1FF01F' }, { stat: 'hp', disp: 'Hp', colour: '#1FF01F' },

View File

@ -21,6 +21,7 @@ const store = createStore(
combiner: reducers.combinerReducer, combiner: reducers.combinerReducer,
cryps: reducers.crypsReducer, cryps: reducers.crypsReducer,
game: reducers.gameReducer, game: reducers.gameReducer,
showLog: reducers.showLogReducer,
info: reducers.infoReducer, info: reducers.infoReducer,
instance: reducers.instanceReducer, instance: reducers.instanceReducer,
instances: reducers.instancesReducer, instances: reducers.instancesReducer,

View File

@ -80,6 +80,16 @@ function gameReducer(state = defaultGame, action) {
} }
} }
const defaultShowLog = false;
function showLogReducer(state = defaultShowLog, action) {
switch (action.type) {
case actions.SET_SHOW_LOG:
return action.value;
default:
return state;
}
}
const defaultReclaiming = false; const defaultReclaiming = false;
function reclaimingReducer(state = defaultReclaiming, action) { function reclaimingReducer(state = defaultReclaiming, action) {
switch (action.type) { switch (action.type) {
@ -116,6 +126,7 @@ module.exports = {
combinerReducer, combinerReducer,
crypsReducer, crypsReducer,
gameReducer, gameReducer,
showLogReducer,
instanceReducer, instanceReducer,
instancesReducer, instancesReducer,
reclaimingReducer, reclaimingReducer,

View File

@ -260,7 +260,7 @@ function createSocket(events) {
// if (!account) events.loginPrompt(); // if (!account) events.loginPrompt();
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
send({ method: 'account_login', params: { name: 'grepking', password: 'grepgrepgrep' } }); send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
} }
return true; return true;

View File

@ -61,7 +61,7 @@ const STATS = {
redDamage: { stat: 'red_damage', colour: 'red', svg: shapes.pentagon }, redDamage: { stat: 'red_damage', colour: 'red', svg: shapes.pentagon },
blueShield: { stat: 'blue_shield', colour: 'blue', svg: shapes.squircle }, blueShield: { stat: 'blue_shield', colour: 'blue', svg: shapes.squircle },
blueDamage: { stat: 'blue_damage', colour: 'blue', svg: shapes.circle }, blueDamage: { stat: 'blue_damage', colour: 'blue', svg: shapes.circle },
speed: { stat: 'speed', colour: 'yellow', svg: shapes.triangle }, speed: { stat: 'speed', colour: '', svg: shapes.triangle },
}; };
module.exports = { module.exports = {