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

@@ -69,7 +69,8 @@ const DEFAULT_CONFIG = {
clientToken: uuidV4().replace(/-/g, ''),
selectedServer: null, // Resolved
selectedAccount: null,
authenticationDatabase: {}
authenticationDatabase: {},
modConfigurations: []
}
let config = null;
@@ -92,7 +93,6 @@ exports.save = function(){
*/
exports.load = function(){
// Determine the effective configuration.
//const EFFECTIVE_CONFIG = config == null ? DEFAULT_CONFIG : config
const filePath = path.join(dataPath, 'config.json')
if(!fs.existsSync(filePath)){
@@ -353,6 +353,57 @@ exports.setSelectedAccount = function(uuid){
return authAcc
}
/**
* Get an array of each mod configuration currently stored.
*
* @returns {Array.<Object>} An array of each stored mod configuration.
*/
exports.getModConfigurations = function(){
return config.modConfigurations
}
/**
* Set the array of stored mod configurations.
*
* @param {Array.<Object>} configurations An array of mod configurations.
*/
exports.setModConfigurations = function(configurations){
config.modConfigurations = configurations
}
/**
* Get the mod configuration for a specific server.
*
* @param {string} serverid The id of the server.
* @returns {Object} The mod configuration for the given server.
*/
exports.getModConfiguration = function(serverid){
const cfgs = config.modConfigurations
for(let i=0; i<cfgs.length; i++){
if(cfgs[i].id === serverid){
return cfgs[i]
}
}
return null
}
/**
* Set the mod configuration for a specific server. This overrides any existing value.
*
* @param {string} serverid The id of the server for the given mod configuration.
* @param {Object} configuration The mod configuration for the given server.
*/
exports.setModConfiguration = function(serverid, configuration){
const cfgs = config.modConfigurations
for(let i=0; i<cfgs.length; i++){
if(cfgs[i].id === serverid){
cfgs[i] = configuration
return
}
}
cfgs.push(configuration)
}
// User Configurable Settings
// Java Settings