Переглянути джерело

Timers can change their delay. They also get their own config.

tags/v0.1.1
Fen Dweller 6 роки тому
джерело
коміт
caaf2d7753
2 змінених файлів з 14 додано та 7 видалено
  1. +10
    -3
      game.js
  2. +4
    -4
      stories/fen-snack.js

+ 10
- 3
game.js Переглянути файл

@@ -13,7 +13,7 @@ function initGamePostSetup(state) {
const holder = document.querySelector("#player-info");

holder.innerHTML = "";
Object.entries(state.player.stats).forEach(([key, val]) => {

if (val.type == "meter") {
@@ -88,7 +88,7 @@ Returns the timeout id - but you still need to cancel it through stopTimer!
function startTimer(config, state) {
if (config.loop) {
const timeout = setTimeout(() => {
const result = config.func(state);
const result = config.func(state, config);
refresh();

// the timer may have terminated itself!
@@ -96,8 +96,15 @@ function startTimer(config, state) {

if (state.timers.some(x => x.timeout == timeout)){
state.timers = state.timers.filter(x => x.timeout != timeout);
if (result)
if (typeof(result) === "number") {
config.delay = result;
}

// you shouldn't use a delay of 0 anyway
if (result) {
startTimer(config, state);
}

}

}, config.delay);


+ 4
- 4
stories/fen-snack.js Переглянути файл

@@ -40,15 +40,15 @@ stories.push({
let bonus = state.player.flags.submission ? 10 : 1;

if (location.startsWith("stomach")) {
state.player.stats.health.value -= 1 * bonus;
state.player.stats.health.value -= 1;
}

if (location.startsWith("intestines")) {
state.player.stats.health.value -= 0.75 * bonus;
state.player.stats.health.value -= 0.75;
}

if (location.startsWith("bowels")) {
state.player.stats.health.value -= 0.5 * bonus;
state.player.stats.health.value -= 0.5;
}


@@ -69,7 +69,7 @@ stories.push({

return false;
}
return true;
return 1000 / bonus;
},
delay: 1000,
loop: true,


Завантаження…
Відмінити
Зберегти