Selaa lähdekoodia

Set up conditional news items

tags/v0.0.4
Fen Dweller 5 vuotta sitten
vanhempi
commit
de272b1b98
2 muutettua tiedostoa jossa 41 lisäystä ja 7 poistoa
  1. +27
    -0
      constants.js
  2. +14
    -7
      gorge.js

+ 27
- 0
constants.js Näytä tiedosto

@@ -1002,3 +1002,30 @@ const clickVictimUpgradeText = {
"desc": "Gorge on the multiverse"
}
};

// to avoid yoinking stuff from global variables directly...

// state.ownedUpgrades == ownedUpgrades
// state.resources == resources
// state.currentProductivity == currentProductivity

const news = [
{
condition: state => {
return true;
},
lines: [
state => "This is news.",
state => "This is also news.",
state => "SPORTS!"
]
},
{
condition: state => {
return state.resources.food > 100;
},
lines: [
state => "You have at least 100 food. Wow!"
]
}
]

+ 14
- 7
gorge.js Näytä tiedosto

@@ -647,15 +647,22 @@ function clickPopup(text, type, location) {
}

function doNews() {
let news = [
"This is news",
"This is also news",
"SPORTS!"
];
const state = {
ownedUpgrades: ownedUpgrades,
resources: resources,
currentProductivity: currentProductivity
};

let options = [];
news.forEach(entry => {
if (entry.condition(state)) {
options = options.concat(entry.lines);
}
});

const choice = Math.floor(Math.random() * news.length);
const choice = Math.floor(Math.random() * options.length);

showNews(news[choice]);
showNews(options[choice](state));

setTimeout(() => {
doNews();


Loading…
Peruuta
Tallenna