Cleaning up and improving item card buying process.
This commit is contained in:
@@ -1352,7 +1352,10 @@ class BoardApp extends React.Component {
|
|||||||
<CardList ui={this.props.ui} />
|
<CardList ui={this.props.ui} />
|
||||||
</div>
|
</div>
|
||||||
<div className='cell medium-auto'>
|
<div className='cell medium-auto'>
|
||||||
<Card ui={this.props.ui} />
|
<Card ui={this.props.ui}
|
||||||
|
min={(this.props.ui.card.total * 0.2) / 1000}
|
||||||
|
max={Math.floor(Math.min(this.props.player.cash / 1000, this.props.ui.card.total / 1000))}
|
||||||
|
cash={(this.props.ui.card.total * 0.2) / 1000} />
|
||||||
</div>
|
</div>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
@@ -1383,25 +1386,55 @@ export default connect(
|
|||||||
)(BoardApp)
|
)(BoardApp)
|
||||||
|
|
||||||
class Card extends React.Component {
|
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 () {
|
render () {
|
||||||
const card = this.props.ui.card;
|
const card = this.props.ui.card;
|
||||||
let action = (null);
|
let action = (null);
|
||||||
switch (card.type) {
|
switch (card.type) {
|
||||||
case 'otb': action = (
|
case 'otb': action = (
|
||||||
<div className='card-action'>
|
<div className='card-action'>
|
||||||
<form onSubmit={(e) =>
|
<form onSubmit={this.handleSubmit}>
|
||||||
{ e.preventDefault();
|
|
||||||
buy(card.id, parseInt(document.getElementById('cash-input').value));
|
|
||||||
return false; }}>
|
|
||||||
<Row collapse='true'>
|
<Row collapse='true'>
|
||||||
<Col width='2'>
|
<Col width='2'>
|
||||||
<Button className='tiny' type='submit'>Buy</Button>
|
<Button className='tiny'
|
||||||
|
disabled={this.props.max < this.props.min}
|
||||||
|
type='submit'>Buy</Button>
|
||||||
</Col>
|
</Col>
|
||||||
<Col width='4' />
|
<Col width='4' />
|
||||||
<Col width='6'>
|
<Col width='6'>
|
||||||
<div className='money'>
|
<div className='money'>
|
||||||
$:
|
$:
|
||||||
<input id='cash-input' type='number' />
|
<input id='cash-input' type='number'
|
||||||
|
disabled={this.props.max < this.props.min}
|
||||||
|
onChange={this.handleInput}
|
||||||
|
value={this.state.cash} />
|
||||||
{'\u00A0'},000
|
{'\u00A0'},000
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class Button extends React.Component {
|
|||||||
<button className={'button ' + (this.props.size ? this.props.size : '') +
|
<button className={'button ' + (this.props.size ? this.props.size : '') +
|
||||||
' ' + (this.props.className ? this.props.className : '')}
|
' ' + (this.props.className ? this.props.className : '')}
|
||||||
type={this.props.type || 'button'}
|
type={this.props.type || 'button'}
|
||||||
|
disabled={this.props.disabled}
|
||||||
onClick={this.props.onClick} >
|
onClick={this.props.onClick} >
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -804,7 +804,10 @@
|
|||||||
(string->symbol (alist-ref 'crop otb)))
|
(string->symbol (alist-ref 'crop otb)))
|
||||||
(string->symbol (alist-ref 'crop otb))
|
(string->symbol (alist-ref 'crop otb))
|
||||||
(alist-ref 'amount otb)
|
(alist-ref 'amount otb)
|
||||||
(* (alist-ref 'cash msg) 1000)
|
(* (or (and (number? (alist-ref 'cash msg))
|
||||||
|
(alist-ref 'cash msg))
|
||||||
|
0)
|
||||||
|
1000)
|
||||||
player
|
player
|
||||||
game)
|
game)
|
||||||
(set! (player-otbs player)
|
(set! (player-otbs player)
|
||||||
@@ -1691,8 +1694,13 @@
|
|||||||
(thread-join! *server-thread*)))
|
(thread-join! *server-thread*)))
|
||||||
|
|
||||||
;; TODO
|
;; 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
|
;; make sure two players can't have the same name
|
||||||
;; bug: harvest action multiplayer doesn't flow right for other players
|
;; bug: harvest action multiplayer doesn't flow right for other players
|
||||||
;; info actions should look better
|
;; 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
|
||||||
|
|||||||
Reference in New Issue
Block a user