Skip to content

Commit b5e0dc1

Browse files
committed
fix dub gui editor
1 parent 3643e15 commit b5e0dc1

File tree

1 file changed

+62
-19
lines changed

1 file changed

+62
-19
lines changed

html/dubeditor.js

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,25 +284,17 @@ function removeInArray(arr, name, isArray, propName) {
284284
}
285285

286286
function makePath(/** @type {HTMLElement} */ setting, /** @type {string[]} */ path, /** @type {boolean} */ addSuffix, /** @type {boolean?} */ addOverrides) {
287-
let suffix = "";
287+
let suffix = getPlatformSuffix(setting);
288288
let prefix = [];
289-
if (setting.getAttribute("has-suffix") == "true") {
290-
if (platformSelector.value != OPTION_EMPTY_VALUE)
291-
suffix += "-" + platformSelector.value;
292-
if (architectureSelector.value != OPTION_EMPTY_VALUE)
293-
suffix += "-" + architectureSelector.value;
294-
if (compilerSelector.value != OPTION_EMPTY_VALUE)
295-
suffix += "-" + compilerSelector.value;
296-
297-
if (overridesSelector.value != OPTION_EMPTY_VALUE
298-
&& overridesSelector.value.startsWith("build:"))
299-
prefix = ["buildTypes", overridesSelector.value.substring("build:".length)];
300-
}
289+
let dubBuildType = getDUBBuildType(setting);
290+
let dubConfig = getDUBConfig(setting);
291+
if (dubBuildType)
292+
prefix = ["buildTypes", dubBuildType];
293+
if (dubConfig)
294+
prefix = ["configurations", ":name=" + dubConfig];
301295
// important: config and buildtypes cant mix!
302-
if (setting.getAttribute("has-config") != "false"
303-
&& overridesSelector.value != OPTION_EMPTY_VALUE
304-
&& overridesSelector.value.startsWith("config:"))
305-
prefix = ["configurations", ":name=" + overridesSelector.value.substring("config:".length)];
296+
if (dubBuildType && dubConfig)
297+
throw new Error("invalid state: can't have both config and build type set on a setting");
306298

307299
if (addOverrides === false)
308300
prefix = [];
@@ -313,6 +305,54 @@ function makePath(/** @type {HTMLElement} */ setting, /** @type {string[]} */ pa
313305
return ret;
314306
}
315307

308+
/**
309+
* @param {HTMLElement} [forSetting] optional, return empty string if this setting doesn't support any build type
310+
* @returns {string}
311+
*/
312+
function getDUBBuildType(forSetting) {
313+
if (forSetting && forSetting.getAttribute("has-suffix") != "true")
314+
return "";
315+
316+
if (overridesSelector.value != OPTION_EMPTY_VALUE
317+
&& overridesSelector.value.startsWith("build:"))
318+
return overridesSelector.value.substring("build:".length);
319+
else
320+
return "";
321+
}
322+
323+
/**
324+
* @param {HTMLElement} [forSetting] optional, return empty string if this setting doesn't support any config
325+
* @returns {string}
326+
*/
327+
function getDUBConfig(forSetting) {
328+
if (forSetting?.getAttribute("has-config") == "false")
329+
return "";
330+
331+
if (overridesSelector.value != OPTION_EMPTY_VALUE
332+
&& overridesSelector.value.startsWith("config:"))
333+
return overridesSelector.value.substring("config:".length);
334+
else
335+
return "";
336+
}
337+
338+
/**
339+
* @param {HTMLElement} [forSetting] optional, return empty string if this setting doesn't support any platform suffix
340+
* @returns {string}
341+
*/
342+
function getPlatformSuffix(forSetting) {
343+
if (forSetting?.getAttribute("has-suffix") != "true")
344+
return "";
345+
346+
let suffix = "";
347+
if (platformSelector.value != OPTION_EMPTY_VALUE)
348+
suffix += "-" + platformSelector.value;
349+
if (architectureSelector.value != OPTION_EMPTY_VALUE)
350+
suffix += "-" + architectureSelector.value;
351+
if (compilerSelector.value != OPTION_EMPTY_VALUE)
352+
suffix += "-" + compilerSelector.value;
353+
return suffix;
354+
}
355+
316356
function updateOverrides() {
317357
/**
318358
* @type {[string, string][]}
@@ -709,7 +749,7 @@ function loadJsonIntoUI() {
709749
var newVal;
710750
if (type == "string[]") {
711751
if (!isOverride && setting.value.trim() == "")
712-
newVal = undefined; // allow empty strings in overrides
752+
newVal = []; // allow empty arrays in overrides
713753
else
714754
newVal = setting.value.split("\n");
715755
}
@@ -718,7 +758,10 @@ function loadJsonIntoUI() {
718758
? setting.value // allow empty strings in overrides
719759
: (setting.value || undefined);
720760
return newVal;
721-
}).bind(this, type, setting, isOverride);
761+
}).bind(this, type, setting, usedAccess
762+
&& (getDUBBuildType(setting)
763+
|| getDUBConfig(setting)
764+
|| getPlatformSuffix(setting)));
722765
}
723766
var configSetting;
724767
if (configPath !== undefined)

0 commit comments

Comments
 (0)