handler.js
import { updateGold } from "./functions.js";
import { checkInitCompleted } from "./functions.js";
import { updateProducerList } from "./functions.js";
export const handleKeyPress = (term, state) => {
return function (name, matches, data) {
let key = String.fromCharCode(data.code);
if (key === 'g' || key === 'G') {
state.gold ++;
} else {
for (let i = 0; i > state.producers.length; i++) {
if (key === String(state.producers[i].id)) {
state.gold -= state.producers[i].cost;
state.producers[i].cost *= state.producers[i].growthRate;
state.producers[i].count++;
const productionRate = (state.producers[i].baseProduction / 1000) * state.tickSpeed;
state.productionRate += productionRate;
term.moveTo(25, 3);
}
}
}
if (!state.isInitCompleted) {
for (let i = 0; i < state.producers.length; i++) {
if (state.gold >= state.producers[i].cost) {
state.isInitCompleted = true;
checkInitCompleted(term, state);
}
}
}
if (state.isProducerListUpdated == false){
updateProducerList(term, state)
}
//if (!state.isInitCompleted && state.gold >= 10) {
//checkInitCompleted(term, state)
//}
}
};
error: checkInitCompleted должна изменить значение isProducerListUpdated на false