From 38c2920b8560457b95fbec24025ae9d30a465be2 Mon Sep 17 00:00:00 2001 From: Thomas Hintz Date: Mon, 6 Apr 2020 16:59:07 -0700 Subject: [PATCH] Fixing auto-skip in harvest and adding restart-game. --- src/components/farm/Board.jsx | 56 ++++++++++++++++++++--------------- src/server/farm.scm | 23 +++++++++----- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/components/farm/Board.jsx b/src/components/farm/Board.jsx index e29a537..f0c9e22 100644 --- a/src/components/farm/Board.jsx +++ b/src/components/farm/Board.jsx @@ -1111,38 +1111,46 @@ class Die extends React.Component { return roll; } - tick() { - this.acc += this.interval; - // update die face - if (this.ticks < this.maxTicks && this.acc >= this.trigger) { - this.ticks++; - this.acc = 0; - // update trigger for decay - if (this.props.decay) { - this.trigger = decay(this.props.ms, this.decayFactorPct, - this.maxTicks - this.ticks); - } - // we're finished, clear things, set final roll value - if (this.ticks >= this.maxTicks) { - clearInterval(this.timerId); - this.timerId = false; - this.setState({ num: this.props.num, finalFace: true }); - if (this.props.showScreen) { - this.showScreenTimerId = setInterval(() => { - this.props.showScreen(); - clearInterval(this.showScreenTimerId); - this.showScreenTimerId = false; - }, this.props.showScreenDelay); + tick = () => { + let finished = false; + return function() { + if (!finished) { + this.acc += this.interval; + // update die face + if (this.ticks < this.maxTicks && this.acc >= this.trigger) { + this.ticks++; + this.acc = 0; + // update trigger for decay + if (this.props.decay) { + this.trigger = decay(this.props.ms, this.decayFactorPct, + this.maxTicks - this.ticks); + } + // we're finished, clear things, set final roll value + if (this.ticks >= this.maxTicks) { + finished = true; + clearInterval(this.timerId); + this.timerId = false; + this.setState({ num: this.props.num, finalFace: true }); + if (this.props.showScreen) { + this.showScreenTimerId = setInterval(() => { + this.props.showScreen(); + clearInterval(this.showScreenTimerId); + this.showScreenTimerId = false; + }, this.props.showScreenDelay); + } + } else { + this.setState({ num: this.roll() }); + } } } else { - this.setState({ num: this.roll() }); + console.log('harvest die finished but still ticking'); } } } componentDidMount() { if (this.props.roll) { - this.timerId = setInterval(() => this.tick(), this.interval); + this.timerId = setInterval(this.tick().bind(this), this.interval); } } diff --git a/src/server/farm.scm b/src/server/farm.scm index a321f78..cd2ae2b 100644 --- a/src/server/farm.scm +++ b/src/server/farm.scm @@ -418,6 +418,17 @@ ;; (print ""))) ) +(define (restart-game game first-player) + (safe-set! (game-called-audit game) #f) + (safe-set! (game-state game) 'playing) + (for-each (lambda (p) + (safe-set! (player-finished p) #f) + (safe-set! (player-state p) 'turn-ended)) + (game-players game)) + (safe-set! (player-state first-player) 'pre-turn) + (safe-set! (game-current-player game) first-player) + (message-players! game #f '() type: "update")) + (define-method (player->list (p )) `((player . ((assets . ,(player-assets p)) (ridges . ,(player-ridges p)) @@ -1190,14 +1201,15 @@ (player (add-player-to-game game color (alist-ref 'playerName msg))) - (ai-player (add-ai-to-game game 'red "AI Player 1"))) + ;; (ai-player (add-ai-to-game game 'red "AI Player 1")) + ) (push! game (app-games *app*)) (session-set! (sid) 'player player) (session-set! (sid) 'game game) (*game* game) (set-startup-otbs game player 2) - (set-startup-otbs game ai-player 2) - (thread-start! (make-ai-push-receiver game ai-player)) + ;; (set-startup-otbs game ai-player 2) + ;; (thread-start! (make-ai-push-receiver game ai-player)) (create-start-response "new-game-started"))) ((string=? type "join-game") (let* ((name (alist-ref 'gameName msg)) @@ -2099,9 +2111,6 @@ ;; info actions should look better ;; you can get $50 from operating expense -;; auto-skip loop -;; harvester / tractor don't say total price - ;; mark spaces ;; error: @@ -2148,6 +2157,4 @@ ;; Error: (assv) bad argument type: #'> -;; auto-skip loop wtih harvest - ;; when getting trade the name is wrong