From 4346790330eac29133597b94bf86e6fb9e0294f2 Mon Sep 17 00:00:00 2001 From: ntr Date: Fri, 29 Mar 2019 20:14:32 +1100 Subject: [PATCH] bit o cleaning --- html-client/src/components/body.component.jsx | 25 +----- .../{game.jsx => game.component.jsx} | 79 ++++++++----------- html-client/src/components/game.container.js | 9 ++- .../src/components/game.join.button.jsx | 42 ---------- .../components/instance.cryps.component.jsx | 22 ------ .../src/components/item.list.container.js | 20 ----- html-client/src/components/item.list.jsx | 37 --------- html-client/src/components/logs.jsx | 19 ----- html-client/src/components/navbar.jsx | 47 ----------- 9 files changed, 41 insertions(+), 259 deletions(-) rename html-client/src/components/{game.jsx => game.component.jsx} (66%) delete mode 100644 html-client/src/components/game.join.button.jsx delete mode 100644 html-client/src/components/instance.cryps.component.jsx delete mode 100644 html-client/src/components/item.list.container.js delete mode 100644 html-client/src/components/item.list.jsx delete mode 100644 html-client/src/components/logs.jsx delete mode 100644 html-client/src/components/navbar.jsx diff --git a/html-client/src/components/body.component.jsx b/html-client/src/components/body.component.jsx index fd23e110..ed411225 100644 --- a/html-client/src/components/body.component.jsx +++ b/html-client/src/components/body.component.jsx @@ -8,7 +8,6 @@ const CrypSpawnContainer = require('./cryp.spawn.container'); const CrypListContainer = require('./cryp.list.container'); const GameContainer = require('./game.container'); const InstanceContainer = require('./instance.container'); -const Logs = require('./logs'); const addState = connect( (state) => { @@ -20,35 +19,15 @@ const addState = connect( } return { game, instance }; - }, - (dispatch) => { - function setGame(game) { - dispatch(actions.setGame(game)); - } - return { setGame }; - }, + } ); function renderBody(props) { - const { game, instance, setGame } = props; + const { game, instance } = props; if (game) { return (
-
-
- -
-
- -
-
); } diff --git a/html-client/src/components/game.jsx b/html-client/src/components/game.component.jsx similarity index 66% rename from html-client/src/components/game.jsx rename to html-client/src/components/game.component.jsx index 83a05744..fb167f6e 100644 --- a/html-client/src/components/game.jsx +++ b/html-client/src/components/game.component.jsx @@ -15,6 +15,7 @@ function GamePanel(props) { selectSkillTarget, selectIncomingTarget, account, + quit, } = props; if (!game) return
...
; @@ -58,44 +59,22 @@ function GamePanel(props) { ); } - function PlayerCrypCard(cryp) { - const skills = cryp.skills.map((skill, i) => { - const hotkey = SKILL_HOT_KEYS[i]; - key.unbind(hotkey); - key(hotkey, () => setActiveSkill(cryp.id, skill)); - - return ( - - ); - }); - - const effects = cryp.effects.map((effect, i) => ( -
{effect} for {effect.turns}T
- )); - + function PlayerCryp(cryp) { return (
selectIncomingTarget(cryp.id)} - className="tile is-vertical"> + onClick={() => selectIncomingTarget(cryp.id)}> {Cryp(cryp, setActiveSkill)}
); } function PlayerTeam(team) { - const cryps = team.cryps.map(c => PlayerCrypCard(c, setActiveSkill)); + const cryps = team.cryps.map(c => PlayerCryp(c, setActiveSkill)); return ( -
+
{cryps}
); @@ -107,25 +86,24 @@ function GamePanel(props) { )); return ( -
selectSkillTarget(cryp.id)} > -
-
-
-
-

{cryp.name}

+
+
+
+
+

{cryp.name}

