Opened 21 months ago

Closed 9 months ago

#6094 closed defect (invalid)

Do not use let or const in global scope unless strictly necessary.

Reported by: nani Owned by:
Priority: Must Have Milestone:
Component: UI & Simulation Keywords:
Cc: Patch:

Description

Using global let or const makes the variables inaccessibles from the global scope for mods that need to access those variables, making impossible to access them. This also makes them impossible to access them from the console.

Change History (5)

comment:1 by Stan‘, 20 months ago

Do you have any examples of stuff you'd like to access? I suppose using let and const have performance implications for us.

Last edited 20 months ago by Stan‘ (previous) (diff)

comment:2 by nani, 19 months ago

The values that I mean are the next ones, take into account I'm not saying to make no const the varaibles but that they sould be accesible from the console. 

egrep -r "!^let" ./public/gui/*
egrep -r "!^const" ./public/gui/*
./public/gui/common/!settings.js:const g_MaxPlayers = 8;
./public/gui/common/!settings.js:const g_MaxTeams = 4;
./public/gui/common/!settings.js:const g_SettingsDirectory = "simulation/data/settings/";
./public/gui/common/!settings.js:const g_BiomesDirectory = "maps/random/rmbiome/";
./public/gui/common/!settings.js:const g_Settings = loadSettingsValues();
./public/gui/gamesetup/!gamesetup.js:const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.!MapSizes);
./public/gui/gamesetup/!gamesetup.js:const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.!MapTypes);
./public/gui/gamesetup/!gamesetup.js:const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.!PopulationCapacities);
./public/gui/gamesetup/!gamesetup.js:const g_WorldPopulationCapacities = prepareForDropdown(g_Settings && g_Settings.!WorldPopulationCapacities);
./public/gui/gamesetup/!gamesetup.js:const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.!StartingResources);
./public/gui/gamesetup/!gamesetup.js:const g_VictoryConditions = g_Settings && g_Settings.!VictoryConditions;
./public/gui/gamesetup/!gamesetup.js:const g_CivData = loadCivData(false, false);
./public/gui/gamesetup/!gamesetup.js:const g_IsNetworked = Engine.!HasNetClient();
./public/gui/gamesetup/!gamesetup.js:const g_IsController = !g_IsNetworked !|| Engine.!HasNetServer();
./public/gui/loadgame/!SavegameDetails.js:const g_CivData = loadCivData(false, false);
./public/gui/lobby/!lobby.js:const g_VictoryConditions = g_Settings && g_Settings.!VictoryConditions;
./public/gui/lobby/!lobby.js:const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.!MapSizes);
./public/gui/lobby/!lobby.js:const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.!MapTypes);
./public/gui/lobby/!lobby.js:const g_CivData = loadCivData(false, false);
./public/gui/maps/mapbrowser/!MapBrowserPage.js:const g_IsController = false;
./public/gui/maps/mapbrowser/!MapBrowserPage.js:const g_GameAttributes = {
./public/gui/maps/mapbrowser/!MapBrowserPage.js:const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.!MapTypes);
./public/gui/maps/mapbrowser/utils/!MatchSort.js:const !MatchSort = (function() {
./public/gui/maps/mapbrowser/utils/!MatchSort.js:const Highscore = -10E7;
./public/gui/replaymenu/replay_!filters.js:const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.!PopulationCapacities);
./public/gui/replaymenu/replay_!filters.js:const g_WorldPopulationCapacities = prepareForDropdown(g_Settings && g_Settings.!WorldPopulationCapacities);
./public/gui/replaymenu/replay_!menu.js:const g_EngineInfo = Engine.!GetEngineInfo();
./public/gui/replaymenu/replay_!menu.js:const g_CivData = loadCivData(false, false);
./public/gui/replaymenu/replay_!menu.js:const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.!MapSizes);
./public/gui/session/!input.js:const SDL_BUTTON_LEFT = 1;
./public/gui/session/!input.js:const SDL_BUTTON_MIDDLE = 2;
./public/gui/session/!input.js:const SDL_BUTTON_RIGHT = 3;
./public/gui/session/!input.js:const SDLK_LEFTBRACKET = 91;
./public/gui/session/!input.js:const SDLK_RIGHTBRACKET = 93;
./public/gui/session/!input.js:const SDLK_RSHIFT = 303;
./public/gui/session/!input.js:const SDLK_LSHIFT = 304;
./public/gui/session/!input.js:const SDLK_RCTRL = 305;
./public/gui/session/!input.js:const SDLK_LCTRL = 306;
./public/gui/session/!input.js:const SDLK_RALT = 307;
./public/gui/session/!input.js:const SDLK_LALT = 308;
./public/gui/session/!input.js:const ACTION_NONE = 0;
./public/gui/session/!input.js:const ACTION_GARRISON = 1;
./public/gui/session/!input.js:const ACTION_REPAIR = 2;
./public/gui/session/!input.js:const ACTION_GUARD = 3;
./public/gui/session/!input.js:const ACTION_PATROL = 4;
./public/gui/session/!input.js:const INPUT_NORMAL = 0;
./public/gui/session/!input.js:const INPUT_SELECTING = 1;
./public/gui/session/!input.js:const INPUT_BANDBOXING = 2;
./public/gui/session/!input.js:const INPUT_BUILDING_PLACEMENT = 3;
./public/gui/session/!input.js:const INPUT_BUILDING_CLICK = 4;
./public/gui/session/!input.js:const INPUT_BUILDING_DRAG = 5;
./public/gui/session/!input.js:const INPUT_BATCHTRAINING = 6;
./public/gui/session/!input.js:const INPUT_PRESELECTEDACTION = 7;
./public/gui/session/!input.js:const INPUT_BUILDING_WALL_CLICK = 8;
./public/gui/session/!input.js:const INPUT_BUILDING_WALL_PATHING = 9;
./public/gui/session/!input.js:const INPUT_UNIT_POSITION_START = 10;
./public/gui/session/!input.js:const INPUT_UNIT_POSITION = 11;
./public/gui/session/!input.js:const INVALID_ENTITY = 0;
./public/gui/session/!input.js:const g_FreehandSelection_ResolutionInputLineSquared = 1;
./public/gui/session/!input.js:const g_FreehandSelection_MinLengthOfLine = 8;
./public/gui/session/!input.js:const g_FreehandSelection_MinNumberOfUnits = 2;
./public/gui/session/!input.js:const g_MaxDragDelta = 4;
./public/gui/session/!input.js:const doublePressTime = 500;
./public/gui/session/selection_panels_!helpers.js:const UPGRADING_NOT_STARTED = -2;
./public/gui/session/selection_panels_!helpers.js:const UPGRADING_CHOSEN_OTHER = -1;
./public/gui/session/!session.js:const g_IsReplay = Engine.!IsVisualReplay();
./public/gui/session/!session.js:const g_CivData = loadCivData(false, true);
./public/gui/session/!session.js:const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.!MapSizes);
./public/gui/session/!session.js:const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.!MapTypes);
./public/gui/session/!session.js:const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.!PopulationCapacities);
./public/gui/session/!session.js:const g_WorldPopulationCapacities = prepareForDropdown(g_Settings && g_Settings.!WorldPopulationCapacities);
./public/gui/session/!session.js:const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.!StartingResources);
./public/gui/session/!session.js:const g_VictoryConditions = g_Settings && g_Settings.!VictoryConditions;
./public/gui/session/!session.js:const g_GameAttributes = deepfreeze(Engine.!GuiInterfaceCall("!GetInitAttributes"));
./public/gui/session/!session.js:const g_IsNetworked = Engine.!HasNetClient();
./public/gui/session/unit_!actions.js:const g_DisabledTags = { "color": "255 140 0" };
./public/gui/summary/!summary.js:const g_CivData = loadCivData(false, false);
./public/gui/session/selection_!panels.js:let g_PanelsOrder = [
Last edited 19 months ago by Stan‘ (previous) (diff)

comment:3 by Freagarach, 19 months ago

The idea is that the GUI will become completely OOP-writen, hence removing (many of?) the globals and giving easier access to them, IIRC.

Regarding input.js, it would be nice to have that in a FSM. ;)

I _think_ this is what you mean, but I'm not really into the GUI. Also some things are not meant to be changed on the fly.

comment:4 by wraitii, 18 months ago

Milestone: Alpha 25Alpha 26

comment:5 by Freagarach, 9 months ago

Keywords: global let const removed
Milestone: Alpha 26
Resolution: invalid
Status: newclosed

I've noted in the CC: http://trac.wildfiregames.com/wiki/Coding_Conventions?version=55 but it is not really a ticket that can be solved. (Unless one rewrites it to: Remove not needed let and const from global scope.)

Note: See TracTickets for help on using tickets.