| @@ -1002,3 +1002,30 @@ const clickVictimUpgradeText = { | |||||
| "desc": "Gorge on the multiverse" | "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!" | |||||
| ] | |||||
| } | |||||
| ] | |||||
| @@ -647,15 +647,22 @@ function clickPopup(text, type, location) { | |||||
| } | } | ||||
| function doNews() { | 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(() => { | setTimeout(() => { | ||||
| doNews(); | doNews(); | ||||