summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hintz <t@thintz.com>2020-04-30 21:57:00 -0700
committerThomas Hintz <t@thintz.com>2020-04-30 21:57:00 -0700
commit56097208769be1fd382527780a50d3b3fd9a78cd (patch)
tree25e9ba8b85d54aaa0baed763775f4388d1a090f3
parentcb983ae1c98868f38376d9534c00994aceac4ac2 (diff)
downloadfarm-56097208769be1fd382527780a50d3b3fd9a78cd.tar.gz
Improving test routine.HEADmaster
-rw-r--r--src/components/farm/Board.jsx65
1 files changed, 55 insertions, 10 deletions
diff --git a/src/components/farm/Board.jsx b/src/components/farm/Board.jsx
index 156be60..ee4865a 100644
--- a/src/components/farm/Board.jsx
+++ b/src/components/farm/Board.jsx
@@ -51,14 +51,20 @@ import { buy, roll, endTurn, loan, trade, submitTradeAccept,
leaveGame, kickPlayer, toggleRevealForTrade,
addAIPlayer } from './interface.js'
-const showScreenDelay = 0;
+let showScreenDelay = 2000;
function test() {
+ showScreenDelay = 0;
if (!document.querySelector('.show-for-large .action-item')) {
- setTimeout(test, 500);
+ setTimeout(test, 0);
} else {
- document.querySelector('.show-for-large .action-item').click();
- setTimeout(test, 100);
+ if (document.querySelector('.show-for-large .action-item')) {
+ document.querySelector('.show-for-large .action-item').click();
+ }
+ if (document.querySelector('.show-for-large .action-item2')) {
+ document.querySelector('.show-for-large .action-item2').click();
+ }
+ setTimeout(test, 0);
}
}
@@ -247,11 +253,27 @@ class PlayerSummary extends React.Component {
}
class PlayerTurnContainer extends React.Component {
+ state = {
+ endedTurn: false
+ }
+
clickRoll = () => {
roll();
this.props.showScreen(SCREENS.action);
}
+ clickEndTurn = () => {
+ this.setState({ endedTurn: true });
+ }
+
+ componentDidUpdate(prevProps, prevState) {
+ if (this.state.endedTurn && !prevState.endedTurn) {
+ endTurn();
+ } else if (this.props.player.state === 'pre-turn' && prevProps.player.state !== 'pre-turn') {
+ this.setState({ endedTurn: false });
+ }
+ }
+
render() {
let view;
const { player, ui } = this.props,
@@ -283,10 +305,16 @@ class PlayerTurnContainer extends React.Component {
Raise Cash
</Button>
);
+ } else if (this.state.endedTurn) {
+ view = (
+ <Button disabled={true}>
+ Loading...
+ </Button>
+ );
} else {
view = (
<Fragment>
- <Button className="action-item" onClick={endTurn}>
+ <Button className="action-item" onClick={this.clickEndTurn}>
End Turn
</Button>{' '}{auditButton}
</Fragment>);
@@ -1552,7 +1580,8 @@ class Moving extends React.Component {
class Action extends React.Component {
state = {
- bertChoice: 'nothing'
+ bertChoice: 'nothing',
+ aiPlayerTurnEnded: false
}
setBertChoice = (e) => {
@@ -1569,6 +1598,18 @@ class Action extends React.Component {
}
}
+ endAiTurn = () => {
+ this.setState({ aiPlayerTurnEnded: true });
+ }
+
+ componentDidUpdate(prevProps, prevState) {
+ if (this.state.aiPlayerTurnEnded && !prevState.aiPlayerTurnEnded) {
+ endAiTurn();
+ } else if (this.props.game.currentPlayer !== prevProps.game.currentPlayer) {
+ this.setState({ aiPlayerTurnEnded: false });
+ }
+ }
+
render() {
let view,
buttons = false;
@@ -1622,14 +1663,18 @@ class Action extends React.Component {
) : (<></>)}
<form onSubmit={this.bertSubmit}>
<label>
- <input type="radio" name="bert" value="accept" onClick={this.setBertChoice} />
+ <input type="radio" name="bert" value="accept" onClick={this.setBertChoice} className="action-item" />
Yes, take over for $10,000!
</label>
<label>
<input type="radio" name="bert" value="deny" onClick={this.setBertChoice} />
No, continue on
</label>
- <Button type="submit" disabled={this.state.bertChoice === 'nothing' || this.state.bertChoice === 'accept' && cash < 10000}>Submit</Button>
+ <Button type="submit" disabled={this.state.bertChoice === 'nothing' || this.state.bertChoice === 'accept' && cash < 10000}
+ className="action-item2"
+ >
+ Submit
+ </Button>
</form>
</>
);
@@ -1777,9 +1822,9 @@ class Action extends React.Component {
screen={this.props.screen}
showScreen={this.props.showScreen}
game={this.props.game} />);
- } else if (currentPlayer.ai) {
+ } else if (currentPlayer.ai && !this.state.aiPlayerTurnEnded) {
view = (
- <Button className="action-item" onClick={endAiTurn}>
+ <Button className="action-item" onClick={this.endAiTurn}>
Next Player's Turn
</Button>
);