WebHost: Clean up the exported yaml in weighted settings (#2167)
* Trim output yaml in weighted options Remove options that have only one possible outcome as well as empty arrays, when building yaml. * fix quotes
This commit is contained in:
parent
57c13ff273
commit
1756a30acc
|
@ -1134,8 +1134,8 @@ const validateSettings = () => {
|
|||
return;
|
||||
}
|
||||
|
||||
// Remove any disabled options
|
||||
Object.keys(settings[game]).forEach((setting) => {
|
||||
// Remove any disabled options
|
||||
Object.keys(settings[game][setting]).forEach((option) => {
|
||||
if (settings[game][setting][option] === 0) {
|
||||
delete settings[game][setting][option];
|
||||
|
@ -1149,6 +1149,32 @@ const validateSettings = () => {
|
|||
) {
|
||||
errorMessage = `${game} // ${setting} has no values above zero!`;
|
||||
}
|
||||
|
||||
// Remove weights from options with only one possibility
|
||||
if (
|
||||
Object.keys(settings[game][setting]).length === 1 &&
|
||||
!Array.isArray(settings[game][setting]) &&
|
||||
setting !== 'start_inventory'
|
||||
) {
|
||||
settings[game][setting] = Object.keys(settings[game][setting])[0];
|
||||
}
|
||||
|
||||
// Remove empty arrays
|
||||
else if (
|
||||
['exclude_locations', 'priority_locations', 'local_items',
|
||||
'non_local_items', 'start_hints', 'start_location_hints'].includes(setting) &&
|
||||
settings[game][setting].length === 0
|
||||
) {
|
||||
delete settings[game][setting];
|
||||
}
|
||||
|
||||
// Remove empty start inventory
|
||||
else if (
|
||||
setting === 'start_inventory' &&
|
||||
Object.keys(settings[game]['start_inventory']).length === 0
|
||||
) {
|
||||
delete settings[game]['start_inventory'];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1156,6 +1182,11 @@ const validateSettings = () => {
|
|||
errorMessage = 'You have not chosen a game to play!';
|
||||
}
|
||||
|
||||
// Remove weights if there is only one game
|
||||
else if (Object.keys(settings.game).length === 1) {
|
||||
settings.game = Object.keys(settings.game)[0];
|
||||
}
|
||||
|
||||
// If an error occurred, alert the user and do not export the file
|
||||
if (errorMessage) {
|
||||
userMessage.innerText = errorMessage;
|
||||
|
|
Loading…
Reference in New Issue