-
-
+
+
-
{cryp.hp.value} / {cryp.hp.value} HP
- - +
{cryp.hp.value} / {cryp.hp.value} HP
+
{effects}
@@ -148,19 +126,28 @@ function GamePanel(props) {
- {playerTeam.id} - {PlayerTeam(playerTeam, setActiveSkill)} +
-
- Round X -
- -
- {otherTeams.id} - {otherTeams.map(OpponentTeam)} +
+
 
+
+ {playerTeam.id} + {PlayerTeam(playerTeam, setActiveSkill)} +
+
+ {otherTeams.id} + {otherTeams.map(OpponentTeam)} +
+
+ {logs} +
); diff --git a/html-client/src/components/game.container.js b/html-client/src/components/game.container.js index 17a41dba..64149b37 100644 --- a/html-client/src/components/game.container.js +++ b/html-client/src/components/game.container.js @@ -2,7 +2,7 @@ const { connect } = require('preact-redux'); const actions = require('../actions'); -const Game = require('./game'); +const Game = require('./game.component'); const addState = connect( function receiveState(state) { @@ -10,7 +10,7 @@ const addState = connect( function selectSkillTarget(targetCrypId) { if (activeSkill) { - return ws.sendGameSkill(game.id, activeSkill.crypId, targetCrypId, activeSkill.skill.skill); + return ws.sendGameSkill(game.id, activeSkill.crypId, targetCrypId, activeSkill.skill); } return false; } @@ -39,8 +39,11 @@ const addState = connect( dispatch(actions.setActiveIncoming(skillId)); } + function quit() { + dispatch(actions.setGame(null)); + } - return { setActiveSkill, setActiveIncoming }; + return { setActiveSkill, setActiveIncoming, quit }; } ); diff --git a/html-client/src/components/game.join.button.jsx b/html-client/src/components/game.join.button.jsx deleted file mode 100644 index 35c56555..00000000 --- a/html-client/src/components/game.join.button.jsx +++ /dev/null @@ -1,42 +0,0 @@ -const preact = require('preact'); -const { connect } = require('preact-redux'); - -const addState = connect( - (state) => { - const { ws, cryps } = state; - function sendGameJoin(gameId) { - return ws.sendGameJoin(gameId, [cryps[0].id]); - } - - return { account: state.account, sendGameJoin }; - }, -); - -function GameJoinButton({ account, sendGameJoin }) { - let gameId = ''; - - if (!account) return
...
; - - return ( -
-
- (gameId = e.target.value)} - /> -
-
- -
-
- ); -} - -module.exports = addState(GameJoinButton); diff --git a/html-client/src/components/instance.cryps.component.jsx b/html-client/src/components/instance.cryps.component.jsx deleted file mode 100644 index 5cda62a4..00000000 --- a/html-client/src/components/instance.cryps.component.jsx +++ /dev/null @@ -1,22 +0,0 @@ -const preact = require('preact'); -// const key = require('keymaster'); - -function Vbox(args) { - const { - instance, - combiner, - sendVboxAccept, - sendVboxDiscard, - sendVboxReclaim, - sendVboxCombine, - } = args; - - const { cryps } = instance; - - return ( -
-
- ); -} - -module.exports = Vbox; \ No newline at end of file diff --git a/html-client/src/components/item.list.container.js b/html-client/src/components/item.list.container.js deleted file mode 100644 index bfa8731d..00000000 --- a/html-client/src/components/item.list.container.js +++ /dev/null @@ -1,20 +0,0 @@ -const { connect } = require('preact-redux'); -const actions = require('../actions'); - -const ItemList = require('./item.list'); - -const addState = connect( - function receiveState(state) { - const { items } = state; - return { items }; - }, - function receiveDispatch(dispatch) { - function setActiveItem(id) { - dispatch(actions.setActiveItem(id)) - } - - return { setActiveItem }; - } -); - -module.exports = addState(ItemList); diff --git a/html-client/src/components/item.list.jsx b/html-client/src/components/item.list.jsx deleted file mode 100644 index b003b5b8..00000000 --- a/html-client/src/components/item.list.jsx +++ /dev/null @@ -1,37 +0,0 @@ -// eslint-disable-next-line -const preact = require('preact'); - -function ItemList({ items, setActiveItem }) { - if (!items) return
...
; - const itemPanels = items.map(item => ( - -
-
-
-
-

{item.action}

-

-
-
-
- -
-
-
-
- -
- )); - return ( -
- {itemPanels} -
- ); -} - -module.exports = ItemList; diff --git a/html-client/src/components/logs.jsx b/html-client/src/components/logs.jsx deleted file mode 100644 index 77b4b3dd..00000000 --- a/html-client/src/components/logs.jsx +++ /dev/null @@ -1,19 +0,0 @@ -const preact = require('preact'); -const { connect } = require('preact-redux'); - -// const Logs = require('./logs'); - -const addState = connect( - function receiveState(state) { - const { game } = state; - return { game }; - } -); - -function Logs(props) { - const { game } = props; - const logs = game.log.reverse().map((l, i) => (
{l}
)); - return (
{logs}
); -} - -module.exports = addState(Logs); diff --git a/html-client/src/components/navbar.jsx b/html-client/src/components/navbar.jsx deleted file mode 100644 index d45dc8e8..00000000 --- a/html-client/src/components/navbar.jsx +++ /dev/null @@ -1,47 +0,0 @@ -const preact = require('preact'); - -// components all the way down -const Icon = name => ( - - {name} - - -); - -// the css attribute name `class` is reserved in js -// so in react you have to call it `className` -function Navbar() { - const NAMES = ['Mashy', 'ntr']; - - return ( -
- - {NAMES.map(Icon)} -
- ); - // map is a function that is called on every element of an array - // so in this ^^ case it calls Icon('Mashy') which returns some jsx - // that gets put into the dom -} - -module.exports = Navbar;