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 }) } }