Added support for optional submods of required mods.
This commit is contained in:
parent
60ba7b4f8a
commit
0c98cc2447
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -465,7 +465,7 @@ function parseModulesForUI(mdls, submodules = false, servConf){
|
||||
</label>
|
||||
</div>
|
||||
${mdl.hasSubModules() ? `<div class="settingsSubModContainer">
|
||||
${Object.values(parseModulesForUI(mdl.getSubModules(), true)).join('')}
|
||||
${Object.values(parseModulesForUI(mdl.getSubModules(), true, servConf[mdl.getVersionlessID()])).join('')}
|
||||
</div>` : ''}
|
||||
</div>`
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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'){
|
||||
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<newMods.length; i++){
|
||||
@ -346,6 +380,7 @@ document.addEventListener('readystatechange', function(){
|
||||
|
||||
if (document.readyState === 'interactive' || document.readyState === 'complete'){
|
||||
if(rscShouldLoad){
|
||||
rscShouldLoad = false
|
||||
if(!fatalStartupError){
|
||||
const data = DistroManager.getDistribution()
|
||||
showMainUI(data)
|
||||
@ -353,13 +388,8 @@ document.addEventListener('readystatechange', function(){
|
||||
showFatalStartupError()
|
||||
}
|
||||
}
|
||||
}// else if(document.readyState === 'interactive'){
|
||||
//toggleOverlay(true, 'loadingContent')
|
||||
//}
|
||||
}
|
||||
|
||||
/*if (document.readyState === 'interactive'){
|
||||
|
||||
}*/
|
||||
}, false)
|
||||
|
||||
// Actions that must be performed after the distribution index is downloaded.
|
||||
|
Loading…
Reference in New Issue
Block a user