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.
61 lines
1.8 KiB
61 lines
1.8 KiB
import { MODE, VALUES, BLINK, MUNCHER } from './Constants.js';
|
|
|
|
import { Values } from '../board/Values';
|
|
import { GRID } from './Settings';
|
|
|
|
export const modeReducer = (state = MODE.WELCOME, action) => {
|
|
if (action.type === MODE.NEXT) {
|
|
switch (state) {
|
|
case MODE.BOARD:
|
|
return MODE.WELCOME;
|
|
case MODE.WELCOME:
|
|
return MODE.BOARD;
|
|
};
|
|
}
|
|
|
|
return MODE.BOARD;
|
|
};
|
|
|
|
export const blinkReducer = (state = false, action) => {
|
|
if (action.type === BLINK.TOGGLE) {
|
|
return (state ? false : true);
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
export const valuesReducer = (state = [], action) => {
|
|
if (action.type === VALUES.FOO) {
|
|
switch (action.action) {
|
|
case VALUES.GENERATE:
|
|
return Values.generate(action.count, action.level);
|
|
case VALUES.UPDATE:
|
|
const valid = Values.validate(state[action.index], action.level);
|
|
const results = state.slice(0);
|
|
if (valid) {
|
|
results[action.index] = "";
|
|
}
|
|
return results;
|
|
}
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
const muncherInitialState = { x: 0, y: 0 };
|
|
export const muncherReducer = (state = muncherInitialState, action) => {
|
|
if (action.type === MUNCHER.MOVE) {
|
|
switch (action.direction) {
|
|
case MUNCHER.LEFT:
|
|
return (state.x > 0 ? { x: state.x - 1, y: state.y } : state);
|
|
case MUNCHER.RIGHT:
|
|
return (state.x < GRID.W - 1 ? { x: state.x + 1, y: state.y } : state);
|
|
case MUNCHER.UP:
|
|
return (state.y > 0 ? { x: state.x, y: state.y - 1 } : state);
|
|
case MUNCHER.DOWN:
|
|
return (state.y < GRID.H - 1 ? { x: state.x, y: state.y + 1 } : state);
|
|
};
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|