rewrite the mod logic to including looping over the weather sets and overriding weather items
This commit is contained in:
parent
ebdf90a761
commit
778fceac26
35
src/mod.js
35
src/mod.js
@ -4,31 +4,40 @@ class ChooseTheWeather {
|
||||
constructor() {
|
||||
this.mod = "Revingly-BraceTheStorm";
|
||||
Logger.info(`Loading: ${this.mod}`);
|
||||
WeatherController.generateWeather = this.chooseWeather;
|
||||
WeatherController.generateWeather = this.chooseWeather.bind(this);
|
||||
}
|
||||
|
||||
chooseWeather(data) {
|
||||
// Get the config file for the weather
|
||||
const { weather, customSettings } = require('./config.json');
|
||||
const { weatherTypes, weather, loop, overrides} = require('./config.json');
|
||||
// Get the weather sets to choose from
|
||||
const weatherSets = require('./weatherSet.json');
|
||||
// Put the choosen weather from the config in a variable
|
||||
const choosenWeather = weatherSets[weather];
|
||||
let choosenWeather;
|
||||
|
||||
// If user choose custom then we loop over the customSettings
|
||||
// and add each property to the data.weather object
|
||||
if (weather === "custom") {
|
||||
Object.entries(customSettings).forEach(([key, value]) => {
|
||||
data.weather[key] = customSettings[key];
|
||||
});
|
||||
} else { // If user select one of the predefined weather sets then we just add it to the data.weather
|
||||
Object.entries(choosenWeather).forEach(([key, value]) => {
|
||||
data.weather[key] = value;
|
||||
});
|
||||
if (loop) {
|
||||
const randomIndex = Math.floor(Math.random() * weatherTypes.length);
|
||||
choosenWeather = weatherSets[weatherTypes[randomIndex]];
|
||||
} else {
|
||||
choosenWeather = weatherSets[weather];
|
||||
}
|
||||
|
||||
if (Object.keys(overrides).length > 0) { // check if overrides object has key/values to iterate through
|
||||
for (const weatherItem in overrides) {
|
||||
choosenWeather[weatherItem] = overrides[weatherItem];
|
||||
}
|
||||
}
|
||||
|
||||
this.createWeather(choosenWeather, data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
createWeather(choosenWeather, data) {
|
||||
Object.entries(choosenWeather).forEach(([key, value]) => {
|
||||
data.weather[key] = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.Mod = ChooseTheWeather;
|
Loading…
x
Reference in New Issue
Block a user