Здравствуйте, посмотрев все подобные посты, проблему не смог решить
ОШИБКА: 5. setInterval нужно вызывать из startMiningGame и запускать handleStateChange каждую секунду
**handlers.js **
import { updateGold } from "./functions.js";
export const handleKeyPress = (term, state) => {
return function (name, matche, data) {
if (data.code == 103 || data.code === 71) {
state.gold++;
}
const producers = state.producers; // берем список producers из масива config
let key = parseInt(String.fromCharCode(data.code));
let producer = null;
const getProducerById = producers.reduce((obj, item) => {
if (item.id === key) {
producer = item;
}
}, 1);
if (producer) {
state.gold = state.gold - producer.cost;
producer.cost = producer.cost * producer.growthRate;
producer.count = producer.count + 1;
state.productionRate += producer.baseProduction;
}
};
};
export const handleStateChange = (term, state) => {
return function () {
updateGold(term, state);
};
};
gameEngine.js
import { init } from "./functions.js";
import { handleKeyPress, handleStateChange } from "./handlers.js";
export const startMiningGame = (term, state) => {
init(term());
const handler = handleKeyPress(term, state)
term.on('key', handler);
setInterval(handleStateChange(term, state), 1000);
}