Browse Source

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

tags/v0.1.1
Fen Dweller 6 years ago
parent
commit
caaf2d7753
2 changed files with 14 additions and 7 deletions
  1. +10
    -3
      game.js
  2. +4
    -4
      stories/fen-snack.js

+ 10
- 3
game.js View File

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


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


if (val.type == "meter") { 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) { function startTimer(config, state) {
if (config.loop) { if (config.loop) {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
const result = config.func(state);
const result = config.func(state, config);
refresh(); refresh();


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


if (state.timers.some(x => x.timeout == timeout)){ if (state.timers.some(x => x.timeout == timeout)){
state.timers = state.timers.filter(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); startTimer(config, state);
}

} }


}, config.delay); }, config.delay);


+ 4
- 4
stories/fen-snack.js View File

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


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


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


if (location.startsWith("bowels")) { 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 false;
} }
return true;
return 1000 / bonus;
}, },
delay: 1000, delay: 1000,
loop: true, loop: true,


Loading…
Cancel
Save