From de272b1b98c79c23cf62cfd1f650d9067d9a3aad Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 17 Dec 2019 10:26:17 -0500 Subject: [PATCH] Set up conditional news items --- constants.js | 27 +++++++++++++++++++++++++++ gorge.js | 21 ++++++++++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/constants.js b/constants.js index 0392522..f0f682e 100644 --- a/constants.js +++ b/constants.js @@ -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!" + ] + } +] \ No newline at end of file diff --git a/gorge.js b/gorge.js index 7ce8583..266d20d 100644 --- a/gorge.js +++ b/gorge.js @@ -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();