import { tick } from "https://esm.town/v/beneskildsen/tick";
import { initBonsaiState } from "https://esm.town/v/beneskildsen/initBonsaiState";
export const bonsaiReducer = (state, action) => {
if (state === undefined) return initBonsaiState();
switch (action.type) {
case "TICK": {
return tick(state);
}
case "SNIP": {
const { pos, clientID, grammar } = action;
if (clientID != 1 && state.snips[clientID]) {
return state;
}
state.snips[clientID] = true;
return { ...state, grammar };
}
case "CLEAR_SNIPS": {
return { ...state, snips: {} };
}
}
return state;
};