Fix eslint rule 'prefer-const' in gamesettings

eslint --no-config-lookup --fix --rule '"prefer-const": 1' \
    binaries/data/mods/public/gamesettings

Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2025-05-05 19:34:12 +02:00
parent bc5f42d4a4
commit dc16f1ce82
No known key found for this signature in database
16 changed files with 52 additions and 52 deletions

View file

@ -13,7 +13,7 @@ class GameSetting extends Observable /* ProfilableMixin(Observable) /* Replace t
getDefaultValue(settingsProp, dataProp)
{
for (let index in g_Settings[settingsProp])
for (const index in g_Settings[settingsProp])
if (g_Settings[settingsProp][index].Default)
return g_Settings[settingsProp][index][dataProp];
return undefined;

View file

@ -33,14 +33,14 @@ class GameSettings
});
// Load attributes as regular enumerable (i.e. iterable) properties.
for (let comp in GameSettings.prototype.Attributes)
for (const comp in GameSettings.prototype.Attributes)
{
let name = comp[0].toLowerCase() + comp.substr(1);
const name = comp[0].toLowerCase() + comp.substr(1);
if (name in this)
error("Game Settings attribute '" + name + "' is already used.");
this[name] = new GameSettings.prototype.Attributes[comp](this);
}
for (let comp in this)
for (const comp in this)
if (this[comp].init)
this[comp].init();
@ -64,10 +64,10 @@ class GameSettings
*/
toInitAttributes()
{
let attribs = {
const attribs = {
"settings": {}
};
for (let comp in this)
for (const comp in this)
if (this[comp].toInitAttributes)
this[comp].toInitAttributes(attribs);

View file

@ -22,7 +22,7 @@ GameSettings.prototype.Attributes.Daytime = class Daytime extends GameSetting
onMapChange()
{
let mapData = this.settings.map.data;
const mapData = this.settings.map.data;
if (!mapData || !mapData.settings || !mapData.settings.Daytime)
{
this.setDataValueHelper(undefined, undefined);

View file

@ -47,8 +47,8 @@ GameSettings.prototype.Attributes.Landscape = class Landscape extends GameSettin
{
if (!this.value)
return undefined;
for (let group of this.data)
for (let item of group.Items)
for (const group of this.data)
for (const item of group.Items)
if (item.Id == this.value)
return item.Preview;
return undefined;
@ -63,7 +63,7 @@ GameSettings.prototype.Attributes.Landscape = class Landscape extends GameSettin
let items = [];
if (this.value.indexOf("_") !== -1)
{
let subgroup = this.data.find(x => x.Id == this.value);
const subgroup = this.data.find(x => x.Id == this.value);
items = subgroup.Items.map(x => x.Id);
}
else

View file

@ -29,8 +29,8 @@ GameSettings.prototype.Attributes.MapPreview = class MapPreview extends GameSett
{
if (!subtype)
return undefined;
let substr = subtype.substr(subtype.lastIndexOf("/") + 1);
let path = basepath + "_" + substr + ".png";
const substr = subtype.substr(subtype.lastIndexOf("/") + 1);
const path = basepath + "_" + substr + ".png";
if (this.settings.mapCache.previewExists(path))
return this.settings.mapCache.getMapPreview(this.settings.map.type,
this.settings.map.map, path);
@ -39,7 +39,7 @@ GameSettings.prototype.Attributes.MapPreview = class MapPreview extends GameSett
getLandscapePreview()
{
let filename = this.settings.landscape.getPreviewFilename();
const filename = this.settings.landscape.getPreviewFilename();
if (!filename)
return undefined;
return this.settings.mapCache.getMapPreview(this.settings.map.type,
@ -55,7 +55,7 @@ GameSettings.prototype.Attributes.MapPreview = class MapPreview extends GameSett
}
// This handles "random" map type (mostly for convenience).
let mapPath = basename(this.settings.map.map);
const mapPath = basename(this.settings.map.map);
this.value = this.getPreviewForSubtype(mapPath, this.settings.biome.biome) ||
this.getLandscapePreview() ||
this.getPreviewForSubtype(mapPath, this.settings.daytime.value) ||

View file

@ -84,7 +84,7 @@ GameSettings.prototype.Attributes.PlayerAI = class PlayerAI extends GameSetting
setAI(playerIndex, ai)
{
let old = this.values[playerIndex] ? this.values[playerIndex].bot : undefined;
const old = this.values[playerIndex] ? this.values[playerIndex].bot : undefined;
if (!ai)
this.values[playerIndex] = undefined;
else

View file

@ -18,7 +18,7 @@ GameSettings.prototype.Attributes.PlayerCiv = class PlayerCiv extends GameSettin
attribs.settings.PlayerData = [];
while (attribs.settings.PlayerData.length < this.values.length)
attribs.settings.PlayerData.push({});
for (let i in this.values)
for (const i in this.values)
if (this.values[i])
attribs.settings.PlayerData[i].Civ = this.values[i];
}
@ -76,7 +76,7 @@ GameSettings.prototype.Attributes.PlayerCiv = class PlayerCiv extends GameSettin
const civs = Object.keys(this.settings.civData).filter(civ => this.settings.civData[civ].SelectableInGameSetup);
let picked = false;
for (let i in this.values)
for (const i in this.values)
{
if (this.values[i] != "random")
continue;
@ -91,7 +91,7 @@ GameSettings.prototype.Attributes.PlayerCiv = class PlayerCiv extends GameSettin
_getMapData(i)
{
let data = this.settings.map.data;
const data = this.settings.map.data;
if (!data || !data.settings || !data.settings.PlayerData)
return undefined;
if (data.settings.PlayerData.length <= i)
@ -101,7 +101,7 @@ GameSettings.prototype.Attributes.PlayerCiv = class PlayerCiv extends GameSettin
_set(playerIndex, value)
{
let map = this._getMapData(playerIndex);
const map = this._getMapData(playerIndex);
if (!!map)
{
this.values[playerIndex] = map;

View file

@ -21,7 +21,7 @@ GameSettings.prototype.Attributes.PlayerColor = class PlayerColor extends GameSe
attribs.settings.PlayerData = [];
while (attribs.settings.PlayerData.length < this.values.length)
attribs.settings.PlayerData.push({});
for (let i in this.values)
for (const i in this.values)
if (this.values[i])
attribs.settings.PlayerData[i].Color = this.values[i];
}
@ -71,13 +71,13 @@ GameSettings.prototype.Attributes.PlayerColor = class PlayerColor extends GameSe
_set(playerIndex, color)
{
let inUse = this.values.findIndex((otherColor, i) =>
const inUse = this.values.findIndex((otherColor, i) =>
color && otherColor &&
sameColor(color, otherColor));
if (inUse != -1 && inUse != playerIndex)
{
// Swap colors.
let col = this.values[playerIndex];
const col = this.values[playerIndex];
this.values[playerIndex] = undefined;
this._set(inUse, col);
}
@ -113,7 +113,7 @@ GameSettings.prototype.Attributes.PlayerColor = class PlayerColor extends GameSe
_getMapData(i)
{
let data = this.settings.map.data;
const data = this.settings.map.data;
if (!data || !data.settings || !data.settings.PlayerData)
return undefined;
if (data.settings.PlayerData.length <= i)
@ -126,11 +126,11 @@ GameSettings.prototype.Attributes.PlayerColor = class PlayerColor extends GameSe
// Pick colors that the map specifies, add most unsimilar default colors
// Provide the access to all the colors defined in simulation/data/settings/player_defaults.json,
// regardless of current playercount.
let values = [];
const values = [];
let mapColors = false;
for (let i = 0; i < this.DefaultColors.length; ++i)
{
let col = this._getMapData(i);
const col = this._getMapData(i);
if (col)
mapColors = true;
if (mapColors)
@ -145,9 +145,9 @@ GameSettings.prototype.Attributes.PlayerColor = class PlayerColor extends GameSe
{
let closestColor;
let closestColorDistance = 0;
for (let color of colors)
for (const color of colors)
{
let dist = colorDistance(targetColor, color);
const dist = colorDistance(targetColor, color);
if (!closestColor || dist < closestColorDistance)
{
closestColor = color;
@ -162,12 +162,12 @@ GameSettings.prototype.Attributes.PlayerColor = class PlayerColor extends GameSe
let farthestColor;
let farthestDistance = 0;
for (let defaultColor of this.DefaultColors)
for (const defaultColor of this.DefaultColors)
{
let smallestDistance = Infinity;
for (let usedColor of values)
for (const usedColor of values)
{
let distance = colorDistance(usedColor, defaultColor);
const distance = colorDistance(usedColor, defaultColor);
if (distance < smallestDistance)
smallestDistance = distance;
}

View file

@ -22,7 +22,7 @@ GameSettings.prototype.Attributes.PlayerName = class PlayerName extends GameSett
while (attribs.settings.PlayerData.length < this.values.length)
attribs.settings.PlayerData.push({});
for (let i in this.values)
for (const i in this.values)
if (this.values[i])
attribs.settings.PlayerData[i].Name = this.values[i];
}
@ -69,17 +69,17 @@ GameSettings.prototype.Attributes.PlayerName = class PlayerName extends GameSett
{
const AIPlayerNamesList = [];
let picked = false;
for (let i in this.values)
for (const i in this.values)
{
if (!!this.values[i] &&
this.values[i] !== g_Settings.PlayerDefaults[+i + 1].Name)
continue;
let ai = this.settings.playerAI.values[i];
const ai = this.settings.playerAI.values[i];
if (!ai)
continue;
let civ = this.settings.playerCiv.values[i];
const civ = this.settings.playerCiv.values[i];
if (!civ || civ == "random")
continue;
@ -125,7 +125,7 @@ GameSettings.prototype.Attributes.PlayerName = class PlayerName extends GameSett
_getMapData(i)
{
let data = this.settings.map.data;
const data = this.settings.map.data;
if (!data || !data.settings || !data.settings.PlayerData)
return undefined;
if (data.settings.PlayerData.length <= i)

View file

@ -18,7 +18,7 @@ GameSettings.prototype.Attributes.PlayerTeam = class PlayerTeam extends GameSett
attribs.settings.PlayerData = [];
while (attribs.settings.PlayerData.length < this.values.length)
attribs.settings.PlayerData.push({});
for (let i in this.values)
for (const i in this.values)
if (this.values[i] !== undefined)
attribs.settings.PlayerData[i].Team = this.values[i];
}

View file

@ -22,7 +22,7 @@ GameSettings.prototype.Attributes.Population = class Population extends GameSett
attribs.settings.PlayerData = [];
while (attribs.settings.PlayerData.length < this.perPlayer.length)
attribs.settings.PlayerData.push({});
for (let i in this.perPlayer)
for (const i in this.perPlayer)
if (this.perPlayer[i])
attribs.settings.PlayerData[i].PopulationLimit = this.perPlayer[i];
}

View file

@ -27,7 +27,7 @@ GameSettings.prototype.Attributes.SeaLevelRise = class SeaLevelRise extends Game
this.value = undefined;
return;
}
let mapData = this.settings.map.data;
const mapData = this.settings.map.data;
this.min = mapData.settings.SeaLevelRise.Min;
this.max = mapData.settings.SeaLevelRise.Max;
this.value = mapData.settings.SeaLevelRise.Default;

View file

@ -46,9 +46,9 @@ GameSettings.prototype.Attributes.StartingCamera = class StartingCamera extends
onMapChange()
{
let pData = this.getMapSetting("PlayerData");
const pData = this.getMapSetting("PlayerData");
this._resize(pData?.length || 0);
for (let i in pData)
for (const i in pData)
this.values[i] = pData?.[i]?.StartingCamera;
}

View file

@ -19,7 +19,7 @@ GameSettings.prototype.Attributes.StartingResources = class StartingResources ex
attribs.settings.PlayerData = [];
while (attribs.settings.PlayerData.length < this.perPlayer.length)
attribs.settings.PlayerData.push({});
for (let i in this.perPlayer)
for (const i in this.perPlayer)
if (this.perPlayer[i])
attribs.settings.PlayerData[i].Resources = this.perPlayer[i];
}

View file

@ -22,9 +22,9 @@ GameSettings.prototype.Attributes.TriggerScripts = class TriggerScripts extends
updateVictoryScripts()
{
let setting = this.settings.victoryConditions;
let scripts = new Set();
for (let cond of setting.active)
const setting = this.settings.victoryConditions;
const scripts = new Set();
for (const cond of setting.active)
setting.conditions[cond].Scripts.forEach(script => scripts.add(script));
this.victoryScripts = scripts;
}

View file

@ -13,12 +13,12 @@ GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions ex
{
this.settings.map.watch(() => this.onMapChange(), ["map"]);
let conditions = loadVictoryConditions();
for (let cond of conditions)
const conditions = loadVictoryConditions();
for (const cond of conditions)
this.conditions[cond.Name] = cond;
let defaults = [];
for (let cond in this.conditions)
const defaults = [];
for (const cond in this.conditions)
if (this.conditions[cond].Default)
defaults.push(this.conditions[cond].Name);
this._add(this.active, this.disabled, defaults);
@ -57,8 +57,8 @@ GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions ex
_reconstructDisabled(active)
{
let disabled = new Set();
for (let cond of active)
const disabled = new Set();
for (const cond of active)
if (this.conditions[cond].DisabledWhenChecked)
this.conditions[cond].DisabledWhenChecked.forEach(x => disabled.add(x));
@ -67,7 +67,7 @@ GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions ex
_add(currentActive, currentDisabled, names)
{
let active = clone(currentActive);
const active = clone(currentActive);
for (const name of names)
{
if (currentDisabled.has(name))
@ -84,7 +84,7 @@ GameSettings.prototype.Attributes.VictoryConditions = class VictoryConditions ex
_delete(names)
{
let active = clone(this.active);
const active = clone(this.active);
for (const name of names)
active.delete(name);
// TODO: sanity check