Fix eslint rule 'prefer-const' in gui/[c-p]

eslint --no-config-lookup --fix --rule '"prefer-const": 1' \
    binaries/data/mods/public/gui/[c-p]*

Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser
2025-05-12 14:14:50 +02:00
parent e7f1406c37
commit c24bf321d6
23 changed files with 161 additions and 161 deletions
@@ -32,9 +32,9 @@ var g_TabButtonDist = 5;
function init()
{
// Load credits list from the disk and parse them
for (let category of g_OrderTabNames)
for (const category of g_OrderTabNames)
{
let json = Engine.ReadJSONFile("gui/credits/texts/" + category + ".json");
const json = Engine.ReadJSONFile("gui/credits/texts/" + category + ".json");
if (!json || !json.Content)
{
if (category == "translators")
@@ -70,7 +70,7 @@ function parseHelper(list)
{
let result = "";
for (let object of list)
for (const object of list)
{
if (object.LangName)
result += setStringTags(object.LangName + "\n", { "font": "sans-bold-stroke-14" });
@@ -83,7 +83,7 @@ function parseHelper(list)
if (object.List)
{
for (let element of object.List)
for (const element of object.List)
{
let credit;
if (element.nick && element.name)
@@ -51,7 +51,7 @@ async function init(attribs)
}
case "host":
{
let hasXmppClient = Engine.HasXmppClient();
const hasXmppClient = Engine.HasXmppClient();
Engine.GetGUIObjectByName("hostPasswordWrapper").hidden = !hasXmppClient;
if (hasXmppClient)
{
@@ -130,9 +130,9 @@ function confirmSetup(loadSavedGame)
{
if (!Engine.GetGUIObjectByName("pageJoin").hidden)
{
let joinPlayerName = Engine.GetGUIObjectByName("joinPlayerName").caption;
let joinServer = Engine.GetGUIObjectByName("joinServer").caption;
let joinPort = Engine.GetGUIObjectByName("joinPort").caption;
const joinPlayerName = Engine.GetGUIObjectByName("joinPlayerName").caption;
const joinServer = Engine.GetGUIObjectByName("joinServer").caption;
const joinPort = Engine.GetGUIObjectByName("joinPort").caption;
if (startJoin(joinPlayerName, joinServer, getValidPort(joinPort)))
{
@@ -144,14 +144,14 @@ function confirmSetup(loadSavedGame)
if (!Engine.GetGUIObjectByName("pageHost").hidden)
{
let hostServerName = Engine.GetGUIObjectByName("hostServerName").caption;
const hostServerName = Engine.GetGUIObjectByName("hostServerName").caption;
if (!hostServerName)
{
Engine.GetGUIObjectByName("hostFeedback").caption = translate("Please enter a valid server name.");
return false;
}
let hostPort = Engine.GetGUIObjectByName("hostPort").caption;
const hostPort = Engine.GetGUIObjectByName("hostPort").caption;
if (getValidPort(hostPort) != +hostPort)
{
Engine.GetGUIObjectByName("hostFeedback").caption = sprintf(
@@ -162,8 +162,8 @@ function confirmSetup(loadSavedGame)
return false;
}
let hostPlayerName = Engine.GetGUIObjectByName("hostPlayerName").caption;
let hostPassword = Engine.GetGUIObjectByName("hostPassword").caption;
const hostPlayerName = Engine.GetGUIObjectByName("hostPlayerName").caption;
const hostPassword = Engine.GetGUIObjectByName("hostPassword").caption;
if (startHost(hostPlayerName, hostServerName, getValidPort(hostPort), hostPassword,
loadSavedGame))
{
@@ -367,23 +367,23 @@ async function handleAuthenticated(message, loadSavedGame)
function switchSetupPage(newPage)
{
let multiplayerPages = Engine.GetGUIObjectByName("multiplayerPages");
for (let page of multiplayerPages.children)
const multiplayerPages = Engine.GetGUIObjectByName("multiplayerPages");
for (const page of multiplayerPages.children)
if (page.name.startsWith("page"))
page.hidden = true;
if (newPage == "pageJoin" || newPage == "pageHost")
{
let pageSize = multiplayerPages.size;
let halfHeight = newPage == "pageJoin" ? 145 : Engine.HasXmppClient() ? 140 : 125;
const pageSize = multiplayerPages.size;
const halfHeight = newPage == "pageJoin" ? 145 : Engine.HasXmppClient() ? 140 : 125;
pageSize.top = -halfHeight;
pageSize.bottom = halfHeight;
multiplayerPages.size = pageSize;
}
else if (newPage == "pagePassword")
{
let pageSize = multiplayerPages.size;
let halfHeight = 60;
const pageSize = multiplayerPages.size;
const halfHeight = 60;
pageSize.top = -halfHeight;
pageSize.bottom = halfHeight;
multiplayerPages.size = pageSize;
@@ -405,7 +405,7 @@ function startHost(playername, servername, port, password, loadSavedGame)
Engine.ConfigDB_CreateValue("user", "multiplayerhosting.port", port);
Engine.ConfigDB_SaveChanges("user");
let hostFeedback = Engine.GetGUIObjectByName("hostFeedback");
const hostFeedback = Engine.GetGUIObjectByName("hostFeedback");
// Disallow identically named games in the multiplayer lobby
if (Engine.HasXmppClient() &&
@@ -14,30 +14,30 @@ class HotkeyMetadata
parseSpec()
{
let files = this.getFiles();
const files = this.getFiles();
let hotkey_i = 0;
let categories = {
const categories = {
[this.DEFAULT_CATEGORY]: {
"name": translate(this.DefaultCategoryString),
"desc": translate(this.DefaultCategoryString),
}
};
for (let file of files)
for (const file of files)
{
let data = Engine.ReadJSONFile(file);
const data = Engine.ReadJSONFile(file);
if (data.categories)
for (let cat in data.categories)
for (const cat in data.categories)
categories[cat] = data.categories[cat];
if (data.hotkeys)
for (let hotkey in data.hotkeys)
for (const hotkey in data.hotkeys)
{
this.hotkeys[hotkey] = data.hotkeys[hotkey];
this.hotkeys[hotkey].order = hotkey_i++;
this.hotkeys[hotkey].categories = data.hotkeys[hotkey].categories || [this.DEFAULT_CATEGORY];
}
if (data.mapped_hotkeys)
for (let cat in data.mapped_hotkeys)
for (let hotkey in data.mapped_hotkeys[cat])
for (const cat in data.mapped_hotkeys)
for (const hotkey in data.mapped_hotkeys[cat])
{
if (data.mapped_hotkeys[cat][hotkey].categories)
warn("Categories will be overwritten for mapped hotkey " + hotkey);
@@ -48,14 +48,14 @@ class HotkeyMetadata
}
// Sort categories (JS objects are (in this case) sorted by insertion order).
this.categories = {};
let keys = Object.keys(categories).sort((a, b) => {
const keys = Object.keys(categories).sort((a, b) => {
if (a === this.DEFAULT_CATEGORY || b === this.DEFAULT_CATEGORY)
return a === this.DEFAULT_CATEGORY ? 1 : -1;
if (categories[a].order === undefined || categories[b].order === undefined)
return categories[a].order === undefined ? -1 : 1; // Likely to keep alphabetical order.
return categories[a].order - categories[b].order;
});
for (let key of keys)
for (const key of keys)
this.categories[key] = categories[key];
// TODO: validate that categories exist.
}
@@ -32,7 +32,7 @@ class HotkeyPicker
// This is a bit "using a bazooka to kill a fly"
Engine.ConfigDB_RemoveValueAndSave("user", "hotkey." + this.name);
Engine.ReloadHotkeys();
let data = Engine.GetHotkeyMap();
const data = Engine.GetHotkeyMap();
this.combinations = data[this.name];
this.setupCombinations();
this.render();
@@ -49,7 +49,7 @@ class HotkeyPicker
{
for (let i = 0; i < 4; ++i)
{
let s = Engine.GetGUIObjectByName("combination[" + i + "]").size;
const s = Engine.GetGUIObjectByName("combination[" + i + "]").size;
s.top = +i * 60 + 120;
s.bottom = +i * 60 + 150;
Engine.GetGUIObjectByName("combination[" + i + "]").size = s;
@@ -58,9 +58,9 @@ class HotkeyPicker
if (i == this.combinations.length)
this.combinations.push([]);
let input = Engine.GetGUIObjectByName("combMapping[" + i + "]");
const input = Engine.GetGUIObjectByName("combMapping[" + i + "]");
let picker = Engine.GetGUIObjectByName("picker[" + i + "]");
const picker = Engine.GetGUIObjectByName("picker[" + i + "]");
Engine.GetGUIObjectByName("combMappingBtn[" + i + "]").onPress = () => {
this.enteringInput = i;
picker.focus();
@@ -99,7 +99,7 @@ class HotkeyPicker
{
for (let i = 0; i < 4; ++i)
{
let input = Engine.GetGUIObjectByName("combMapping[" + i + "]");
const input = Engine.GetGUIObjectByName("combMapping[" + i + "]");
if (i == this.enteringInput)
input.caption = translate("Enter new Hotkey, hold to register.");
else
@@ -108,7 +108,7 @@ class HotkeyPicker
Engine.GetGUIObjectByName("deleteComb[" + i + "]").hidden = !this.combinations[i].length;
let conflicts = (Engine.GetConflicts(this.combinations[i]) || [])
const conflicts = (Engine.GetConflicts(this.combinations[i]) || [])
.filter(name => name != this.name).map(translate);
if (conflicts.length)
Engine.GetGUIObjectByName("conflicts[" + i + "]").caption =
@@ -5,8 +5,8 @@ class HotkeysPage
this.metadata = metadata;
Engine.GetGUIObjectByName("hotkeyList").onMouseLeftDoubleClickItem = () => {
let idx = Engine.GetGUIObjectByName("hotkeyList").selected;
let picker = new HotkeyPicker(
const idx = Engine.GetGUIObjectByName("hotkeyList").selected;
const picker = new HotkeyPicker(
this.metadata,
this.onHotkeyPicked.bind(this),
Engine.GetGUIObjectByName("hotkeyList").list_data[idx],
@@ -37,30 +37,30 @@ class HotkeysPage
setupHotkeyData()
{
let hotkeydata = Engine.GetHotkeyMap();
const hotkeydata = Engine.GetHotkeyMap();
this.hotkeys = hotkeydata;
let categories = clone(this.metadata.categories);
for (let name in categories)
const categories = clone(this.metadata.categories);
for (const name in categories)
categories[name].hotkeys = [];
// Add hotkeys defined in the metadata but not in the C++ map.
for (let hotkeyName in this.metadata.hotkeys)
for (const hotkeyName in this.metadata.hotkeys)
if (!this.hotkeys[hotkeyName])
this.hotkeys[hotkeyName] = [];
for (let hotkeyName in this.hotkeys)
for (const hotkeyName in this.hotkeys)
{
if (this.metadata.hotkeys[hotkeyName])
for (let cat of this.metadata.hotkeys[hotkeyName].categories)
for (const cat of this.metadata.hotkeys[hotkeyName].categories)
categories[cat].hotkeys.push(hotkeyName);
else
categories[this.metadata.DEFAULT_CATEGORY].hotkeys.push(hotkeyName);
}
for (let cat in categories)
for (const cat in categories)
categories[cat].hotkeys.sort((a, b) => {
if (!this.metadata.hotkeys[a] || !this.metadata.hotkeys[b])
return !this.metadata.hotkeys[a] ? 1 : -1;
return this.metadata.hotkeys[a].order - this.metadata.hotkeys[b].order;
});
for (let cat in categories)
for (const cat in categories)
if (categories[cat].hotkeys.length === 0)
delete categories[cat];
this.categories = categories;
@@ -68,9 +68,9 @@ class HotkeysPage
setupFilters()
{
let dropdown = Engine.GetGUIObjectByName("hotkeyFilter");
let names = [];
for (let cat in this.categories)
const dropdown = Engine.GetGUIObjectByName("hotkeyFilter");
const names = [];
for (const cat in this.categories)
names.push(translateWithContext("hotkey metadata", this.categories[cat].name));
dropdown.list = [translate("All Hotkeys")].concat(names);
dropdown.list_data = [-1].concat(Object.keys(this.categories));
@@ -79,12 +79,12 @@ class HotkeysPage
setupHotkeyList()
{
let hotkeyList = Engine.GetGUIObjectByName("hotkeyList");
const hotkeyList = Engine.GetGUIObjectByName("hotkeyList");
hotkeyList.selected = -1;
let textFilter = Engine.GetGUIObjectByName("hotkeyTextFilter").caption.toLowerCase();
const textFilter = Engine.GetGUIObjectByName("hotkeyTextFilter").caption.toLowerCase();
let hotkeys;
let dropdown = Engine.GetGUIObjectByName("hotkeyFilter");
const dropdown = Engine.GetGUIObjectByName("hotkeyFilter");
if (dropdown.selected && dropdown.selected !== 0)
hotkeys = this.categories[dropdown.list_data[dropdown.selected]].hotkeys;
else
@@ -102,7 +102,7 @@ class HotkeysPage
onFilterHover()
{
let dropdown = Engine.GetGUIObjectByName("hotkeyFilter");
const dropdown = Engine.GetGUIObjectByName("hotkeyFilter");
if (dropdown.hovered === -1)
dropdown.tooltip = "";
else if (dropdown.hovered === 0)
@@ -113,12 +113,12 @@ class HotkeysPage
onHotkeyHover()
{
let hotkeyList = Engine.GetGUIObjectByName("hotkeyList");
const hotkeyList = Engine.GetGUIObjectByName("hotkeyList");
if (hotkeyList.hovered === -1)
hotkeyList.tooltip = "";
else
{
let hotkey = hotkeyList.list_data[hotkeyList.hovered];
const hotkey = hotkeyList.list_data[hotkeyList.hovered];
hotkeyList.tooltip = this.metadata.hotkeys[hotkey]?.desc ?
translateWithContext("hotkey metadata", this.metadata.hotkeys[hotkey]?.desc) :
translate(this.UnavailableTooltipString);
@@ -163,13 +163,13 @@ class HotkeysPage
saveUserHotkeys()
{
for (let hotkey in this.hotkeys)
for (const hotkey in this.hotkeys)
Engine.ConfigDB_RemoveValue("user", "hotkey." + hotkey);
Engine.ReloadHotkeys();
let defaultData = Engine.GetHotkeyMap();
for (let hotkey in this.hotkeys)
const defaultData = Engine.GetHotkeyMap();
for (const hotkey in this.hotkeys)
{
let keymap = formatHotkeyCombinations(this.hotkeys[hotkey], false);
const keymap = formatHotkeyCombinations(this.hotkeys[hotkey], false);
if (keymap.join("") !== formatHotkeyCombinations(defaultData[hotkey], false).join(""))
Engine.ConfigDB_CreateValues("user", "hotkey." + hotkey, keymap);
}
@@ -59,7 +59,7 @@ class SavegameDeleter
if (!Engine.DeleteSavedGame(gameID))
error("Could not delete saved game: " + gameID);
for (let handler of this.savegameListChangeHandlers)
for (const handler of this.savegameListChangeHandlers)
handler.onSavegameListChange();
}
}
@@ -31,15 +31,15 @@ class SavegameList
initSavegameList()
{
let engineInfo = Engine.GetEngineInfo();
const engineInfo = Engine.GetEngineInfo();
this.gameSelection.onSelectionColumnChange = () => { this.updateSavegameList(); };
this.gameSelection.onMouseLeftDoubleClickItem = () => { this.confirmButton.onPress(); };
this.gameSelection.onSelectionChange = () => {
let gameId = this.gameSelection.list_data[this.gameSelection.selected];
let metadata = this.savedGamesMetadata[this.gameSelection.selected];
let label = this.generateSavegameLabel(metadata, engineInfo);
for (let handler of this.selectionChangeHandlers)
const gameId = this.gameSelection.list_data[this.gameSelection.selected];
const metadata = this.savedGamesMetadata[this.gameSelection.selected];
const label = this.generateSavegameLabel(metadata, engineInfo);
for (const handler of this.selectionChangeHandlers)
handler.onSelectionChange(gameId, metadata, label);
};
@@ -71,7 +71,7 @@ class SavegameList
let savedGames = Engine.GetSavedGames();
// Get current game version and loaded mods
let engineInfo = Engine.GetEngineInfo();
const engineInfo = Engine.GetEngineInfo();
if (this.compatibilityFilter.checked)
savedGames = savedGames.filter(game => {
@@ -85,7 +85,7 @@ class SavegameList
this.gameSelection.enabled = !!savedGames.length;
this.gameSelectionFeedback.hidden = !!savedGames.length;
let selectedGameId = this.gameSelection.list_data[this.gameSelection.selected];
const selectedGameId = this.gameSelection.list_data[this.gameSelection.selected];
// Save metadata for the detailed view
this.savedGamesMetadata = savedGames.map(game => {
@@ -93,8 +93,8 @@ class SavegameList
return game.metadata;
});
let sortKey = this.gameSelection.selected_column;
let sortOrder = this.gameSelection.selected_column_order;
const sortKey = this.gameSelection.selected_column;
const sortOrder = this.gameSelection.selected_column_order;
this.savedGamesMetadata = this.savedGamesMetadata.sort((a, b) => {
let cmpA, cmpB;
@@ -127,7 +127,7 @@ class SavegameList
});
let list = this.savedGamesMetadata.map(metadata => {
let isCompatible = this.isCompatibleSavegame(metadata, engineInfo) &&
const isCompatible = this.isCompatibleSavegame(metadata, engineInfo) &&
this.campaignFilter(metadata, this.campaignRun);
// Backwards compatibility for pre-A25 savegames
const mapName = metadata.initAttributes.settings?.mapName ?? metadata.initAttributes.settings.Name;
@@ -153,7 +153,7 @@ class SavegameList
// Restore selection if the selected savegame still exists.
// If the last savegame was deleted, or if it was hidden by the compatibility filter, select the new last item.
let selectedGameIndex = this.savedGamesMetadata.findIndex(metadata => metadata.id == selectedGameId);
const selectedGameIndex = this.savedGamesMetadata.findIndex(metadata => metadata.id == selectedGameId);
if (selectedGameIndex != -1)
this.gameSelection.selected = selectedGameIndex;
else if (this.gameSelection.selected >= this.savedGamesMetadata.length)
@@ -22,9 +22,9 @@ class SavegameLoader
async loadGame(gameId, metadata)
{
// Check compatibility before really loading it
let engineInfo = Engine.GetEngineInfo();
let sameMods = hasSameMods(metadata.mods, engineInfo.mods);
let sameEngineVersion = metadata.engine_version && metadata.engine_version == engineInfo.engine_version;
const engineInfo = Engine.GetEngineInfo();
const sameMods = hasSameMods(metadata.mods, engineInfo.mods);
const sameEngineVersion = metadata.engine_version && metadata.engine_version == engineInfo.engine_version;
if (sameEngineVersion && sameMods)
{
@@ -20,7 +20,7 @@ class SavegamePage
{
this.savegameWriter = new SavegameWriter(closePageCallback, data.savedGameData);
this.savegameList.registerSelectionChangeHandler(this.savegameWriter);
let size = this.savegameList.gameSelection.size;
const size = this.savegameList.gameSelection.size;
size.bottom -= 24;
this.savegameList.gameSelection.size = size;
}
@@ -9,7 +9,7 @@ class SavegameWriter
this.closePageCallback = closePageCallback;
this.savedGameData = savedGameData;
let saveNew = () => {
const saveNew = () => {
this.saveGame();
};
@@ -37,8 +37,8 @@ class SavegameWriter
async saveGame(gameID, label)
{
let desc = this.saveGameDesc.caption;
let name = gameID || "savegame";
const desc = this.saveGameDesc.caption;
const name = gameID || "savegame";
if (gameID)
{
@@ -53,7 +53,7 @@ class SavegameWriter
return;
}
let simulationState = Engine.GuiInterfaceCall("GetSimulationState");
const simulationState = Engine.GuiInterfaceCall("GetSimulationState");
this.savedGameData.timeElapsed = simulationState.timeElapsed;
this.savedGameData.states = simulationState.players.map(pState => pState.state);
@@ -25,7 +25,7 @@ class ProgressBar
return;
// Show 100 when it is really 99
let progress = progression + 1;
const progress = progression + 1;
this.progressbar.progress = progress;
if (this.showDescription)
@@ -36,8 +36,8 @@ class ProgressBar
this.progressText.caption = sprintf(this.CaptionFormat, this.percentArgs);
}
let increment = Math.round(progress * this.progressBarSize / 100);
let size = this.progressbar_right.size;
const increment = Math.round(progress * this.progressBarSize / 100);
const size = this.progressbar_right.size;
size.left = increment;
size.right = increment + this.progressbar_right_width;
this.progressbar_right.size = size;
@@ -5,7 +5,7 @@ class TitleDisplay
{
constructor(data)
{
let loadingMapName = Engine.GetGUIObjectByName("loadingMapName");
const loadingMapName = Engine.GetGUIObjectByName("loadingMapName");
loadingMapName.caption = sprintf(
data.attribs.mapType == "random" ? this.Generating : this.Loading,
{ "map": translate(data.attribs.settings.mapName) });
@@ -45,7 +45,7 @@ function languageSelectionChanged()
async function openAdvancedMenu()
{
let localeText = Engine.GetGUIObjectByName("localeText");
const localeText = Engine.GetGUIObjectByName("localeText");
const locale = await Engine.OpenChildPage("page_locale_advanced.xml", { "locale": localeText.caption });
if (!locale)
@@ -1,17 +1,17 @@
function init(initData)
{
let languageList = Engine.GetGUIObjectByName("languageList");
let countryList = Engine.GetGUIObjectByName("countryList");
let resultingLocaleText = Engine.GetGUIObjectByName("resultingLocale");
let scriptInput = Engine.GetGUIObjectByName("scriptInput");
const languageList = Engine.GetGUIObjectByName("languageList");
const countryList = Engine.GetGUIObjectByName("countryList");
const resultingLocaleText = Engine.GetGUIObjectByName("resultingLocale");
const scriptInput = Engine.GetGUIObjectByName("scriptInput");
// get languageList data. Only list languages for which we have a dictionary.
let languageListData = [];
let languageListTmp = Engine.GetSupportedLocaleBaseNames();
let currentLocaleLanguage = Engine.GetLocaleLanguage(initData.locale);
const languageListData = [];
const languageListTmp = Engine.GetSupportedLocaleBaseNames();
const currentLocaleLanguage = Engine.GetLocaleLanguage(initData.locale);
for (let i = 0; i < languageListTmp.length; ++i)
{
let lang = Engine.GetLocaleLanguage(languageListTmp[i]);
const lang = Engine.GetLocaleLanguage(languageListTmp[i]);
if (lang != "" && languageListData.indexOf(lang) == -1)
languageListData.push(lang);
}
@@ -23,7 +23,7 @@ function init(initData)
var currentLocaleCountry = Engine.GetLocaleCountry(initData.locale);
for (let i = 0; i < countryListTmp.length; ++i)
{
let country = Engine.GetLocaleCountry(countryListTmp[i]);
const country = Engine.GetLocaleCountry(countryListTmp[i]);
if (country != "" && countryListData.indexOf(country) == -1)
countryListData.push(country);
}
@@ -78,11 +78,11 @@ function updateResultingLocale()
if (countryList.selected != -1 && countryList.list_data[countryList.selected] != translateWithContext("localeCountry", "None"))
resultingLocaleTmp = resultingLocaleTmp + "_" + countryList.list_data[countryList.selected];
let acceptButton = Engine.GetGUIObjectByName("acceptButton");
const acceptButton = Engine.GetGUIObjectByName("acceptButton");
if (Engine.ValidateLocale(resultingLocaleTmp))
{
resultingLocaleText.caption = resultingLocaleTmp;
let dictionaryFileList = Engine.GetDictionariesForLocale(Engine.GetDictionaryLocale(resultingLocaleTmp));
const dictionaryFileList = Engine.GetDictionariesForLocale(Engine.GetDictionaryLocale(resultingLocaleTmp));
let dictionaryFileString = "";
dictionaryFileList.forEach(entry => { dictionaryFileString = dictionaryFileString + entry + "\n"; });
dictionaryFile.caption = dictionaryFileString;
@@ -1,9 +1,9 @@
function init()
{
let mainText = Engine.GetGUIObjectByName("mainText");
let text = Engine.TranslateLines(Engine.ReadFile("gui/manual/intro.txt"));
const mainText = Engine.GetGUIObjectByName("mainText");
const text = Engine.TranslateLines(Engine.ReadFile("gui/manual/intro.txt"));
let hotkeys = Engine.GetHotkeyMap();
const hotkeys = Engine.GetHotkeyMap();
// Replace anything starting with 'hotkey.' with its hotkey.
mainText.caption = text.replace(/hotkey\.([a-z0-9_\.]+)/g, (_, k) => formatHotkeyCombinations(hotkeys[k]));
@@ -93,8 +93,8 @@ var g_OptionType = {
"guiToValue": control => control.caption,
"guiSetter": "onTextEdit",
"sanitizeValue": (value, control, option) => {
let color = guiToRgbColor(value);
let sanitized = rgbToGuiColor(color);
const color = guiToRgbColor(value);
const sanitized = rgbToGuiColor(color);
if (control)
{
control.sprite = sanitized == value ? "ModernDarkBoxWhite" : "ModernDarkBoxWhiteInvalid";
@@ -116,7 +116,7 @@ var g_OptionType = {
"guiToValue": control => control.caption,
"guiSetter": "onTextEdit",
"sanitizeValue": (value, control, option) => {
let sanitized =
const sanitized =
Math.min(option.max !== undefined ? option.max : +Infinity,
Math.max(option.min !== undefined ? option.min : -Infinity,
isNaN(+value) ? 0 : value));
@@ -152,7 +152,7 @@ var g_OptionType = {
control.list = option.list.map(e => e.label);
control.list_data = option.list.map(e => e.value);
control.onHoverChange = () => {
let item = option.list[control.hovered];
const item = option.list[control.hovered];
control.tooltip = item && item.tooltip || option.tooltip;
};
}
@@ -248,10 +248,10 @@ function getHotloadData()
function displayOptions()
{
// Hide all controls
for (let body of Engine.GetGUIObjectByName("option_controls").children)
for (const body of Engine.GetGUIObjectByName("option_controls").children)
{
body.hidden = true;
for (let control of body.children)
for (const control of body.children)
control.hidden = true;
}
@@ -259,20 +259,20 @@ function displayOptions()
for (let i = 0; i < g_Options[g_TabCategorySelected].options.length; ++i)
{
// Position vertically
let body = Engine.GetGUIObjectByName("option_control[" + i + "]");
let bodySize = body.size;
const body = Engine.GetGUIObjectByName("option_control[" + i + "]");
const bodySize = body.size;
bodySize.top = g_OptionControlOffset + i * (g_OptionControlHeight + g_OptionControlDist);
bodySize.bottom = bodySize.top + g_OptionControlHeight;
body.size = bodySize;
body.hidden = false;
// Load option data
let option = g_Options[g_TabCategorySelected].options[i];
let optionType = g_OptionType[option.type];
let value = optionType.configToValue(Engine.ConfigDB_GetValue("user", option.config));
const option = g_Options[g_TabCategorySelected].options[i];
const optionType = g_OptionType[option.type];
const value = optionType.configToValue(Engine.ConfigDB_GetValue("user", option.config));
// Setup control
let control = Engine.GetGUIObjectByName("option_control_" + option.type + "[" + i + "]");
const control = Engine.GetGUIObjectByName("option_control_" + option.type + "[" + i + "]");
control.tooltip = option.tooltip + (optionType.tooltip ? "\n" + optionType.tooltip(value, option) : "");
control.hidden = false;
@@ -286,7 +286,7 @@ function displayOptions()
control[optionType.guiSetter] = function() {
let value = optionType.guiToValue(control);
const value = optionType.guiToValue(control);
if (optionType.sanitizeValue)
optionType.sanitizeValue(value, control, option);
@@ -311,12 +311,12 @@ function displayOptions()
};
// Setup label
let label = Engine.GetGUIObjectByName("option_label[" + i + "]");
const label = Engine.GetGUIObjectByName("option_label[" + i + "]");
label.caption = option.label;
label.tooltip = option.tooltip;
label.hidden = false;
let labelSize = label.size;
const labelSize = label.size;
labelSize.left = option.dependencies ? g_DependentLabelIndentation : 0;
labelSize.rright = control.size.rleft;
label.size = labelSize;
@@ -373,8 +373,8 @@ async function setDefaults()
if (buttonIndex === 0)
return;
for (let category in g_Options)
for (let option of g_Options[category].options)
for (const category in g_Options)
for (const option of g_Options[category].options)
{
Engine.ConfigDB_RemoveValue("user", option.config);
g_ChangedKeys.add(option.config);
@@ -401,8 +401,8 @@ function revertChanges()
{
Engine.ConfigDB_Reload("user");
for (let category in g_Options)
for (let option of g_Options[category].options)
for (const category in g_Options)
for (const option of g_Options[category].options)
if (option.function)
Engine[option.function](
g_OptionType[option.type].configToValue(
@@ -415,11 +415,11 @@ async function saveChanges()
{
const category = Object.keys(g_Options).find(key => {
return g_Options[key].options.some(option => {
let optionType = g_OptionType[option.type];
const optionType = g_OptionType[option.type];
if (!optionType.sanitizeValue)
return false;
let value = optionType.configToValue(Engine.ConfigDB_GetValue("user", option.config));
const value = optionType.configToValue(Engine.ConfigDB_GetValue("user", option.config));
return value != optionType.sanitizeValue(value, undefined, option);
});
});
@@ -15,14 +15,14 @@ class BackgroundHandler
onWindowResized()
{
let size = this.backgrounds.getComputedSize();
const size = this.backgrounds.getComputedSize();
this.backgroundsSize = deepfreeze(new GUISize(size.top, size.left, size.right, size.bottom));
}
onTick()
{
let time = Date.now() - this.initTime;
for (let background of this.backgroundLayers)
const time = Date.now() - this.initTime;
for (const background of this.backgroundLayers)
background.update(time, this.backgroundsSize);
}
}
@@ -41,13 +41,13 @@ class BackgroundLayer
update(time, backgroundsSize)
{
let height = backgroundsSize.bottom - backgroundsSize.top;
let width = height * this.AspectRatio;
let offset = this.layer.offset(time / 1000, width);
const height = backgroundsSize.bottom - backgroundsSize.top;
const width = height * this.AspectRatio;
const offset = this.layer.offset(time / 1000, width);
if (this.layer.tiling)
{
let iw = height * 2;
const iw = height * 2;
let left = offset % iw;
if (left >= 0)
left -= iw;
@@ -59,7 +59,7 @@ class BackgroundLayer
}
else
{
let right = backgroundsSize.right / 2 + offset;
const right = backgroundsSize.right / 2 + offset;
this.background.size = new GUISize(
right - height,
backgroundsSize.top,
@@ -28,7 +28,7 @@ class MainMenuItemHandler
setupMenuButtons(buttons, menuItems)
{
buttons.forEach((button, i) => {
let item = menuItems[i];
const item = menuItems[i];
button.hidden = !item;
if (button.hidden)
return;
@@ -82,9 +82,9 @@ class MainMenuItemHandler
setupHotkeys(menuItems)
{
for (let i in menuItems)
for (const i in menuItems)
{
let item = menuItems[i];
const item = menuItems[i];
if (item.onPress && item.hotkey)
Engine.SetGlobalHotkey(item.hotkey, "Press", () => {
this.closeSubmenu();
@@ -100,7 +100,7 @@ class MainMenuItemHandler
{
this.setupMenuButtons(this.submenuButtons.children, this.menuItems[i].submenu);
let top = this.mainMenuButtons.children[i].getComputedSize().top;
const top = this.mainMenuButtons.children[i].getComputedSize().top;
this.submenu.size = new GUISize(
this.submenu.size.left, top - this.Margin,
@@ -109,14 +109,14 @@ class MainMenuItemHandler
this.submenu.hidden = false;
{
let size = this.MainMenuPanelRightBorderTop.size;
const size = this.MainMenuPanelRightBorderTop.size;
size.bottom = this.submenu.size.top + this.Margin;
size.rbottom = 0;
this.MainMenuPanelRightBorderTop.size = size;
}
{
let size = this.MainMenuPanelRightBorderBottom.size;
const size = this.MainMenuPanelRightBorderBottom.size;
size.top = this.submenu.size.bottom;
this.MainMenuPanelRightBorderBottom.size = size;
}
@@ -131,7 +131,7 @@ class MainMenuItemHandler
this.submenu.hidden = true;
this.submenu.size = this.mainMenu.size;
let size = this.MainMenuPanelRightBorderTop.size;
const size = this.MainMenuPanelRightBorderTop.size;
size.top = 0;
size.bottom = 0;
size.rbottom = 100;
@@ -140,12 +140,12 @@ class MainMenuItemHandler
onTick()
{
let now = Date.now();
const now = Date.now();
if (now == this.lastTickTime)
return;
let maxOffset = this.mainMenu.size.right - this.submenu.size.left;
let offset = Math.min(this.MenuSpeed * (now - this.lastTickTime), maxOffset);
const maxOffset = this.mainMenu.size.right - this.submenu.size.left;
const offset = Math.min(this.MenuSpeed * (now - this.lastTickTime), maxOffset);
this.lastTickTime = now;
@@ -155,7 +155,7 @@ class MainMenuItemHandler
return;
}
let size = this.submenu.size;
const size = this.submenu.size;
size.left += offset;
size.right += offset;
this.submenu.size = size;
@@ -36,8 +36,8 @@ class ProjectInformationHandler
{
constructor(projectInformation)
{
for (let objectName in projectInformation)
for (let propertyName in projectInformation[objectName])
for (const objectName in projectInformation)
for (const propertyName in projectInformation[objectName])
Engine.GetGUIObjectByName(objectName)[propertyName] = projectInformation[objectName][propertyName];
}
}
@@ -46,12 +46,12 @@ class CommunityButtonHandler
{
constructor(communityButtons)
{
let buttons = Engine.GetGUIObjectByName("communityButtons").children;
const buttons = Engine.GetGUIObjectByName("communityButtons").children;
communityButtons.forEach((buttonInfo, i) => {
let button = buttons[i];
const button = buttons[i];
button.hidden = false;
for (let propertyName in buttonInfo)
for (const propertyName in buttonInfo)
button[propertyName] = buttonInfo[propertyName];
});
@@ -55,9 +55,9 @@ function setUserReportEnabled(enabled)
function updateUserReportButtons()
{
let termsFeedback = checkTerms();
const termsFeedback = checkTerms();
let userReportEnableButton = Engine.GetGUIObjectByName("userReportEnableButton");
const userReportEnableButton = Engine.GetGUIObjectByName("userReportEnableButton");
userReportEnableButton.caption = Engine.IsUserReportEnabled() ? translate("Disable Feedback") : translate("Enable Feedback");
userReportEnableButton.enabled = !termsFeedback;
userReportEnableButton.tooltip = termsFeedback;
@@ -65,7 +65,7 @@ function updateUserReportButtons()
setUserReportEnabled(!Engine.IsUserReportEnabled());
};
let userReportTermsButton = Engine.GetGUIObjectByName("userReportTermsButton");
const userReportTermsButton = Engine.GetGUIObjectByName("userReportTermsButton");
userReportTermsButton.caption = g_TermsUserReport.TermsAndConditions.title;
userReportTermsButton.onPress = () => {
openTerms("TermsAndConditions");
@@ -74,7 +74,7 @@ function updateUserReportButtons()
function updateUserReportStatus()
{
let statusData = Engine.GetUserReportStatus().split(":");
const statusData = Engine.GetUserReportStatus().split(":");
Engine.GetGUIObjectByName("userReportText").caption =
Engine.IsUserReportEnabled() ?
@@ -1,6 +1,6 @@
function checkUsername(register)
{
let username = Engine.GetGUIObjectByName("username").caption;
const username = Engine.GetGUIObjectByName("username").caption;
if (!username)
return translate("Please enter your username");
@@ -12,7 +12,7 @@ function checkUsername(register)
function checkPassword(register)
{
let password = Engine.GetGUIObjectByName("password").caption;
const password = Engine.GetGUIObjectByName("password").caption;
if (!password)
return register ?
@@ -27,11 +27,11 @@ function checkPassword(register)
function checkPasswordConfirmation()
{
let password1 = Engine.GetGUIObjectByName("password").caption;
const password1 = Engine.GetGUIObjectByName("password").caption;
if (!password1)
return translate("Please enter your password again");
let password2 = Engine.GetGUIObjectByName("passwordRepeat").caption;
const password2 = Engine.GetGUIObjectByName("passwordRepeat").caption;
if (password1 != password2)
return translate("Passwords do not match");
@@ -46,8 +46,8 @@ function initRememberPassword()
async function toggleRememberPassword()
{
let checkbox = Engine.GetGUIObjectByName("rememberPassword");
let enabled = Engine.ConfigDB_GetValue("user", "lobby.rememberpassword") == "true";
const checkbox = Engine.GetGUIObjectByName("rememberPassword");
const enabled = Engine.ConfigDB_GetValue("user", "lobby.rememberpassword") == "true";
if (!checkbox.checked && enabled && Engine.ConfigDB_GetValue("user", "lobby.password"))
{
const buttonIndex = await messageBox(
@@ -68,8 +68,8 @@ async function toggleRememberPassword()
function getEncryptedPassword()
{
let typedUnencryptedPassword = Engine.GetGUIObjectByName("password").caption;
let storedEncryptedPassword = Engine.ConfigDB_GetValue("user", "lobby.password");
const typedUnencryptedPassword = Engine.GetGUIObjectByName("password").caption;
const storedEncryptedPassword = Engine.ConfigDB_GetValue("user", "lobby.password");
if (typedUnencryptedPassword == storedEncryptedPassword.substr(0, 10))
return storedEncryptedPassword;
@@ -81,7 +81,7 @@ function getEncryptedPassword()
function saveCredentials()
{
let username = Engine.GetGUIObjectByName("username").caption;
const username = Engine.GetGUIObjectByName("username").caption;
Engine.ConfigDB_CreateValue("user", "playername.multiplayer", username);
Engine.ConfigDB_CreateValue("user", "lobby.login", username);
@@ -17,11 +17,11 @@ var g_LobbyMessages = {
*/
function onTick()
{
let messages = Engine.LobbyGuiPollNewMessages();
const messages = Engine.LobbyGuiPollNewMessages();
if (!messages)
return;
for (let message of messages)
for (const message of messages)
{
if (message.type == "system" && message.level)
g_LobbyMessages[message.level](message);
@@ -2,9 +2,9 @@ var g_TermsButtonHeight = 38;
function initLobbyTerms()
{
let termsURL = Engine.ConfigDB_GetValue("user", "lobby.terms_url");
const termsURL = Engine.ConfigDB_GetValue("user", "lobby.terms_url");
let terms = {
const terms = {
"Service": {
"title": translate("Terms of Service"),
"instruction": translate("Please read and accept the Terms of Service."),
@@ -39,7 +39,7 @@ function initLobbyTerms()
Object.keys(terms).forEach((page, i) => {
let button = Engine.GetGUIObjectByName("termsButton[" + i + "]");
const button = Engine.GetGUIObjectByName("termsButton[" + i + "]");
button.caption = terms[page].title;
@@ -47,7 +47,7 @@ function initLobbyTerms()
openTerms(page);
};
let size = button.size;
const size = button.size;
size.top = i * g_TermsButtonHeight;
size.bottom = i * g_TermsButtonHeight + 28;
button.size = size;