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.
30 lines
822 B
30 lines
822 B
const Immutable = require('immutable');
|
|
|
|
import * as GridActions from '../../actions/board/grid.actions';
|
|
import { SETTINGS } from '../../App';
|
|
import Values from '../Values';
|
|
|
|
const reducer = (state = [], action) => {
|
|
if (action.type !== GridActions.GRID_ACTION) {
|
|
return state;
|
|
}
|
|
|
|
switch (action.action) {
|
|
case GridActions.GENERATE:
|
|
return Values.generate(action.count, action.level);
|
|
|
|
case GridActions.UPDATE:
|
|
const results = Immutable.List(state);
|
|
const index = action.y * SETTINGS.GRID_HEIGHT + action.x;
|
|
const valid = Values.validate(state[index], action.level);
|
|
|
|
if (valid) {
|
|
return results.set(index, '').toArray();
|
|
}
|
|
break;
|
|
}
|
|
|
|
return state;
|
|
};
|
|
|
|
export default reducer;
|
|
|