handler.js
import { updateGold } from "./functions.js";
export const handleKeyPress = (term, state) => {
return function (name, matches, data) {
if (
String.fromCharCode(data.code) === "g" ||
String.fromCharCode(data.code) === "G"
) {
state.gold = state.gold + 1;
}
for (let i = 0; i < state.producers.length; i++) {
if (String.fromCharCode(data.code) === `${state.producers[i].id}`) {
state.gold = state.gold - state.producers[i].cost;
state.producers[i].cost =
state.producers[i].cost * state.producers[i].growthRate;
state.producers[i].count = state.producers[i].count + 1;
state.productionRate += state.producers[i].baseProduction;
}
}
};
};
export const handleStateChange = (term, state) => {
return function () {
updateGold(term, state);
};
};