|
|
@@ -48,6 +48,8 @@ let newsRemoveTimer; |
|
|
|
|
|
|
|
|
const newsDelay = 8000; |
|
|
const newsDelay = 8000; |
|
|
|
|
|
|
|
|
|
|
|
const newsWeightFactors = []; |
|
|
|
|
|
|
|
|
let buttonClicked = false; |
|
|
let buttonClicked = false; |
|
|
|
|
|
|
|
|
const state = { |
|
|
const state = { |
|
|
@@ -531,6 +533,7 @@ function setup() { |
|
|
// prepare dynamic stuff |
|
|
// prepare dynamic stuff |
|
|
|
|
|
|
|
|
initializeData(); |
|
|
initializeData(); |
|
|
|
|
|
initializeNews(); |
|
|
createButtons(); |
|
|
createButtons(); |
|
|
createDisplays(); |
|
|
createDisplays(); |
|
|
registerListeners(); |
|
|
registerListeners(); |
|
|
@@ -541,6 +544,12 @@ function setup() { |
|
|
updateAll(); |
|
|
updateAll(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function initializeNews() { |
|
|
|
|
|
news.forEach(entry => { |
|
|
|
|
|
newsWeightFactors.push(0); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const cache = {}; |
|
|
const cache = {}; |
|
|
|
|
|
|
|
|
function initializeCaches() { |
|
|
function initializeCaches() { |
|
|
@@ -1116,16 +1125,28 @@ function clickPopup(text, type, location) { |
|
|
|
|
|
|
|
|
function doNews() { |
|
|
function doNews() { |
|
|
let options = []; |
|
|
let options = []; |
|
|
|
|
|
let weights = []; |
|
|
|
|
|
let indices = []; |
|
|
|
|
|
let index = 0; |
|
|
news.forEach(entry => { |
|
|
news.forEach(entry => { |
|
|
if (entry.condition(state)) { |
|
|
|
|
|
|
|
|
if (entry.condition(state) && newsWeightFactors[index] != 1) { |
|
|
options = options.concat(entry.lines); |
|
|
options = options.concat(entry.lines); |
|
|
|
|
|
weights.push(1 - newsWeightFactors[index]) |
|
|
|
|
|
indices.push(index); |
|
|
} |
|
|
} |
|
|
|
|
|
index += 1; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const choice = Math.floor(Math.random() * options.length); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const choice = weightedSelect(weights); |
|
|
|
|
|
|
|
|
showNews(options[choice](state)); |
|
|
showNews(options[choice](state)); |
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < newsWeightFactors.length; i++) { |
|
|
|
|
|
newsWeightFactors[i] *= 0.9; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
newsWeightFactors[indices[choice]] = 1; |
|
|
|
|
|
|
|
|
newsShowTimer = setTimeout(() => { |
|
|
newsShowTimer = setTimeout(() => { |
|
|
doNews(); |
|
|
doNews(); |
|
|
}, 8000); |
|
|
}, 8000); |
|
|
|