ConfigManager improvements. v0.0.1-alpha.1
Added new configuration option, launchDetached. Added validation function to ConfigManager to add missing keys (due to updates). Updated westeroscraft.json Game process can now be detached from the launcher.
This commit is contained in:
@@ -1562,6 +1562,7 @@ class AssetGuard extends EventEmitter {
|
||||
if(concurrentDlQueue.length === 0){
|
||||
return false
|
||||
} else {
|
||||
console.debug('DLQueue', concurrentDlQueue)
|
||||
async.eachLimit(concurrentDlQueue, limit, (asset, cb) => {
|
||||
let count = 0;
|
||||
mkpath.sync(path.join(asset.to, ".."))
|
||||
|
||||
@@ -38,7 +38,8 @@ const DEFAULT_CONFIG = {
|
||||
resWidth: 1280,
|
||||
resHeight: 720,
|
||||
fullscreen: false,
|
||||
autoConnect: true
|
||||
autoConnect: true,
|
||||
launchDetached: true
|
||||
},
|
||||
launcher: {}
|
||||
},
|
||||
@@ -78,9 +79,36 @@ exports.load = function(){
|
||||
exports.save()
|
||||
} else {
|
||||
config = JSON.parse(fs.readFileSync(filePath, 'UTF-8'))
|
||||
config = validateKeySet(DEFAULT_CONFIG, config)
|
||||
exports.save()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the destination object has at least every field
|
||||
* present in the source object. Assign a default value otherwise.
|
||||
*
|
||||
* @param {Object} srcObj The source object to reference against.
|
||||
* @param {Object} destObj The destination object.
|
||||
* @returns {Object} A validated destination object.
|
||||
*/
|
||||
function validateKeySet(srcObj, destObj){
|
||||
if(srcObj == null){
|
||||
srcObj = {}
|
||||
}
|
||||
const validationBlacklist = ['authenticationDatabase']
|
||||
const keys = Object.keys(srcObj)
|
||||
console.log(keys)
|
||||
for(let i=0; i<keys.length; i++){
|
||||
if(typeof destObj[keys[i]] === 'undefined'){
|
||||
destObj[keys[i]] = srcObj[keys[i]]
|
||||
} else if(typeof srcObj[keys[i]] === 'object' && srcObj[keys[i]] != null && !(srcObj[keys[i]] instanceof Array) && validationBlacklist.indexOf(keys[i]) === -1){
|
||||
destObj[keys[i]] = validateKeySet(srcObj[keys[i]], destObj[keys[i]])
|
||||
}
|
||||
}
|
||||
return destObj
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the absolute path of the launcher directory.
|
||||
*
|
||||
@@ -443,4 +471,23 @@ exports.isAutoConnect = function(def = false){
|
||||
*/
|
||||
exports.setAutoConnect = function(autoConnect){
|
||||
config.settings.game.autoConnect = autoConnect
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the game should launch as a detached process.
|
||||
*
|
||||
* @param {boolean} def Optional. If true, the default value will be returned.
|
||||
* @returns {boolean} Whether or not the game will launch as a detached process.
|
||||
*/
|
||||
exports.isLaunchDetached = function(def = false){
|
||||
return !def ? config.settings.game.launchDetached : DEFAULT_CONFIG.settings.game.launchDetached
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the status of whether or not the game should launch as a detached process.
|
||||
*
|
||||
* @param {boolean} launchDetached Whether or not the game should launch as a detached process.
|
||||
*/
|
||||
exports.setLaunchDetached = function(launchDetached){
|
||||
config.settings.game.launchDetached = launchDetached
|
||||
}
|
||||
@@ -44,9 +44,14 @@ class ProcessBuilder {
|
||||
console.log(args)
|
||||
|
||||
const child = child_process.spawn(ConfigManager.getJavaExecutable(), args, {
|
||||
cwd: ConfigManager.getGameDirectory()
|
||||
cwd: ConfigManager.getGameDirectory(),
|
||||
detached: ConfigManager.isLaunchDetached()
|
||||
})
|
||||
|
||||
if(ConfigManager.isLaunchDetached()){
|
||||
child.unref()
|
||||
}
|
||||
|
||||
child.stdout.on('data', (data) => {
|
||||
console.log('Minecraft:', data.toString('utf8'))
|
||||
})
|
||||
|
||||
@@ -72,7 +72,7 @@ function showMainUI(){
|
||||
$('#loadingContainer').fadeOut(500, () => {
|
||||
$('#loadSpinnerImage').removeClass('rotating')
|
||||
})
|
||||
}, 500)
|
||||
}, 250)
|
||||
|
||||
}, 750)
|
||||
initNews()
|
||||
@@ -160,6 +160,12 @@ async function validateSelectedAccount(){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporary function to update the selected account along
|
||||
* with the relevent UI elements.
|
||||
*
|
||||
* @param {string} uuid The UUID of the account.
|
||||
*/
|
||||
function setSelectedAccount(uuid){
|
||||
const authAcc = ConfigManager.setSelectedAccount(uuid)
|
||||
ConfigManager.save()
|
||||
|
||||
Reference in New Issue
Block a user