From 8f05ace34440d9af944d79af5d27bedb154eb4f4 Mon Sep 17 00:00:00 2001 From: FinnHornhoover Date: Mon, 13 Nov 2023 00:15:45 +0300 Subject: [PATCH] added config modal, bumped version --- assets/css/openfusion.css | 5 ++ assets/js/server-selector.js | 52 +++++++++++++++++++- defaults/config.json | 4 +- index.html | 95 +++++++++++++++++++++++++++++++++++- index.js | 6 +-- 5 files changed, 154 insertions(+), 8 deletions(-) diff --git a/assets/css/openfusion.css b/assets/css/openfusion.css index c8bc8d8..a357719 100644 --- a/assets/css/openfusion.css +++ b/assets/css/openfusion.css @@ -115,6 +115,11 @@ body { border-color: #6699ff; } +#of-editconfigmodal > .modal-dialog > .modal-content { + background-color: #093363; + border-color: #6699ff; +} + #of-addversionmodal > .modal-dialog > .modal-content { background-color: #093363; border-color: #6699ff; diff --git a/assets/js/server-selector.js b/assets/js/server-selector.js index 149a6e7..6a1f1b0 100644 --- a/assets/js/server-selector.js +++ b/assets/js/server-selector.js @@ -14,7 +14,8 @@ var cacheRoot = path.join( userData, "/../../LocalLow/Unity/Web Player/Cache" ); -var offlineRoot = path.join(cacheRoot, "Offline"); +var offlineRootDefault = path.join(cacheRoot, "Offline"); +var offlineRoot = offlineRootDefault; var cdnString = "http://cdn.dexlabs.systems/ff/big"; @@ -292,6 +293,38 @@ function restoreDefaultVersions() { handleCache("hash-check"); } +function editConfig() { + var jsonToModify = JSON.parse(remotefs.readJsonSync(configPath)); + + jsonToModify["autoupdate-check"] = $("#editconfig-autoupdate").prop("checked"); + jsonToModify["cache-swapping"] = $("#editconfig-cacheswapping").prop("checked"); + jsonToModify["enable-offline-cache"] = $("#editconfig-enableofflinecache").prop("checked"); + jsonToModify["verify-offline-cache"] = $("#editconfig-verifyofflinecache").prop("checked"); + + var dirInput = $("#editconfig-offlinecachelocation:text").val(); + + jsonToModify["offline-cache-location"] = ( + remotefs.existsSync(dirInput) && + remotefs.statSync(dirInput).isDirectory() + ) ? dirInput : offlineRoot; + + remotefs.writeFileSync(configPath, JSON.stringify(jsonToModify, null, 4)); + loadConfig(); +} + +function validateCacheLocation() { + var input = document.getElementById("editconfig-offlinecachelocation"); + var button = document.getElementById("editconfig-savebutton"); + + input.classList.remove("invalidinput"); + button.removeAttribute("disabled"); + + if (!remotefs.existsSync(input.value) || !remotefs.statSync(input.value).isDirectory()) { + input.classList.add("invalidinput"); + button.setAttribute("disabled", ""); + } +} + function loadGameVersions() { var versionJson = remotefs.readJsonSync(versionsPath); versionArray = versionJson["versions"]; @@ -304,6 +337,16 @@ function loadGameVersions() { function loadConfig() { // Load config object globally config = remotefs.readJsonSync(configPath); + + $("#editconfig-autoupdate").prop("checked", config["autoupdate-check"]); + $("#editconfig-cacheswapping").prop("checked", config["cache-swapping"]); + $("#editconfig-enableofflinecache").prop("checked", config["enable-offline-cache"]); + $("#editconfig-verifyofflinecache").prop("checked", config["verify-offline-cache"]); + + offlineRoot = config["offline-cache-location"] || offlineRootDefault; + $("#editconfig-offlinecachelocation:text").val(offlineRoot); + + validateCacheLocation(); } function loadServerList() { @@ -685,7 +728,7 @@ function prepGameInfo(serverUUID) { } } - if (config["always-use-cdn"]) { + if (!config["enable-offline-cache"]) { // if we always ignore the offline cache, just use the URL setGameInfo(serverInfo, versionInfo.url); return; @@ -898,3 +941,8 @@ $("#of-deleteversionmodal").on("show.bs.modal", function (e) { $("#of-editcacheconfigmodal").on("show.bs.modal", function (e) { if (!cacheSizes) handleCache("hash-check"); }); + +$("#of-editconfigmodal").on("show.bs.modal", function (e) { + // best to keep this synced on modal show + loadConfig(); +}); diff --git a/defaults/config.json b/defaults/config.json index 86e3078..d8b71ae 100644 --- a/defaults/config.json +++ b/defaults/config.json @@ -1,7 +1,7 @@ { "autoupdate-check": true, "cache-swapping": true, - "always-use-cdn": true, + "enable-offline-cache": false, "verify-offline-cache": false, - "last-version-initialized": "1.5" + "last-version-initialized": "1.6" } diff --git a/index.html b/index.html index e13eb6d..9b0d60a 100644 --- a/index.html +++ b/index.html @@ -108,6 +108,18 @@
+
+