Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
/**
|
2017-12-10 08:13:18 -08:00
|
|
|
* @file This GUI page displays all available mods and allows the player to enabled and launch a set of compatible mods.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2025-05-12 13:02:00 -07:00
|
|
|
* A mod is defined by a mod.json file.
|
2017-12-10 08:13:18 -08:00
|
|
|
* A mod is identified by the directory name.
|
|
|
|
|
* A mod must define the "name", "version", "label", "description" and "dependencies" property.
|
|
|
|
|
* The "url" property is optional.
|
|
|
|
|
*
|
|
|
|
|
* The property "name" can consist alphanumeric characters, underscore and dash.
|
|
|
|
|
* The name is used for version comparison of mod dependencies.
|
|
|
|
|
* The property "version" may only contain numbers and up to two periods.
|
|
|
|
|
* The property "label" is a human-readable name of the mod.
|
|
|
|
|
* The property "description" is a human-readable summary of the features of the mod.
|
|
|
|
|
* The property "url" is reference to a website about the mod.
|
|
|
|
|
* The property "dependencies" is an array of strings. Each string is either a modname or a mod version comparison.
|
|
|
|
|
* A mod version comparison is a modname, followed by an operator (=, <, >, <= or >=), followed by a mod version.
|
|
|
|
|
* This allows mods to express upwards and downwards compatibility.
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
*/
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2026-07-27 03:23:43 -07:00
|
|
|
import { downloadModsButton } from "gui/modmod/modmodio.js";
|
|
|
|
|
import { regExpComparisonOperator, validateMod } from "gui/modmod/validatemod.js";
|
|
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
/**
|
2017-12-10 08:13:18 -08:00
|
|
|
* Mod definitions loaded from the files, including invalid mods.
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
*/
|
2026-07-27 03:23:43 -07:00
|
|
|
let g_Mods = {};
|
2014-08-25 09:02:54 -07:00
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
/**
|
|
|
|
|
* Folder names of all mods that are or can be launched.
|
|
|
|
|
*/
|
2026-07-27 03:23:43 -07:00
|
|
|
let g_ModsEnabled = [];
|
|
|
|
|
let g_ModsDisabled = [];
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2026-07-27 03:23:43 -07:00
|
|
|
let g_ModsEnabledFiltered = [];
|
|
|
|
|
let g_ModsDisabledFiltered = [];
|
2019-12-20 12:19:21 -08:00
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
/**
|
|
|
|
|
* Cache mod compatibility recomputed when some mod is enbaled/disabled.
|
|
|
|
|
*/
|
2026-07-27 03:23:43 -07:00
|
|
|
const g_ModsCompatibility = [];
|
2021-03-21 03:22:50 -07:00
|
|
|
|
2018-04-14 18:46:28 -07:00
|
|
|
/**
|
|
|
|
|
* Name of the mods installed by the ModInstaller.
|
|
|
|
|
*/
|
2026-07-27 03:23:43 -07:00
|
|
|
let g_InstalledMods;
|
2018-04-14 18:46:28 -07:00
|
|
|
|
2026-07-27 03:23:43 -07:00
|
|
|
let g_HasIncompatibleMods;
|
2021-05-09 06:53:25 -07:00
|
|
|
|
2026-07-27 03:23:43 -07:00
|
|
|
/* eslint-disable prefer-const -- Mods should be able to change them */
|
|
|
|
|
let g_FakeMod = {
|
2021-05-09 06:53:25 -07:00
|
|
|
"name": translate("This mod does not exist"),
|
|
|
|
|
"version": "",
|
|
|
|
|
"label": "",
|
|
|
|
|
"url": "",
|
|
|
|
|
"description": "",
|
|
|
|
|
"dependencies": []
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-27 03:23:43 -07:00
|
|
|
let g_ColorNoModSelected = "255 255 100";
|
|
|
|
|
let g_ColorDependenciesMet = "100 255 100";
|
|
|
|
|
let g_ColorDependenciesNotMet = "255 100 100";
|
|
|
|
|
/* eslint-enable prefer-const */
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2026-07-27 03:23:43 -07:00
|
|
|
export function init(data, hotloadData)
|
2018-04-14 18:46:28 -07:00
|
|
|
{
|
2026-07-27 03:23:43 -07:00
|
|
|
Object.assign(Engine.GetGUIObjectByName("modsDisabledList"), {
|
|
|
|
|
"onSelectionChange": selectedMod.bind(undefined, "modsDisabledList"),
|
|
|
|
|
"onSelectionColumnChange": displayModLists,
|
|
|
|
|
"onMouseLeftDoubleClickItem": enableMod
|
|
|
|
|
});
|
|
|
|
|
Object.assign(Engine.GetGUIObjectByName("modsEnabledList"), {
|
|
|
|
|
"onSelectionChange": selectedMod.bind(undefined, "modsEnabledList"),
|
|
|
|
|
"onMouseLeftDoubleClickItem": disableMod
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Engine.GetGUIObjectByName("enabledModUp").onPress =
|
|
|
|
|
moveCurrItem.bind(undefined, "modsEnabledList", true);
|
|
|
|
|
Engine.GetGUIObjectByName("enabledModDown").onPress =
|
|
|
|
|
moveCurrItem.bind(undefined, "modsEnabledList", false);
|
|
|
|
|
|
|
|
|
|
Engine.GetGUIObjectByName("visitWebButton").onPress = visitModWebsite;
|
|
|
|
|
Engine.GetGUIObjectByName("downloadButton").onPress = downloadModsButton.bind(undefined, initMods);
|
|
|
|
|
Engine.GetGUIObjectByName("saveConfigurationButton").onPress = saveMods;
|
|
|
|
|
Engine.GetGUIObjectByName("startButton").onPress = startMods;
|
|
|
|
|
|
|
|
|
|
|
2018-04-14 18:46:28 -07:00
|
|
|
g_InstalledMods = data && data.installedMods || hotloadData && hotloadData.installedMods || [];
|
2021-05-20 07:36:42 -07:00
|
|
|
g_HasIncompatibleMods = Engine.HasIncompatibleMods();
|
2018-09-14 08:14:48 -07:00
|
|
|
|
2018-04-14 18:46:28 -07:00
|
|
|
initMods();
|
|
|
|
|
initGUIButtons(data);
|
2021-05-20 07:36:42 -07:00
|
|
|
if (g_HasIncompatibleMods)
|
2024-10-30 10:56:33 -07:00
|
|
|
Engine.OpenChildPage("page_incompatible_mods.xml", {});
|
2024-10-28 13:34:20 -07:00
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
return new Promise(closePageCallback =>
|
|
|
|
|
{
|
2024-10-28 13:34:20 -07:00
|
|
|
Engine.GetGUIObjectByName("quitButton").onPress = closePageCallback;
|
2025-04-24 09:09:03 -07:00
|
|
|
Engine.GetGUIObjectByName("cancelButton").onPress = closePageCallback.bind(undefined, {
|
|
|
|
|
[Engine.openRequest]: { "page": "page_pregame.xml" }
|
|
|
|
|
});
|
2024-10-28 13:34:20 -07:00
|
|
|
});
|
2018-04-14 18:46:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initMods()
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
{
|
|
|
|
|
loadMods();
|
2017-12-10 08:13:18 -08:00
|
|
|
loadEnabledMods();
|
2021-03-21 03:22:50 -07:00
|
|
|
recomputeCompatibility();
|
2017-12-10 08:13:18 -08:00
|
|
|
validateMods();
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
initGUIFilters();
|
2018-04-14 18:46:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getHotloadData()
|
|
|
|
|
{
|
|
|
|
|
return { "installedMods": g_InstalledMods };
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadMods()
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2017-12-10 08:13:18 -08:00
|
|
|
g_Mods = Engine.GetAvailableMods();
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
deepfreeze(g_Mods);
|
2017-12-10 08:13:18 -08:00
|
|
|
}
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2021-05-09 06:53:25 -07:00
|
|
|
/**
|
|
|
|
|
* Return fake mod for mods which do not exist
|
|
|
|
|
*/
|
|
|
|
|
function getMod(folder)
|
|
|
|
|
{
|
2025-06-13 09:23:18 -07:00
|
|
|
return g_Mods[folder] ? g_Mods[folder] : g_FakeMod;
|
2021-05-09 06:53:25 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-10 08:13:18 -08:00
|
|
|
function loadEnabledMods()
|
|
|
|
|
{
|
2021-05-20 07:36:42 -07:00
|
|
|
if (g_HasIncompatibleMods)
|
2021-05-22 00:33:49 -07:00
|
|
|
g_ModsEnabled = Engine.GetEnabledMods().concat(Engine.GetIncompatibleMods())
|
|
|
|
|
.filter(folder => folder != "mod");
|
2021-05-09 06:53:25 -07:00
|
|
|
else
|
|
|
|
|
g_ModsEnabled = Engine.GetEnabledMods().filter(folder => !!g_Mods[folder]);
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
g_ModsDisabled = Object.keys(g_Mods).filter(folder => g_ModsEnabled.indexOf(folder) == -1);
|
2019-12-20 12:19:21 -08:00
|
|
|
g_ModsEnabledFiltered = g_ModsEnabled;
|
|
|
|
|
g_ModsDisabledFiltered = g_ModsDisabled;
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-10 08:13:18 -08:00
|
|
|
function validateMods()
|
|
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
for (const folder in g_Mods)
|
2017-12-10 08:13:18 -08:00
|
|
|
validateMod(folder, g_Mods[folder], true);
|
|
|
|
|
}
|
|
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
function initGUIFilters()
|
|
|
|
|
{
|
2014-08-25 09:02:54 -07:00
|
|
|
Engine.GetGUIObjectByName("negateFilter").checked = false;
|
2021-03-21 03:22:50 -07:00
|
|
|
Engine.GetGUIObjectByName("modCompatibleFilter").checked = true;
|
2014-08-25 09:02:54 -07:00
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
displayModLists();
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-12 08:06:52 -08:00
|
|
|
function initGUIButtons(data)
|
|
|
|
|
{
|
|
|
|
|
// Either get back to the previous page or quit if there is no previous page
|
2025-05-06 04:49:01 -07:00
|
|
|
const hasPreviousPage = !data || data.cancelbutton || false;
|
2021-05-09 06:53:25 -07:00
|
|
|
Engine.GetGUIObjectByName("cancelButton").hidden = !hasPreviousPage;
|
|
|
|
|
Engine.GetGUIObjectByName("quitButton").hidden = hasPreviousPage;
|
2021-05-26 06:27:43 -07:00
|
|
|
// Turn 'save' off, it will be enabled on any change.
|
|
|
|
|
Engine.GetGUIObjectByName("saveConfigurationButton").enabled = false;
|
2020-02-17 10:22:52 -08:00
|
|
|
Engine.GetGUIObjectByName("toggleModButton").caption = translateWithContext("mod activation", "Enable");
|
2017-12-12 08:06:52 -08:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 09:02:54 -07:00
|
|
|
function saveMods()
|
|
|
|
|
{
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
sortEnabledMods();
|
2022-11-02 00:21:25 -07:00
|
|
|
Engine.ConfigDB_CreateAndSaveValue("user", "mod.enabledmods", ["mod"].concat(g_ModsEnabled).join(" "));
|
2021-05-26 06:27:43 -07:00
|
|
|
|
|
|
|
|
Engine.GetGUIObjectByName("saveConfigurationButton").enabled = false;
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startMods()
|
|
|
|
|
{
|
2021-05-26 06:27:43 -07:00
|
|
|
saveMods();
|
2021-05-09 06:53:25 -07:00
|
|
|
if (!Engine.SetModsAndRestartEngine(["mod"].concat(g_ModsEnabled)))
|
|
|
|
|
Engine.GetGUIObjectByName("message").caption = coloredText(translate('Dependencies not met'), g_ColorDependenciesNotMet);
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
function displayModLists()
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2021-03-21 03:22:50 -07:00
|
|
|
g_ModsEnabledFiltered = displayModList("modsEnabledList", g_ModsEnabled, true);
|
|
|
|
|
g_ModsDisabledFiltered = displayModList("modsDisabledList", g_ModsDisabled, false);
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
function displayModList(listObjectName, folders, enabled)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const listObject = Engine.GetGUIObjectByName(listObjectName);
|
2017-11-29 04:47:16 -08:00
|
|
|
|
|
|
|
|
if (listObjectName == "modsDisabledList")
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const sortFolder = folder => String(getMod(folder)[listObject.selected_column] || folder);
|
2017-11-29 04:47:16 -08:00
|
|
|
folders.sort((folder1, folder2) =>
|
|
|
|
|
listObject.selected_column_order *
|
|
|
|
|
sortFolder(folder1).localeCompare(sortFolder(folder2)));
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
folders = folders.filter(filterMod);
|
2021-03-21 03:22:50 -07:00
|
|
|
if (!enabled && Engine.GetGUIObjectByName("modCompatibleFilter").checked)
|
|
|
|
|
folders = folders.filter(folder => g_ModsCompatibility[folder]);
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const selected = listObject.selected !== -1 ? listObject.list_name[listObject.selected] : null;
|
2021-02-08 02:13:06 -08:00
|
|
|
|
2021-06-02 10:58:49 -07:00
|
|
|
listObject.list_name = folders.map(folder => colorMod(folder, getMod(folder).name || "", enabled));
|
2021-03-21 03:22:50 -07:00
|
|
|
listObject.list_folder = folders.map(folder => colorMod(folder, folder, enabled));
|
2021-06-02 10:58:49 -07:00
|
|
|
listObject.list_label = folders.map(folder => colorMod(folder, getMod(folder).label || "", enabled));
|
2021-05-09 06:53:25 -07:00
|
|
|
listObject.list_url = folders.map(folder => colorMod(folder, getMod(folder).url || "", enabled));
|
2021-06-02 10:58:49 -07:00
|
|
|
listObject.list_version = folders.map(folder => colorMod(folder, getMod(folder).version || "", enabled));
|
|
|
|
|
listObject.list_dependencies = folders.map(folder => colorMod(folder, getMod(folder)?.dependencies.join(" ") || "", enabled));
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
listObject.list = folders;
|
2019-12-20 12:19:21 -08:00
|
|
|
|
2021-02-08 02:13:06 -08:00
|
|
|
listObject.selected = selected ? listObject.list_name.indexOf(selected) : -1;
|
|
|
|
|
|
2019-12-20 12:19:21 -08:00
|
|
|
return folders;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
function getModColor(folder, enabled)
|
|
|
|
|
{
|
|
|
|
|
if (!g_ModsCompatibility[folder])
|
|
|
|
|
return enabled ? g_ColorDependenciesNotMet : "gray";
|
2021-05-09 06:53:25 -07:00
|
|
|
if (g_InstalledMods.indexOf(getMod(folder).name) != -1)
|
2021-03-21 03:22:50 -07:00
|
|
|
return "green";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function colorMod(folder, text, enabled)
|
|
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const color = getModColor(folder, enabled);
|
2021-03-21 03:22:50 -07:00
|
|
|
return color ? coloredText(text, color) : text;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-20 12:19:21 -08:00
|
|
|
function reloadDisabledMods()
|
|
|
|
|
{
|
|
|
|
|
g_ModsDisabled = Object.keys(g_Mods).filter(folder => g_ModsEnabled.indexOf(folder) == -1);
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function enableMod()
|
|
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const modsDisabledList = Engine.GetGUIObjectByName("modsDisabledList");
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
let pos = modsDisabledList.selected;
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
if (pos == -1 || !g_ModsCompatibility[g_ModsDisabledFiltered[pos]])
|
2014-08-25 09:02:54 -07:00
|
|
|
return;
|
|
|
|
|
|
2019-12-20 12:19:21 -08:00
|
|
|
g_ModsEnabled.push(g_ModsDisabledFiltered.splice(pos, 1)[0]);
|
|
|
|
|
reloadDisabledMods();
|
2021-03-21 03:22:50 -07:00
|
|
|
recomputeCompatibility();
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
2021-05-26 06:27:43 -07:00
|
|
|
Engine.GetGUIObjectByName("saveConfigurationButton").enabled = true;
|
|
|
|
|
|
2019-12-20 12:19:21 -08:00
|
|
|
if (pos >= g_ModsDisabledFiltered.length)
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
--pos;
|
2014-08-25 09:02:54 -07:00
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
displayModLists();
|
2021-05-09 06:53:25 -07:00
|
|
|
Engine.GetGUIObjectByName("message").caption = "";
|
2019-12-20 12:19:21 -08:00
|
|
|
modsDisabledList.selected = pos;
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function disableMod()
|
|
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const modsEnabledList = Engine.GetGUIObjectByName("modsEnabledList");
|
|
|
|
|
const pos = modsEnabledList.selected;
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
if (pos == -1)
|
2014-08-25 09:02:54 -07:00
|
|
|
return;
|
|
|
|
|
|
2019-12-20 12:19:21 -08:00
|
|
|
// Find true position of disabled mod and remove it
|
2025-05-06 04:49:01 -07:00
|
|
|
const disabledMod = g_ModsEnabledFiltered[pos];
|
2019-12-20 12:19:21 -08:00
|
|
|
for (let i = 0; i < g_ModsEnabled.length; ++i)
|
|
|
|
|
if (g_ModsEnabled[i] == disabledMod)
|
|
|
|
|
{
|
|
|
|
|
g_ModsEnabled.splice(i, 1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-13 09:23:18 -07:00
|
|
|
if (g_Mods[disabledMod])
|
2021-05-09 06:53:25 -07:00
|
|
|
g_ModsDisabled.push(disabledMod);
|
2014-08-25 09:02:54 -07:00
|
|
|
|
|
|
|
|
// Remove mods that required the removed mod and cascade
|
|
|
|
|
// Sort them, so we know which ones can depend on the removed mod
|
|
|
|
|
// TODO: Find position where the removed mod would have fit (for now assume idx 0)
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
|
|
|
|
sortEnabledMods();
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < g_ModsEnabled.length; ++i)
|
2021-03-21 03:22:50 -07:00
|
|
|
if (!areDependenciesMet(g_ModsEnabled[i], true))
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
g_ModsDisabled.push(g_ModsEnabled.splice(i, 1)[0]);
|
2014-08-25 09:02:54 -07:00
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-26 06:27:43 -07:00
|
|
|
Engine.GetGUIObjectByName("saveConfigurationButton").enabled = true;
|
|
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
recomputeCompatibility(true);
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
displayModLists();
|
2021-05-09 06:53:25 -07:00
|
|
|
Engine.GetGUIObjectByName("message").caption = "";
|
2019-12-20 12:19:21 -08:00
|
|
|
modsEnabledList.selected = Math.min(pos, g_ModsEnabledFiltered.length - 1);
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
function filterMod(folder)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const mod = getMod(folder);
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const negateFilter = Engine.GetGUIObjectByName("negateFilter").checked;
|
|
|
|
|
const searchText = Engine.GetGUIObjectByName("modGenericFilter").caption;
|
2017-12-03 13:44:16 -08:00
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
if (searchText &&
|
|
|
|
|
folder.indexOf(searchText) == -1 &&
|
2021-06-02 10:58:49 -07:00
|
|
|
(mod.name || "").indexOf(searchText) == -1 &&
|
|
|
|
|
(mod.label || "").indexOf(searchText) == -1 &&
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
(mod.url || "").indexOf(searchText) == -1 &&
|
2021-06-02 10:58:49 -07:00
|
|
|
(mod.version || "").indexOf(searchText) == -1 &&
|
|
|
|
|
(mod.description || "").indexOf(searchText) == -1 &&
|
|
|
|
|
(mod.dependencies || "").indexOf(searchText) == -1)
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
return negateFilter;
|
|
|
|
|
|
|
|
|
|
return !negateFilter;
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
* Moves an item in the list up or down.
|
2014-08-25 09:02:54 -07:00
|
|
|
*/
|
|
|
|
|
function moveCurrItem(objectName, up)
|
|
|
|
|
{
|
2019-12-20 12:19:21 -08:00
|
|
|
// Prevent moving while filters are applied
|
|
|
|
|
// because we would need to map filtered positions
|
|
|
|
|
// to not filtered positions so changes will persist.
|
2021-05-30 02:32:18 -07:00
|
|
|
if (Engine.GetGUIObjectByName("modGenericFilter").caption)
|
2019-12-20 12:19:21 -08:00
|
|
|
return;
|
|
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const obj = Engine.GetGUIObjectByName(objectName);
|
|
|
|
|
const idx = obj.selected;
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
if (idx == -1)
|
2014-08-25 09:02:54 -07:00
|
|
|
return;
|
|
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const num = obj.list.length;
|
|
|
|
|
const idx2 = idx + (up ? -1 : 1);
|
2014-08-25 09:02:54 -07:00
|
|
|
if (idx2 < 0 || idx2 >= num)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const tmp = g_ModsEnabled[idx];
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
g_ModsEnabled[idx] = g_ModsEnabled[idx2];
|
|
|
|
|
g_ModsEnabled[idx2] = tmp;
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
g_ModsEnabledFiltered = displayModList("modsEnabledList", g_ModsEnabled, true);
|
2015-02-02 18:37:42 -08:00
|
|
|
obj.selected = idx2;
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
function areDependenciesMet(folder, disabledAction = false)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2021-03-21 03:22:50 -07:00
|
|
|
// If we disabled mod it will not change satus of incompatible mods
|
|
|
|
|
if (disabledAction && !g_ModsCompatibility[folder])
|
|
|
|
|
return g_ModsCompatibility[folder];
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
2021-05-09 06:53:25 -07:00
|
|
|
if (!g_Mods[folder])
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
for (const dependency of getMod(folder).dependencies)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2021-03-21 03:22:50 -07:00
|
|
|
if (!isDependencyMet(dependency))
|
|
|
|
|
return false;
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
function recomputeCompatibility(disabledAction = false)
|
|
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
for (const mod in g_Mods)
|
2021-03-21 03:22:50 -07:00
|
|
|
g_ModsCompatibility[mod] = areDependenciesMet(mod, disabledAction);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 09:02:54 -07:00
|
|
|
/**
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
* @param dependency is a mod name or a mod version comparison.
|
2014-08-25 09:02:54 -07:00
|
|
|
*/
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
function isDependencyMet(dependency)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2026-07-27 03:23:43 -07:00
|
|
|
const operator = dependency.match(regExpComparisonOperator);
|
2025-05-06 04:49:01 -07:00
|
|
|
const [name, version] = operator ? dependency.split(operator[0]) : [dependency, undefined];
|
2014-08-25 09:02:54 -07:00
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
return g_ModsEnabled.some(folder =>
|
2021-05-09 06:53:25 -07:00
|
|
|
getMod(folder).name == name &&
|
|
|
|
|
(!operator || versionSatisfied(getMod(folder).version, operator[0], version)));
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
* Compares the given versions using the given operator.
|
2014-08-25 09:02:54 -07:00
|
|
|
* '-' or '_' is ignored. Only numbers are supported.
|
|
|
|
|
* @note "5.3" < "5.3.0"
|
|
|
|
|
*/
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
function versionSatisfied(version1, operator, version2)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const versionList1 = version1.split(/[-_]/)[0].split(/\./g);
|
|
|
|
|
const versionList2 = version2.split(/[-_]/)[0].split(/\./g);
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const eq = operator.indexOf("=") != -1;
|
|
|
|
|
const lt = operator.indexOf("<") != -1;
|
|
|
|
|
const gt = operator.indexOf(">") != -1;
|
2014-08-25 09:02:54 -07:00
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
for (let i = 0; i < Math.min(versionList1.length, versionList2.length); ++i)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const diff = +versionList1[i] - +versionList2[i];
|
2014-08-25 09:02:54 -07:00
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
if (gt && diff > 0 || lt && diff < 0)
|
2014-08-25 09:02:54 -07:00
|
|
|
return true;
|
|
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
if (gt && diff < 0 || lt && diff > 0 || eq && diff)
|
2014-08-25 09:02:54 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
2014-08-25 09:02:54 -07:00
|
|
|
// common prefix matches
|
2025-05-06 04:49:01 -07:00
|
|
|
const ldiff = versionList1.length - versionList2.length;
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
if (!ldiff)
|
2014-08-25 09:02:54 -07:00
|
|
|
return eq;
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
2014-08-25 09:02:54 -07:00
|
|
|
// NB: 2.3 != 2.3.0
|
|
|
|
|
if (ldiff < 0)
|
|
|
|
|
return lt;
|
|
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
return gt;
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
function sortEnabledMods()
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const dependencies = {};
|
|
|
|
|
for (const folder of g_ModsEnabled)
|
2026-07-27 03:23:43 -07:00
|
|
|
dependencies[folder] = getMod(folder).dependencies.map(d => d.split(regExpComparisonOperator)[0]);
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
|
|
|
|
g_ModsEnabled.sort((folder1, folder2) =>
|
2021-05-09 06:53:25 -07:00
|
|
|
dependencies[folder1].indexOf(getMod(folder2).name) != -1 ? 1 :
|
|
|
|
|
dependencies[folder2].indexOf(getMod(folder1).name) != -1 ? -1 : 0);
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
|
2021-03-21 03:22:50 -07:00
|
|
|
g_ModsEnabledFiltered = displayModList("modsEnabledList", g_ModsEnabled, true);
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
|
|
|
|
|
2018-04-14 13:04:17 -07:00
|
|
|
function selectedMod(listObjectName)
|
2014-08-25 09:02:54 -07:00
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const listObject = Engine.GetGUIObjectByName(listObjectName);
|
|
|
|
|
const isPickedDisabledList = listObjectName == "modsDisabledList";
|
|
|
|
|
const otherListObject = Engine.GetGUIObjectByName(isPickedDisabledList ?
|
2018-04-14 13:04:17 -07:00
|
|
|
"modsEnabledList" : "modsDisabledList");
|
|
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const toggleModButton = Engine.GetGUIObjectByName("toggleModButton");
|
|
|
|
|
const isModSelected = listObject.selected != -1;
|
2021-03-21 03:22:50 -07:00
|
|
|
if (isModSelected)
|
2018-04-14 13:04:17 -07:00
|
|
|
{
|
|
|
|
|
otherListObject.selected = -1;
|
2021-03-21 03:22:50 -07:00
|
|
|
toggleModButton.onPress = isPickedDisabledList ? enableMod : disableMod;
|
2018-04-14 13:04:17 -07:00
|
|
|
}
|
2014-08-25 09:02:54 -07:00
|
|
|
|
2021-06-02 10:45:17 -07:00
|
|
|
const isFiltering = Engine.GetGUIObjectByName("modGenericFilter").caption;
|
2021-03-21 03:22:50 -07:00
|
|
|
Engine.GetGUIObjectByName("visitWebButton").enabled = isModSelected && !!getSelectedModUrl();
|
|
|
|
|
toggleModButton.caption = isPickedDisabledList ?
|
2020-02-17 10:22:52 -08:00
|
|
|
translateWithContext("mod activation", "Enable") :
|
|
|
|
|
translateWithContext("mod activation", "Disable");
|
2021-05-20 10:11:26 -07:00
|
|
|
toggleModButton.enabled = isPickedDisabledList ? isModSelected && g_ModsCompatibility[listObject.list[listObject.selected]] || false : isModSelected;
|
2021-06-02 10:45:17 -07:00
|
|
|
Engine.GetGUIObjectByName("enabledModUp").enabled = isModSelected && listObjectName == "modsEnabledList" && !isFiltering;
|
|
|
|
|
Engine.GetGUIObjectByName("enabledModDown").enabled = isModSelected && listObjectName == "modsEnabledList" && !isFiltering;
|
2020-02-17 10:22:52 -08:00
|
|
|
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
Engine.GetGUIObjectByName("globalModDescription").caption =
|
|
|
|
|
listObject.list[listObject.selected] ?
|
2021-05-09 06:53:25 -07:00
|
|
|
getMod(listObject.list[listObject.selected]).description :
|
Cleanup mod selection GUI page.
Refactor functions and unify sort dropdown choices.
Move colors to globals so that they are easily modifiable, even from
external files, refs fd034c9bcd / D911.
Fix broken "Dependency not met" translation and wrong equal comparison
operator description (== vs =), refs 64bfa089af.
Use localeCompare, simpler loops and array functions, JSdoc syntax,
ternaries, deepfreeze, let keyword and prefix increment operator.
Renames to increase descriptiveness and consistency.
Remove duplication, tautologic and unsatisfiable conditions, dead code,
unused variables and GUI object names, example within example,
unneeded variables, parentheses, TODOs, strict checks and keep XML
element, misleading linebreaks, pointless comments and "Mods Loaded"
string and the switch fall-through.
This was SVN commit r20552.
2017-11-28 14:43:27 -08:00
|
|
|
'[color="' + g_ColorNoModSelected + '"]' + translate("No mod has been selected.") + '[/color]';
|
2021-05-09 06:53:25 -07:00
|
|
|
|
|
|
|
|
if (!g_ModsEnabled.length)
|
2021-05-26 06:27:43 -07:00
|
|
|
Engine.GetGUIObjectByName("message").caption = coloredText(translate('Enable at least 0ad mod'), g_ColorDependenciesNotMet);
|
2021-05-09 06:53:25 -07:00
|
|
|
if (!Engine.GetGUIObjectByName("startButton").hidden)
|
|
|
|
|
Engine.GetGUIObjectByName("startButton").enabled = g_ModsEnabled.length > 0;
|
|
|
|
|
|
2014-08-25 09:02:54 -07:00
|
|
|
}
|
2017-12-06 11:58:23 -08:00
|
|
|
|
2020-02-17 10:22:52 -08:00
|
|
|
/**
|
|
|
|
|
* @returns {string} The url of the currently selected mod.
|
|
|
|
|
*/
|
|
|
|
|
function getSelectedModUrl()
|
2017-12-06 11:58:23 -08:00
|
|
|
{
|
2025-05-06 04:49:01 -07:00
|
|
|
const modsEnabledList = Engine.GetGUIObjectByName("modsEnabledList");
|
|
|
|
|
const modsDisabledList = Engine.GetGUIObjectByName("modsDisabledList");
|
2018-04-14 13:04:17 -07:00
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const list = modsEnabledList.selected == -1 ? modsDisabledList : modsEnabledList;
|
|
|
|
|
const folder = list.list[list.selected];
|
2021-05-09 06:53:25 -07:00
|
|
|
return folder && getMod(folder) && getMod(folder).url || undefined;
|
2020-02-17 10:22:52 -08:00
|
|
|
}
|
2017-12-06 11:58:23 -08:00
|
|
|
|
2020-02-17 10:22:52 -08:00
|
|
|
function visitModWebsite()
|
|
|
|
|
{
|
|
|
|
|
let url = getSelectedModUrl();
|
2017-12-06 11:58:23 -08:00
|
|
|
if (!url)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!url.startsWith("http://") && !url.startsWith("https://"))
|
|
|
|
|
url = "http://" + url;
|
|
|
|
|
|
2018-09-22 09:23:43 -07:00
|
|
|
openURL(url);
|
2017-12-06 11:58:23 -08:00
|
|
|
}
|