1 Commits

Author SHA1 Message Date
29e4955de5 wip 2020-04-22 20:14:18 -07:00
5 changed files with 30 additions and 5 deletions

View File

@@ -40,3 +40,4 @@ export const MESSAGE = 'message'
export const SET_HARVEST_TABLE = 'set-harvest-table'
export const SET_MOVING_SKIP = 'set-moving-skip'
export const SERVER_ERROR = 'server-error'
export const REMOVE_PLAYER = 'remove-player'

View File

@@ -21,14 +21,14 @@ import { UPDATE_GAME, UPDATE_PLAYER, GAME_STATE, SET_SELECTED_CARD, SET_CARDS,
MP_MOUSE, SET_MP_DIMS, MARK_ACTION_CHANGE_HANDLED, SET_NEXT_ACTION,
MOVE_PLAYER, NEXT_UI_ACTION, NEXT_UI_ACTION_SILENT, ALERT, ALERT_HANDLED,
AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE, SET_CARD_ERROR,
SET_MOVING_SKIP, SERVER_ERROR } from './actionTypes.js'
SET_MOVING_SKIP, SERVER_ERROR, REMOVE_PLAYER } from './actionTypes.js'
export { updateGame, updatePlayer, gameState, setSelectedCard, setCards,
spacePushPlayer, spaceClearPlayers, setOldMessages, setMessagePanelSpace,
mpMouse, setMPDims, movePlayer, setNextAction, nextUIAction,
markActionChangeHandled, nextUIActionSilent, alert, alertHandled,
autoSkip, message, setHarvestTable, setCardError, setMovingSkip,
serverError }
serverError, removePlayer }
function updateGame(update) {
return { type: UPDATE_GAME,
@@ -96,6 +96,11 @@ function movePlayer(newSpace, oldSpace, player) {
newSpace, oldSpace, player };
}
function removePlayer(color) {
return { type: REMOVE_PLAYER,
color };
}
function nextUIAction() {
return { type: NEXT_UI_ACTION };
}

View File

@@ -25,7 +25,7 @@ import { updateGame, updatePlayer, gameState, setSelectedCard, setCards,
movePlayer, setOldMessages, markActionChangeHandled,
mpMouse, rolled, setNextAction, nextUIAction, nextUIActionSilent, alert,
autoSkip, message, alertHandled, setHarvestTable,
setCardError, setMovingSkip, serverError } from './actions.js'
setCardError, setMovingSkip, serverError, removePlayer } from './actions.js'
import { itemCard, fateCard } from 'game.js'
export { initialize, buy, roll, endTurn, loan, trade, submitTradeAccept,
@@ -49,6 +49,9 @@ function handleMessage(evt) {
if (data.event === 'left-game') {
window.location.href = window.location.pathname;
}
if (data.event === 'player-left-game') {
store.dispatch(removePlayer(data.color));
}
if (data.game.state === GAME_STATES.preGame) {
store.dispatch(alert(ALERTS.preGame, '', 'pre-game'));
}

View File

@@ -22,7 +22,7 @@ import { UPDATE_GAME, UPDATE_PLAYER, GAME_STATE, SET_SELECTED_CARD, SET_CARDS,
SET_MP_DIMS, MOVE_PLAYER, SET_NEXT_ACTION, NEXT_UI_ACTION,
MARK_ACTION_CHANGE_HANDLED, NEXT_UI_ACTION_SILENT, ALERT, ALERT_HANDLED,
AUTO_SKIP, MESSAGE, SET_HARVEST_TABLE, SET_CARD_ERROR,
SET_MOVING_SKIP, SERVER_ERROR } from './actionTypes.js'
SET_MOVING_SKIP, SERVER_ERROR, REMOVE_PLAYER } from './actionTypes.js'
import { GAME_STATES } from '../../constants.js'
import { spaceContent, corners } from 'game.js'
@@ -176,6 +176,21 @@ export default function(state = initialState, action) {
[action.player]: action.newSpace }}
};
}
case REMOVE_PLAYER:
const playerSpace = state.ui.playerSpaces[action.color];
return { ...state,
spaces: state.spaces.map((item, index) => {
if (index === playerSpace) {
return { ...item,
players: item.players
.filter(x => x !== action.color) };
}
return item;
}),
ui: { ...state.ui,
playerSpaces: { ...state.ui.playerSpaces,
[action.player]: -1 }}
};
case SET_OLD_MESSAGES:
return { ...state, oldMessages: action.messages };
case MESSAGE_PANEL_SPACE:

View File

@@ -1466,7 +1466,8 @@
(when (not (null? (game-players (*game*))))
(safe-set! (game-current-player (*game*)) (car (game-players (*game*)))))
(db-remove-user-game (player-user-id (*player*)) (game-id (*game*)))
(message-players! (*game*) (*player*) '() type: "left-game")
(message-players! (*game*) (*player*) `((color . ,(symbol->string (player-color (*player*)))))
type: "player-left-game")
(create-ws-response (*player*) "left-game" '()))
((string=? type "start-game")
(safe-set! (game-state (*game*)) 'pre-turn)