You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.1 KiB
31 lines
1.1 KiB
import {AppState} from "../state/AppState";
|
|
import {TILE_PAINT, TILE_REMOVE, TileAction} from "../../../common/src/actions/TileAction";
|
|
import {getCell} from "../../../common/src/state/HexMap";
|
|
import {CELL_COLOR, CELL_REMOVE} from "../../../common/src/actions/CellAction";
|
|
import {appStateReducer} from "./AppStateReducer";
|
|
|
|
export function tileReducer(oldState: AppState, action: TileAction): AppState {
|
|
if (oldState.localState === null) {
|
|
return oldState
|
|
}
|
|
const {map, user} = oldState.localState
|
|
switch (action.type) {
|
|
case TILE_PAINT:
|
|
if (getCell(map, action.at)?.color === user.activeColor) {
|
|
return oldState
|
|
}
|
|
return appStateReducer(oldState, {
|
|
type: CELL_COLOR,
|
|
at: action.at,
|
|
color: user.activeColor
|
|
})
|
|
case TILE_REMOVE:
|
|
if (getCell(map, action.at) === null) {
|
|
return oldState
|
|
}
|
|
return appStateReducer(oldState, {
|
|
type: CELL_REMOVE,
|
|
at: action.at
|
|
})
|
|
}
|
|
} |