Making another attempt at fixing movement bugs.

This commit is contained in:
2020-04-02 20:27:20 -07:00
parent 28d02a94f0
commit 9a9119cc18
4 changed files with 97 additions and 30 deletions

View File

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

View File

@@ -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());
}
});

View File

@@ -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: