diff --git a/src/components/farm/Board.jsx b/src/components/farm/Board.jsx index 0314939..feee7b1 100644 --- a/src/components/farm/Board.jsx +++ b/src/components/farm/Board.jsx @@ -1535,6 +1535,20 @@ class Action extends React.Component { ui={this.props.ui} />); buttons = (); break; + case 'resolve-move': + view = ( this.props.showNextAction()} + key={this.props.game.currentPlayer + '|' + this.props.ui.actionValue.from + '|' + this.props.ui.actionValue.to} + player={this.props.player} + game={this.props.game} + spaces={this.props.spaces} + movePlayer={this.props.movePlayer} + autoSkip={this.props.ui.autoSkip} + timerId={this.props.timerId} + setTimerId={this.props.setTimerId} + setMovingSkip={this.props.setMovingSkip} + ui={this.props.ui} />); + buttons = (); + break; case 'goto': view = ( this.props.showNextAction()} timerId={this.props.timerId} diff --git a/src/components/farm/interface.js b/src/components/farm/interface.js index 59fd45e..547d2fc 100644 --- a/src/components/farm/interface.js +++ b/src/components/farm/interface.js @@ -33,9 +33,8 @@ export { initialize, buy, roll, endTurn, loan, trade, submitTradeAccept, nextAction, buyUncleBert, actionsFinished, skip } let store; +let movingTimer = 0; -let spacesWithPlayers = []; -let loop = 0; function handleMessage(evt) { const data = JSON.parse(evt.data), type = data.event; @@ -69,7 +68,7 @@ function handleMessage(evt) { } store.dispatch(updatePlayer(data.player)); if (data.event === 'init') { - store.dispatch(movePlayer(data.player.space, 0, data.player.color)); + store.dispatch(movePlayer(data.player.space, -1, data.player.color)); store.dispatch(setHarvestTable(data.harvestTable)); } // new player(s) added to game, put them on the board @@ -78,7 +77,7 @@ function handleMessage(evt) { const newPlayers = data.game.otherPlayers.filter( x => !otherPlayers.find(y => y.player.name === x.player.name)); for (const p of newPlayers) { - store.dispatch(movePlayer(p.player.space, 0, p.player.color)); + store.dispatch(movePlayer(p.player.space, -1, p.player.color)); } } const oldMessages = store.getState().farm.game.messages.slice(0, 20); @@ -192,7 +191,7 @@ function initialize(st, sc) { rollMessage = '', rollTimer = false, movingAction = { from: 99, to: 99 }, - movingTimer = 0; + handledResolveMove = true; const unsubscribe = store.subscribe( () => { const state = store.getState(); @@ -271,6 +270,7 @@ function initialize(st, sc) { if ((state.farm.ui.action === 'move' || state.farm.ui.action === 'goto') && movingAction.from !== state.farm.ui.actionValue.from && movingAction.to !== state.farm.ui.actionValue.to) { + handledResolveMove = false; movingAction = state.farm.ui.actionValue; const movingProc = (player, from, to) => { let currentPos = from < 0 ? from + 49 : from; @@ -298,6 +298,7 @@ function initialize(st, sc) { } if (currentPos !== to) { + clearInterval(movingTimer); movingTimer = setInterval(tick, 500); } } @@ -305,12 +306,17 @@ function initialize(st, sc) { state.farm.player : state.farm.game.otherPlayers .find(p => p.player.name === state.farm.game.currentPlayer).player, movingAction.from, movingAction.to); - } else if (state.farm.ui.action !== 'move' && state.farm.ui.action !== 'goto') { - if (movingTimer) { - clearInterval(movingTimer); - movingTimer = 0; - movingAction = { from: 99, to: 99 }; - } + } else if (state.farm.ui.action === 'resolve-move' && !handledResolveMove) { + handledResolveMove = true; + clearInterval(movingTimer); + movingTimer = 0; + movingAction = { from: 99, to: 99 }; + store.dispatch(movePlayer(state.farm.ui.actionValue.to, + state.farm.ui.playerSpaces[state.farm.ui.actionValue.color], + state.farm.ui.actionValue.color)); + } + if (state.farm.ui.action === 'resolve-move' && state.farm.ui.nextAction !== 'resolve-move') { + store.dispatch(nextUIAction()); } }); diff --git a/src/components/farm/reducers.js b/src/components/farm/reducers.js index cfe7eae..2b44c7a 100644 --- a/src/components/farm/reducers.js +++ b/src/components/farm/reducers.js @@ -149,22 +149,26 @@ export default function(state = initialState, action) { case SET_CARD_ERROR: return { ...state, ui: { ...state.ui, cardError: action.error }}; case MOVE_PLAYER: - return { ...state, spaces: state.spaces - .map((item, index) => { - if (index === action.newSpace && - item.players.indexOf(action.player) === -1) { - return { ...item, players: [...item.players, action.player]}; - } else if (index === action.oldSpace) { - return { ...item, - players: item.players - .filter(x => x !== action.player) }; - } - return item; - }), - ui: { ...state.ui, - playerSpaces: { ...state.ui.playerSpaces, - [action.player]: action.newSpace }} - }; + if (action.oldSpace === action.newSpace) { + return state; + } else { + return { ...state, spaces: state.spaces + .map((item, index) => { + if (index === action.newSpace && + item.players.indexOf(action.player) === -1) { + return { ...item, players: [...item.players, action.player]}; + } else if (index === action.oldSpace) { + return { ...item, + players: item.players + .filter(x => x !== action.player) }; + } + return item; + }), + ui: { ...state.ui, + playerSpaces: { ...state.ui.playerSpaces, + [action.player]: action.newSpace }} + }; + } case SET_OLD_MESSAGES: return { ...state, oldMessages: action.messages }; case MESSAGE_PANEL_SPACE: diff --git a/src/server/farm.scm b/src/server/farm.scm index c52dce4..4365686 100644 --- a/src/server/farm.scm +++ b/src/server/farm.scm @@ -767,7 +767,10 @@ (to . ,(player-space player))))) (safe-set! (game-actions game) (append (game-actions game) - `(((?action . move) (?value . ,resp))) + `(((?action . move) (?value . ,resp)) + ((?action . resolve-move) + (?value . ((to . ,(player-space player)) + (color . ,(symbol->string (player-color player))))))) (sort-actions (get-actions player (player-space player))))) (message-players! game player `((action . "roll") @@ -813,6 +816,12 @@ `((action . "move") (value . ,value))) (create-ws-response player "action" `((action . "move") (value . ,value)))) + ((eq? name 'resolve-move) + (safe-set! (game-actions game) (cdr (game-actions game))) + (message-players! game player + `((action . "resolve-move") (value . ,value))) + (create-ws-response player "action" + `((action . "resolve-move") (value . ,value)))) ((eq? name 'harvest) (reconcile-display-cash player game) (let ((res (do-action action player))) @@ -902,8 +911,11 @@ (do-action action player) (safe-set! (player-harvest-mult player) 1) (safe-set! (game-actions game) - (append (sort-actions (get-actions player (player-space player))) - (cdr (game-actions game)))) + (append `(((?action . resolve-move) + (?value . ((to . ,(player-space player)) + (color . ,(symbol->string (player-color player))))))) + (sort-actions (get-actions player (player-space player))) + (cdr (game-actions game)))) (let ((resp `((from . ,(player-previous-space player)) (to . ,(player-space player))))) (message-players! game player `((action . "goto") @@ -1931,3 +1943,34 @@ ;; mark spaces ;; can't trade other player's ridge +;; don't let players join without name + +;; error: +;; Call history: + +;; farm.scm:714: mailbox#mailbox-send! +;; type-errors.scm:119: make-error-type-message +;; type-errors.scm:104: make-bad-argument-message +;; type-errors.scm:106: make-type-name-message +;; type-errors.scm:290: ->string +;; type-errors.scm:291: conc +;; type-errors.scm:103: string-append +;; type-errors.scm:119: signal-type-error +;; farm.scm:1125: k7172 +;; farm.scm:1125: g7176 +;; farm.scm:1127: with-output-to-string +;; farm.scm:1129: print-call-chain <-- + +;; Error: (mailbox-send!) bad argument type - not a mailbox: () + + +;; error: +;; Call history: + +;; farm.scm:129: alist-ref +;; farm.scm:1125: k7172 +;; farm.scm:1125: g7176 +;; farm.scm:1127: with-output-to-string +;; farm.scm:1129: print-call-chain <-- + +;; Error: (assv) bad argument type: ridge-cows