diff --git a/app/assets/js/processbuilder.js b/app/assets/js/processbuilder.js index e328829..db07184 100644 --- a/app/assets/js/processbuilder.js +++ b/app/assets/js/processbuilder.js @@ -96,7 +96,7 @@ class ProcessBuilder { * @returns {boolean} True if the mod is enabled, false otherwise. */ static isModEnabled(modCfg, required = null){ - return modCfg != null ? ((typeof modCfg === 'boolean' && modCfg) || (typeof modCfg === 'object' && modCfg.value)) : required != null ? required.isDefault() : true + return modCfg != null ? ((typeof modCfg === 'boolean' && modCfg) || (typeof modCfg === 'object' && (typeof modCfg.value !== 'undefined' ? modCfg.value : true))) : required != null ? required.isDefault() : true } /** diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index 270afd3..e08bfd3 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -465,7 +465,7 @@ function parseModulesForUI(mdls, submodules = false, servConf){ ${mdl.hasSubModules() ? `
- ${Object.values(parseModulesForUI(mdl.getSubModules(), true)).join('')} + ${Object.values(parseModulesForUI(mdl.getSubModules(), true, servConf[mdl.getVersionlessID()])).join('')}
` : ''} ` @@ -541,12 +541,14 @@ function saveModConfiguration(){ */ function _saveModConfiguration(modConf){ for(m of Object.entries(modConf)){ - const val = settingsModsContainer.querySelectorAll(`[formod='${m[0]}']`)[0].checked + const tSwitch = settingsModsContainer.querySelectorAll(`[formod='${m[0]}']`) if(typeof m[1] === 'boolean'){ - modConf[m[0]] = val + modConf[m[0]] = tSwitch[0].checked } else { if(m[1] != null){ - modConf[m[0]].value = val + if(tSwitch.length > 0){ + modConf[m[0]].value = tSwitch[0].checked + } modConf[m[0]].mods = _saveModConfiguration(modConf[m[0]].mods) } } diff --git a/app/assets/js/scripts/uibinder.js b/app/assets/js/scripts/uibinder.js index fe35206..691b976 100644 --- a/app/assets/js/scripts/uibinder.js +++ b/app/assets/js/scripts/uibinder.js @@ -167,7 +167,19 @@ function syncModConfigurations(data){ if(modsOld[mdlID] == null){ mods[mdlID] = scanOptionalSubModules(mdl.getSubModules(), mdl) } else { - mods[mdlID] = mergeModConfiguration(modsOld[mdlID], scanOptionalSubModules(mdl.getSubModules(), mdl)) + mods[mdlID] = mergeModConfiguration(modsOld[mdlID], scanOptionalSubModules(mdl.getSubModules(), mdl), false) + } + } else { + if(mdl.hasSubModules()){ + const mdlID = mdl.getVersionlessID() + const v = scanOptionalSubModules(mdl.getSubModules(), mdl) + if(typeof v === 'object'){ + if(modsOld[mdlID] == null){ + mods[mdlID] = v + } else { + mods[mdlID] = mergeModConfiguration(modsOld[mdlID], v, true) + } + } } } } @@ -187,6 +199,13 @@ function syncModConfigurations(data){ if(type === DistroManager.Types.ForgeMod || type === DistroManager.Types.LiteMod || type === DistroManager.Types.LiteLoader){ if(!mdl.getRequired().isRequired()){ mods[mdl.getVersionlessID()] = scanOptionalSubModules(mdl.getSubModules(), mdl) + } else { + if(mdl.hasSubModules()){ + const v = scanOptionalSubModules(mdl.getSubModules(), mdl) + if(typeof v === 'object'){ + mods[mdl.getVersionlessID()] = v + } + } } } } @@ -221,15 +240,25 @@ function scanOptionalSubModules(mdls, origin){ // It is optional. if(!mdl.getRequired().isRequired()){ mods[mdl.getVersionlessID()] = scanOptionalSubModules(mdl.getSubModules(), mdl) + } else { + if(mdl.hasSubModules()){ + const v = scanOptionalSubModules(mdl.getSubModules(), mdl) + if(typeof v === 'object'){ + mods[mdl.getVersionlessID()] = v + } + } } } } if(Object.keys(mods).length > 0){ - return { - value: origin.getRequired().isDefault(), + const ret = { mods } + if(!origin.getRequired().isRequired()){ + ret.value = origin.getRequired().isDefault() + } + return ret } } return origin.getRequired().isDefault() @@ -240,20 +269,25 @@ function scanOptionalSubModules(mdls, origin){ * * @param {boolean | Object} o The old configuration value. * @param {boolean | Object} n The new configuration value. + * @param {boolean} nReq If the new value is a required mod. * * @returns {boolean | Object} The merged configuration. */ -function mergeModConfiguration(o, n){ +function mergeModConfiguration(o, n, nReq = false){ if(typeof o === 'boolean'){ if(typeof n === 'boolean') return o else if(typeof n === 'object'){ - n.value = o + if(!nReq){ + n.value = o + } return n } } else if(typeof o === 'object'){ - if(typeof n === 'boolean') return o.value + if(typeof n === 'boolean') return typeof o.value !== 'undefined' ? o.value : true else if(typeof n === 'object'){ - n.value = o.value + if(!nReq){ + n.value = typeof o.value !== 'undefined' ? o.value : true + } const newMods = Object.keys(n.mods) for(let i=0; i