Added initial support for optional mods.

Optional mods are stored by ID in the configuration. Their enabled state is stored here. The mod configurations are updated each time the distro index is refreshed. Configurations are stored by server id. If the id no longer exists (changed/removed), the mod configuration is removed. If new optional mods are added, they are added to the configuration. If they are removed, they are removed from the configuration.

Currently only top level optional mods are supported.
This commit is contained in:
Daniel Scalzi
2018-06-23 15:17:26 -04:00
parent 4196856d31
commit 145a2fe77b
4 changed files with 166 additions and 26 deletions

View File

@@ -1,18 +1,14 @@
/**
* The initial iteration of this file will not support optional submodules.
* Support will be added down the line, only top-level modules will recieve optional support.
*/
const AdmZip = require('adm-zip')
const AdmZip = require('adm-zip')
const {AssetGuard, Library} = require('./assetguard.js')
const child_process = require('child_process')
const ConfigManager = require('./configmanager.js')
const crypto = require('crypto')
const fs = require('fs')
const mkpath = require('mkdirp')
const os = require('os')
const path = require('path')
const rimraf = require('rimraf')
const {URL} = require('url')
const child_process = require('child_process')
const ConfigManager = require('./configmanager.js')
const crypto = require('crypto')
const fs = require('fs')
const mkpath = require('mkdirp')
const os = require('os')
const path = require('path')
const rimraf = require('rimraf')
const {URL} = require('url')
class ProcessBuilder {
@@ -26,11 +22,6 @@ class ProcessBuilder {
this.fmlDir = path.join(this.commonDir, 'versions', this.server.id + '.json')
this.libPath = path.join(this.commonDir, 'libraries')
}
static shouldInclude(mdle){
//If the module should be included by default
return mdle.required == null || mdle.required.value == null || mdle.required.value === true || (mdle.required.value === false && (mdle.required.def == null || mdle.required.def === true))
}
/**
* Convienence method to run the functions typically used to build a process.
@@ -77,12 +68,19 @@ class ProcessBuilder {
resolveDefaultMods(options = {type: 'forgemod'}){
//Returns array of default forge mods to load.
const mods = []
const mdles = this.server.modules
const mdls = this.server.modules
const modCfg = ConfigManager.getModConfiguration(this.server.id).mods
for(let i=0; i<mdles.length; ++i){
if(mdles[i].type != null && mdles[i].type === options.type){
if(ProcessBuilder.shouldInclude(mdles[i])){
mods.push(mdles[i])
for(let i=0; i<mdls.length; ++i){
const mdl = mdls[i]
if(mdl.type != null && mdl.type === options.type){
if(mdl.required != null && mdl.required.value === false){
const val = modCfg[AssetGuard._resolveWithoutVersion(mdl.id)]
if(val === true){
mods.push(mdl)
}
} else {
mods.push(mdl)
}
}
}