diff --git a/src/components/farm/Board.jsx b/src/components/farm/Board.jsx index 81884e0..c3d79f0 100644 --- a/src/components/farm/Board.jsx +++ b/src/components/farm/Board.jsx @@ -1352,7 +1352,10 @@ class BoardApp extends React.Component {
- +
@@ -1383,25 +1386,55 @@ export default connect( )(BoardApp) class Card extends React.Component { + constructor(props) { + super(props); + this.state = { cash: this.props.cash, initialCash: this.props.cash }; + } + + static getDerivedStateFromProps(props, state) { + if (state.initialCash !== props.cash) { + return { + cash: props.cash, + initialCash: props.cash + } + } + return null; + } + + handleInput = e => { + const target = e.target; + let value = Math.min(Math.max(this.props.min, + parseInt(target.value)), this.props.max); + if (isNaN(value)) { value = this.props.min; } + this.setState({ cash: value }); + } + + handleSubmit = e => { + e.preventDefault(); + buy(this.props.ui.card.id, this.state.cash); + } + render () { const card = this.props.ui.card; let action = (null); switch (card.type) { case 'otb': action = (
-
- { e.preventDefault(); - buy(card.id, parseInt(document.getElementById('cash-input').value)); - return false; }}> + - +
$: - + {'\u00A0'},000
diff --git a/src/components/widgets.jsx b/src/components/widgets.jsx index 2bf6007..af6f40d 100644 --- a/src/components/widgets.jsx +++ b/src/components/widgets.jsx @@ -61,6 +61,7 @@ class Button extends React.Component { diff --git a/src/server/farm.scm b/src/server/farm.scm index 13cd055..9ff45b4 100644 --- a/src/server/farm.scm +++ b/src/server/farm.scm @@ -804,7 +804,10 @@ (string->symbol (alist-ref 'crop otb))) (string->symbol (alist-ref 'crop otb)) (alist-ref 'amount otb) - (* (alist-ref 'cash msg) 1000) + (* (or (and (number? (alist-ref 'cash msg)) + (alist-ref 'cash msg)) + 0) + 1000) player game) (set! (player-otbs player) @@ -1691,8 +1694,13 @@ (thread-join! *server-thread*))) ;; TODO -;; audit was called but didn't cause anything on year end +;; make game finished display results. ;; make sure two players can't have the same name ;; bug: harvest action multiplayer doesn't flow right for other players ;; info actions should look better -;; bug: dice shows no value when landing on christmas vacation +;; limit to 20 cows +;; don't give extra money for extra tractors +;; you can get $50 from harvest +;; buy ifs with blank box +;; ran out of otbs +;; bug: new websocket messages should not reset IFS card selection