Making another attempt at fixing movement bugs.

logins
Thomas Hintz 5 years ago
parent 28d02a94f0
commit 9a9119cc18

@ -1535,6 +1535,20 @@ class Action extends React.Component {
ui={this.props.ui} />); ui={this.props.ui} />);
buttons = (<Fragment />); buttons = (<Fragment />);
break; break;
case 'resolve-move':
view = (<Moving showNextAction={() => 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 = (<Fragment />);
break;
case 'goto': case 'goto':
view = (<Moving showNextAction={() => this.props.showNextAction()} view = (<Moving showNextAction={() => this.props.showNextAction()}
timerId={this.props.timerId} timerId={this.props.timerId}

@ -33,9 +33,8 @@ export { initialize, buy, roll, endTurn, loan, trade, submitTradeAccept,
nextAction, buyUncleBert, actionsFinished, skip } nextAction, buyUncleBert, actionsFinished, skip }
let store; let store;
let movingTimer = 0;
let spacesWithPlayers = [];
let loop = 0;
function handleMessage(evt) { function handleMessage(evt) {
const data = JSON.parse(evt.data), const data = JSON.parse(evt.data),
type = data.event; type = data.event;
@ -69,7 +68,7 @@ function handleMessage(evt) {
} }
store.dispatch(updatePlayer(data.player)); store.dispatch(updatePlayer(data.player));
if (data.event === 'init') { 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)); store.dispatch(setHarvestTable(data.harvestTable));
} }
// new player(s) added to game, put them on the board // new player(s) added to game, put them on the board
@ -78,7 +77,7 @@ function handleMessage(evt) {
const newPlayers = data.game.otherPlayers.filter( const newPlayers = data.game.otherPlayers.filter(
x => !otherPlayers.find(y => y.player.name === x.player.name)); x => !otherPlayers.find(y => y.player.name === x.player.name));
for (const p of newPlayers) { 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); const oldMessages = store.getState().farm.game.messages.slice(0, 20);
@ -192,7 +191,7 @@ function initialize(st, sc) {
rollMessage = '', rollMessage = '',
rollTimer = false, rollTimer = false,
movingAction = { from: 99, to: 99 }, movingAction = { from: 99, to: 99 },
movingTimer = 0; handledResolveMove = true;
const unsubscribe = store.subscribe( const unsubscribe = store.subscribe(
() => { () => {
const state = store.getState(); const state = store.getState();
@ -271,6 +270,7 @@ function initialize(st, sc) {
if ((state.farm.ui.action === 'move' || state.farm.ui.action === 'goto') && if ((state.farm.ui.action === 'move' || state.farm.ui.action === 'goto') &&
movingAction.from !== state.farm.ui.actionValue.from && movingAction.from !== state.farm.ui.actionValue.from &&
movingAction.to !== state.farm.ui.actionValue.to) { movingAction.to !== state.farm.ui.actionValue.to) {
handledResolveMove = false;
movingAction = state.farm.ui.actionValue; movingAction = state.farm.ui.actionValue;
const movingProc = (player, from, to) => { const movingProc = (player, from, to) => {
let currentPos = from < 0 ? from + 49 : from; let currentPos = from < 0 ? from + 49 : from;
@ -298,6 +298,7 @@ function initialize(st, sc) {
} }
if (currentPos !== to) { if (currentPos !== to) {
clearInterval(movingTimer);
movingTimer = setInterval(tick, 500); movingTimer = setInterval(tick, 500);
} }
} }
@ -305,12 +306,17 @@ function initialize(st, sc) {
state.farm.player : state.farm.game.otherPlayers state.farm.player : state.farm.game.otherPlayers
.find(p => p.player.name === state.farm.game.currentPlayer).player, .find(p => p.player.name === state.farm.game.currentPlayer).player,
movingAction.from, movingAction.to); movingAction.from, movingAction.to);
} else if (state.farm.ui.action !== 'move' && state.farm.ui.action !== 'goto') { } else if (state.farm.ui.action === 'resolve-move' && !handledResolveMove) {
if (movingTimer) { handledResolveMove = true;
clearInterval(movingTimer); clearInterval(movingTimer);
movingTimer = 0; movingTimer = 0;
movingAction = { from: 99, to: 99 }; 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());
} }
}); });

@ -149,6 +149,9 @@ export default function(state = initialState, action) {
case SET_CARD_ERROR: case SET_CARD_ERROR:
return { ...state, ui: { ...state.ui, cardError: action.error }}; return { ...state, ui: { ...state.ui, cardError: action.error }};
case MOVE_PLAYER: case MOVE_PLAYER:
if (action.oldSpace === action.newSpace) {
return state;
} else {
return { ...state, spaces: state.spaces return { ...state, spaces: state.spaces
.map((item, index) => { .map((item, index) => {
if (index === action.newSpace && if (index === action.newSpace &&
@ -165,6 +168,7 @@ export default function(state = initialState, action) {
playerSpaces: { ...state.ui.playerSpaces, playerSpaces: { ...state.ui.playerSpaces,
[action.player]: action.newSpace }} [action.player]: action.newSpace }}
}; };
}
case SET_OLD_MESSAGES: case SET_OLD_MESSAGES:
return { ...state, oldMessages: action.messages }; return { ...state, oldMessages: action.messages };
case MESSAGE_PANEL_SPACE: case MESSAGE_PANEL_SPACE:

@ -767,7 +767,10 @@
(to . ,(player-space player))))) (to . ,(player-space player)))))
(safe-set! (game-actions game) (safe-set! (game-actions game)
(append (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))))) (sort-actions (get-actions player (player-space player)))))
(message-players! game player (message-players! game player
`((action . "roll") `((action . "roll")
@ -813,6 +816,12 @@
`((action . "move") (value . ,value))) `((action . "move") (value . ,value)))
(create-ws-response player "action" (create-ws-response player "action"
`((action . "move") (value . ,value)))) `((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) ((eq? name 'harvest)
(reconcile-display-cash player game) (reconcile-display-cash player game)
(let ((res (do-action action player))) (let ((res (do-action action player)))
@ -902,7 +911,10 @@
(do-action action player) (do-action action player)
(safe-set! (player-harvest-mult player) 1) (safe-set! (player-harvest-mult player) 1)
(safe-set! (game-actions game) (safe-set! (game-actions game)
(append (sort-actions (get-actions player (player-space player))) (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)))) (cdr (game-actions game))))
(let ((resp `((from . ,(player-previous-space player)) (let ((resp `((from . ,(player-previous-space player))
(to . ,(player-space player))))) (to . ,(player-space player)))))
@ -1931,3 +1943,34 @@
;; mark spaces ;; mark spaces
;; can't trade other player's ridge ;; 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

Loading…
Cancel
Save