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() {
|
constructor() {
|
||||||
this.mod = "Revingly-BraceTheStorm";
|
this.mod = "Revingly-BraceTheStorm";
|
||||||
Logger.info(`Loading: ${this.mod}`);
|
Logger.info(`Loading: ${this.mod}`);
|
||||||
WeatherController.generateWeather = this.chooseWeather;
|
WeatherController.generateWeather = this.chooseWeather.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
chooseWeather(data) {
|
chooseWeather(data) {
|
||||||
// Get the config file for the weather
|
// 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
|
// Get the weather sets to choose from
|
||||||
const weatherSets = require('./weatherSet.json');
|
const weatherSets = require('./weatherSet.json');
|
||||||
// Put the choosen weather from the config in a variable
|
// 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
|
if (loop) {
|
||||||
// and add each property to the data.weather object
|
const randomIndex = Math.floor(Math.random() * weatherTypes.length);
|
||||||
if (weather === "custom") {
|
choosenWeather = weatherSets[weatherTypes[randomIndex]];
|
||||||
Object.entries(customSettings).forEach(([key, value]) => {
|
} else {
|
||||||
data.weather[key] = customSettings[key];
|
choosenWeather = weatherSets[weather];
|
||||||
});
|
|
||||||
} 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 (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;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createWeather(choosenWeather, data) {
|
||||||
|
Object.entries(choosenWeather).forEach(([key, value]) => {
|
||||||
|
data.weather[key] = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.Mod = ChooseTheWeather;
|
module.exports.Mod = ChooseTheWeather;
|
Loading…
x
Reference in New Issue
Block a user