diff --git a/client/src/Table.js b/client/src/Table.js index 265f1e3..53b55cf 100755 --- a/client/src/Table.js +++ b/client/src/Table.js @@ -278,7 +278,7 @@ const GameOrder = ({table}) => { const rollClick = (event) => { table.throwDice(); } - + if (!table.game) { return (<>>); } @@ -384,6 +384,10 @@ const Action = ({ table }) => { return table.shuffleTable(); }; + const tradeClick = (event) => { + table.startTrading(); + } + const rollClick = (event) => { table.throwDice(); } @@ -414,7 +418,7 @@ const Action = ({ table }) => { > } { table.game.state === 'normal' && <> - + { table.game.turn.roll === 7 && player && player.mustDiscard > 0 && @@ -535,6 +539,9 @@ class Table extends React.Component { this.rollDice = this.rollDice.bind(this); this.setGameState = this.setGameState.bind(this); this.shuffleTable = this.shuffleTable.bind(this); + this.startTrading = this.startTrading.bind(this); + this.acceptTrade = this.acceptTrade.bind(this); + this.cancelTrading = this.cancelTrading.bind(this); this.discard = this.discard.bind(this); this.passTurn = this.passTurn.bind(this); this.updateGame = this.updateGame.bind(this); @@ -621,6 +628,18 @@ class Table extends React.Component { }); } + startTrading() { + return this.sendAction('trade'); + } + + cancelTrading() { + return this.sendAction('trade', 'cancel'); + } + + acceptTrade(trade) { + return this.sendAction('trade', 'accept', trade); + } + discard(resources) { return this.sendAction('discard', undefined, resources); } diff --git a/client/src/Trade.css b/client/src/Trade.css index 627b629..f8ddbcb 100644 --- a/client/src/Trade.css +++ b/client/src/Trade.css @@ -30,11 +30,12 @@ } .Trade .PlayerColor { - width: 1em; - height: 1em; + width: 0.5em; + height: 0.5em; + margin: 0 0.25em 0 0; } -.Trade .TradePlayer { +.TradePlayer { display: flex; flex-direction: row; width: 100%; @@ -43,5 +44,17 @@ } .TradePlayer > * { - margin: 0 0.25em; + margin-right: 0.25em; } + +.TradeLine { + display: flex; + flex-direction: row; + align-items: center; + flex: 1; + justify-content: space-between; +} + +.TradeLine *:last-child { + align-self: flex-end; +} \ No newline at end of file diff --git a/client/src/Trade.js b/client/src/Trade.js index 602ea05..c11c799 100644 --- a/client/src/Trade.js +++ b/client/src/Trade.js @@ -4,60 +4,57 @@ import { getPlayerName } from './Common.js'; import PlayerColor from './PlayerColor.js'; import Paper from '@material-ui/core/Paper'; import Button from '@material-ui/core/Button'; -import Dice from './Dice.js'; const Trade = ({table}) => { - - const rollClick = (event) => { - table.throwDice(); - } - if (!table.game) { return (<>>); } - let players = [], hasRolled = true; + const isTurn = (table.game && table.game.turn && table.game.turn.color === table.game.color) ? true : false; + + const cancelClicked = (event) => { + table.cancelTrading(); + } + + let players = []; for (let color in table.game.players) { const item = table.game.players[color], name = getPlayerName(table.game.sessions, color); - if (color === table.game.color) { - hasRolled = item.orderRoll !== 0; - } - if (name) { - if (!item.orderRoll) { - item.orderRoll = 0; - } + if (name && table.game.name !== name) { players.push({ name: name, color: color, ...item }); } } players.sort((A, B) => { - if (A.order === B.order) { - if (A.orderRoll === B.orderRoll) { - return A.name.localeCompare(B.name); - } - return B.orderRoll - A.orderRoll; - } - return B.order - A.order; + return A.name.localeCompare(B.name); }); + if (isTurn && table.game.player && table.game.player.banks) { + table.game.player.banks.forEach(bank => { + players.push({ name: `Bank ${bank}`, color: undefined, gives: '*', gets: '2 wheat'}); + }) + } + players = players.map(item => -