Changeset View
Standalone View
binaries/data/mods/public/gui/gamesetup/gamesetup.js
const g_MatchSettings_SP = "config/matchsettings.json"; | const g_MatchSettings_SP = "config/matchsettings.json"; | ||||
const g_MatchSettings_MP = "config/matchsettings.mp.json"; | const g_MatchSettings_MP = "config/matchsettings.mp.json"; | ||||
const g_Ceasefire = prepareForDropdown(g_Settings && g_Settings.Ceasefire); | const g_Ceasefire = prepareForDropdown(g_Settings && g_Settings.Ceasefire); | ||||
const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes); | const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes); | ||||
const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes); | const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes); | ||||
const g_TriggerDifficulties = prepareForDropdown(g_Settings && g_Settings.TriggerDifficulties); | const g_TriggerDifficulties = prepareForDropdown(g_Settings && g_Settings.TriggerDifficulties); | ||||
const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities); | const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities); | ||||
const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources); | const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources); | ||||
const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions); | |||||
const g_VictoryDurations = prepareForDropdown(g_Settings && g_Settings.VictoryDurations); | const g_VictoryDurations = prepareForDropdown(g_Settings && g_Settings.VictoryDurations); | ||||
const g_VictoryConditions = g_Settings && g_Settings.VictoryConditions; | |||||
elexis: No newlines besides the consts, one newline before the first var? | |||||
var g_GameSpeeds = getGameSpeedChoices(false); | var g_GameSpeeds = getGameSpeedChoices(false); | ||||
/** | /** | ||||
* Offer users to select playable civs only. | * Offer users to select playable civs only. | ||||
* Load unselectable civs as they could appear in scenario maps. | * Load unselectable civs as they could appear in scenario maps. | ||||
*/ | */ | ||||
const g_CivData = loadCivData(false, false); | const g_CivData = loadCivData(false, false); | ||||
▲ Show 20 Lines • Show All 269 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Remembers which clients are assigned to which player slots and whether they are ready. | * Remembers which clients are assigned to which player slots and whether they are ready. | ||||
* The keys are guids or "local" in Singleplayer. | * The keys are guids or "local" in Singleplayer. | ||||
*/ | */ | ||||
var g_PlayerAssignments = {}; | var g_PlayerAssignments = {}; | ||||
var g_DefaultPlayerData = []; | var g_DefaultPlayerData = []; | ||||
var g_DefaultVictoryConditions = []; | |||||
Done Inline ActionsNo need for this to be a global, can be computed just-in-time, then also freeze+clone unneeded elexis: No need for this to be a global, can be computed just-in-time, then also freeze+clone unneeded | |||||
var g_GameAttributes = { "settings": {} }; | var g_GameAttributes = { "settings": {} }; | ||||
/** | /** | ||||
* List of translated words that can be used to autocomplete titles of settings | * List of translated words that can be used to autocomplete titles of settings | ||||
Not Done Inline Actionsentirely disliking this... bb: entirely disliking this... | |||||
Done Inline ActionsThere must be a way. I suspect it's possible to treat it similar to PlayerData elexis: There must be a way. I suspect it's possible to treat it similar to PlayerData | |||||
* and their values (for example playernames). | * and their values (for example playernames). | ||||
*/ | */ | ||||
var g_Autocomplete = []; | var g_Autocomplete = []; | ||||
/** | /** | ||||
* Array of strings formatted as displayed, including playername. | * Array of strings formatted as displayed, including playername. | ||||
*/ | */ | ||||
var g_ChatMessages = []; | var g_ChatMessages = []; | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | "settings": [ | ||||
"startingResources", | "startingResources", | ||||
"disableSpies", | "disableSpies", | ||||
"enableCheats" | "enableCheats" | ||||
] | ] | ||||
}, | }, | ||||
{ | { | ||||
"label": translateWithContext("Match settings tab name", "Game Type"), | "label": translateWithContext("Match settings tab name", "Game Type"), | ||||
"settings": [ | "settings": [ | ||||
"victoryCondition", | ...g_VictoryConditions.map(vc => vc.Name), | ||||
"relicCount", | "relicCount", | ||||
"relicDuration", | "relicDuration", | ||||
"wonderDuration", | "wonderDuration", | ||||
"regicideGarrison", | "regicideGarrison", | ||||
"gameSpeed", | "gameSpeed", | ||||
Not Done Inline ActionsI wonder if they should syntatically be mixed with the other checkbuxes. Could insert a separate array of victory conditions in place using the spread operator (similary like we do for resources in the summary screen) elexis: I wonder if they should syntatically be mixed with the other checkbuxes. Could insert a… | |||||
Not Done Inline Actionsmixing the items is as easy as changing the order in this array, kept them together now, but if someone has a better proposal we can ship with that bb: mixing the items is as easy as changing the order in this array, kept them together now, but if… | |||||
Not Done Inline ActionsThe argument was to make it impossible to mix elexis: The argument was to make it impossible to mix | |||||
Not Done Inline ActionsWhy would one? (one could argue to keep the 3 relic settings together f.e.) bb: Why would one? (one could argue to keep the 3 relic settings together f.e.)
(code to… | |||||
Not Done Inline Actionsfine for now. eventually the sub-settings should syntactically reflect being that. elexis: fine for now. eventually the sub-settings should syntactically reflect being that. | |||||
"ceasefire", | "ceasefire", | ||||
"lockTeams", | "lockTeams", | ||||
"lastManStanding", | "lastManStanding", | ||||
"enableRating" | "enableRating" | ||||
] | ] | ||||
} | } | ||||
]; | ]; | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | "ceasefire": { | ||||
"defined": () => g_GameAttributes.settings.Ceasefire !== undefined, | "defined": () => g_GameAttributes.settings.Ceasefire !== undefined, | ||||
"get": () => g_GameAttributes.settings.Ceasefire, | "get": () => g_GameAttributes.settings.Ceasefire, | ||||
"select": (itemIdx) => { | "select": (itemIdx) => { | ||||
g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[itemIdx]; | g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[itemIdx]; | ||||
}, | }, | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
"initOrder": 1000 | "initOrder": 1000 | ||||
}, | }, | ||||
"victoryCondition": { | |||||
"title": () => translate("Victory Condition"), | |||||
"tooltip": (hoverIdx) => g_VictoryConditions.Description[hoverIdx] || translate("Select victory condition."), | |||||
"labels": () => g_VictoryConditions.Title, | |||||
"ids": () => g_VictoryConditions.Name, | |||||
"default": () => g_VictoryConditions.Default, | |||||
"defined": () => g_GameAttributes.settings.GameType !== undefined, | |||||
"get": () => g_GameAttributes.settings.GameType, | |||||
"select": (itemIdx) => { | |||||
g_GameAttributes.settings.GameType = g_VictoryConditions.Name[itemIdx]; | |||||
g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[itemIdx]; | |||||
}, | |||||
"enabled": () => g_GameAttributes.mapType != "scenario", | |||||
"autocomplete": 0, | |||||
"initOrder": 1000 | |||||
}, | |||||
"relicCount": { | "relicCount": { | ||||
"title": () => translate("Relic Count"), | "title": () => translate("Relic Count"), | ||||
"tooltip": (hoverIdx) => translate("Total number of relics spawned on the map. Relic victory is most realistic with only one or two relics. With greater numbers, the relics are important to capture to receive aura bonuses."), | "tooltip": (hoverIdx) => translate("Total number of relics spawned on the map. Relic victory is most realistic with only one or two relics. With greater numbers, the relics are important to capture to receive aura bonuses."), | ||||
"labels": () => g_RelicCountList, | "labels": () => g_RelicCountList, | ||||
"ids": () => g_RelicCountList, | "ids": () => g_RelicCountList, | ||||
"default": () => g_RelicCountList.indexOf(2), | "default": () => g_RelicCountList.indexOf(2), | ||||
"defined": () => g_GameAttributes.settings.RelicCount !== undefined, | "defined": () => g_GameAttributes.settings.RelicCount !== undefined, | ||||
"get": () => g_GameAttributes.settings.RelicCount, | "get": () => g_GameAttributes.settings.RelicCount, | ||||
"select": (itemIdx) => { | "select": (itemIdx) => { | ||||
g_GameAttributes.settings.RelicCount = g_RelicCountList[itemIdx]; | g_GameAttributes.settings.RelicCount = g_RelicCountList[itemIdx]; | ||||
}, | }, | ||||
"hidden": () => g_GameAttributes.settings.GameType != "capture_the_relic", | "hidden": () => g_GameAttributes.settings.VictoryConditions.indexOf("capture_the_relic") == -1, | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
"initOrder": 1000 | "initOrder": 1000 | ||||
}, | }, | ||||
"relicDuration": { | "relicDuration": { | ||||
"title": () => translate("Relic Duration"), | "title": () => translate("Relic Duration"), | ||||
"tooltip": (hoverIdx) => translate("Minutes until the player has achieved Relic Victory."), | "tooltip": (hoverIdx) => translate("Minutes until the player has achieved Relic Victory."), | ||||
"labels": () => g_VictoryDurations.Title, | "labels": () => g_VictoryDurations.Title, | ||||
"ids": () => g_VictoryDurations.Duration, | "ids": () => g_VictoryDurations.Duration, | ||||
"default": () => g_VictoryDurations.Default, | "default": () => g_VictoryDurations.Default, | ||||
"defined": () => g_GameAttributes.settings.RelicDuration !== undefined, | "defined": () => g_GameAttributes.settings.RelicDuration !== undefined, | ||||
"get": () => g_GameAttributes.settings.RelicDuration, | "get": () => g_GameAttributes.settings.RelicDuration, | ||||
"select": (itemIdx) => { | "select": (itemIdx) => { | ||||
g_GameAttributes.settings.RelicDuration = g_VictoryDurations.Duration[itemIdx]; | g_GameAttributes.settings.RelicDuration = g_VictoryDurations.Duration[itemIdx]; | ||||
}, | }, | ||||
"hidden": () => g_GameAttributes.settings.GameType != "capture_the_relic", | "hidden": () => g_GameAttributes.settings.VictoryConditions.indexOf("capture_the_relic") == -1, | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
Not Done Inline Actionsfoo.bar || [] would be shorter but also kind of ugly. elexis: `foo.bar || []` would be shorter but also kind of ugly.
Can we make it so that this always is… | |||||
Not Done Inline ActionsThe problem there lies in the default setting of checkboxes in gamesetup: it will set a default iff when the defined tag is is falsy, as we do want to set a default for the victory conditions when nothing is set we need some kind of "undefined" for the array, empty set is not possible since that is no victory condition, thus an undefined value is used for that. bb: The problem there lies in the default setting of checkboxes in gamesetup: it will set a default… | |||||
Not Done Inline ActionsWhy can't we set the default no-condition array somewhere when initializing settings, similar to PlayerData? elexis: Why can't we set the default no-condition array somewhere when initializing `settings`, similar… | |||||
Not Done Inline ActionsSince we do not want a default no-condition array, but default ["conquest"] array and we shouldn't hardcode that in various parts of gamesetup, but hardcode in the checkboxes object, implemented another hack for now bb: Since we do not want a default no-condition array, but default ["conquest"] array and we… | |||||
"initOrder": 1000 | "initOrder": 1000 | ||||
}, | }, | ||||
"wonderDuration": { | "wonderDuration": { | ||||
"title": () => translate("Wonder Duration"), | "title": () => translate("Wonder Duration"), | ||||
"tooltip": (hoverIdx) => translate("Minutes until the player has achieved Wonder Victory."), | "tooltip": (hoverIdx) => translate("Minutes until the player has achieved Wonder Victory."), | ||||
"labels": () => g_VictoryDurations.Title, | "labels": () => g_VictoryDurations.Title, | ||||
"ids": () => g_VictoryDurations.Duration, | "ids": () => g_VictoryDurations.Duration, | ||||
"default": () => g_VictoryDurations.Default, | "default": () => g_VictoryDurations.Default, | ||||
"defined": () => g_GameAttributes.settings.WonderDuration !== undefined, | "defined": () => g_GameAttributes.settings.WonderDuration !== undefined, | ||||
"get": () => g_GameAttributes.settings.WonderDuration, | "get": () => g_GameAttributes.settings.WonderDuration, | ||||
"select": (itemIdx) => { | "select": (itemIdx) => { | ||||
g_GameAttributes.settings.WonderDuration = g_VictoryDurations.Duration[itemIdx]; | g_GameAttributes.settings.WonderDuration = g_VictoryDurations.Duration[itemIdx]; | ||||
}, | }, | ||||
"hidden": () => g_GameAttributes.settings.GameType != "wonder", | "hidden": () => g_GameAttributes.settings.VictoryConditions.indexOf("wonder") == -1, | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
"initOrder": 1000 | "initOrder": 1000 | ||||
}, | }, | ||||
"gameSpeed": { | "gameSpeed": { | ||||
"title": () => translate("Game Speed"), | "title": () => translate("Game Speed"), | ||||
"tooltip": (hoverIdx) => translate("Select game speed."), | "tooltip": (hoverIdx) => translate("Select game speed."), | ||||
"labels": () => g_GameSpeeds.Title, | "labels": () => g_GameSpeeds.Title, | ||||
"ids": () => g_GameSpeeds.Speed, | "ids": () => g_GameSpeeds.Speed, | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | "playerColorPicker": { | ||||
}, | }, | ||||
"enabled": () => g_GameAttributes.mapType != "scenario", | "enabled": () => g_GameAttributes.mapType != "scenario", | ||||
}, | }, | ||||
}; | }; | ||||
/** | /** | ||||
* Contains the logic of all boolean gamesettings. | * Contains the logic of all boolean gamesettings. | ||||
*/ | */ | ||||
var g_Checkboxes = { | var g_Checkboxes = Object.assign( | ||||
{}, | |||||
g_VictoryConditions.reduce((obj, victoryCondition) => { | |||||
obj[victoryCondition.Name] = { | |||||
"title": () => victoryCondition.Title, | |||||
"tooltip": () => victoryCondition.Description, | |||||
"default": () => victoryCondition.Default, | |||||
Done Inline ActionsAs discused in irc yeterday, never introduce code that doesn't do anything. Because the reader always has to assume that code exists because that code does something. Then he might try to improve the code that doesn'T do anything, or look to fix a bug in that line that doesn't do anything. So don't do anything like this and replace it with a comment explaining minimalistically why there is one entry less than in all the other places. elexis: As discused in irc yeterday, never introduce code that doesn't do anything. Because the reader… | |||||
Done Inline ActionsJSON can't set anything, it just exists. What sets the defaults is supplementDefaults. Maybe // Defaults are set in supplementDefaults because this is an array, not sure elexis: JSON can't set anything, it just exists. What sets the defaults is `supplementDefaults`. Maybe… | |||||
"defined": () => true, | |||||
"get": () => g_GameAttributes.settings.VictoryConditions.indexOf(victoryCondition.Name) != -1, | |||||
"set": checked => { | |||||
if (checked) | |||||
{ | |||||
g_GameAttributes.settings.VictoryConditions.push(victoryCondition.Name); | |||||
if (victoryCondition.Set) | |||||
for (let setting in victoryCondition.ChangeWhenChecked) | |||||
g_Checkboxes[setting].set(victoryCondition.ChangeOnChecked[setting]); | |||||
Not Done Inline ActionsStill not a fan of this thing. I suspect some logic could be pushed to the Conquest trigger scripts. elexis: Still not a fan of this thing. I suspect some logic could be pushed to the Conquest trigger… | |||||
Not Done Inline Actionsnot to the trigger scripts, those do not run in gamesetup, maybe the json can do something however bb: not to the trigger scripts, those do not run in gamesetup, maybe the json can do something… | |||||
Not Done Inline ActionsI mean we might nuke Conquest and make the two remainders behave like Conquest if both are triggered? elexis: I mean we might nuke Conquest and make the two remainders behave like Conquest if both are… | |||||
Not Done Inline Actionsimo it is nice to allow the player && and || bb: imo it is nice to allow the player && and || | |||||
} | |||||
else | |||||
g_GameAttributes.settings.VictoryConditions = g_GameAttributes.settings.VictoryConditions.filter(vc => vc != victoryCondition.Name) | |||||
Done Inline Actionssemi Imarok: semi | |||||
}, | |||||
"enabled": () => | |||||
g_GameAttributes.mapType != "scenario" && | |||||
(!victoryCondition.DisabledWhenChecked || | |||||
victoryCondition.DisabledWhenChecked.every(vc => g_GameAttributes.settings.VictoryConditions.indexOf(vc) == -1)) | |||||
}; | |||||
return obj; | |||||
}, {}), | |||||
Done Inline Actionsg_GameAttributes.mapType != "scenario" can be omitted here too by extending instead of replacing elexis: `g_GameAttributes.mapType != "scenario"` can be omitted here too by extending instead of… | |||||
Not Done Inline ActionsThis is actually much nicer, more maintainable, inviting for mods, extendible and less complex than the previous function. Thanks elexis: This is actually much nicer, more maintainable, inviting for mods, extendible and less complex… | |||||
"regicideGarrison": { | "regicideGarrison": { | ||||
bbAuthorUnsubmitted Not Done Inline Actionsmissing opening curly bracket bb: missing opening curly bracket | |||||
"title": () => translate("Hero Garrison"), | "title": () => translate("Hero Garrison"), | ||||
"tooltip": () => translate("Toggle whether heroes can be garrisoned."), | "tooltip": () => translate("Toggle whether heroes can be garrisoned."), | ||||
"default": () => false, | "default": () => false, | ||||
"defined": () => g_GameAttributes.settings.RegicideGarrison !== undefined, | "defined": () => g_GameAttributes.settings.RegicideGarrison !== undefined, | ||||
"get": () => g_GameAttributes.settings.RegicideGarrison, | "get": () => g_GameAttributes.settings.RegicideGarrison, | ||||
"set": checked => { | "set": checked => { | ||||
g_GameAttributes.settings.RegicideGarrison = checked; | g_GameAttributes.settings.RegicideGarrison = checked; | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | "lastManStanding": { | ||||
"defined": () => g_GameAttributes.settings.LastManStanding !== undefined, | "defined": () => g_GameAttributes.settings.LastManStanding !== undefined, | ||||
"get": () => g_GameAttributes.settings.LastManStanding, | "get": () => g_GameAttributes.settings.LastManStanding, | ||||
"set": checked => { | "set": checked => { | ||||
g_GameAttributes.settings.LastManStanding = checked; | g_GameAttributes.settings.LastManStanding = checked; | ||||
}, | }, | ||||
"enabled": () => | "enabled": () => | ||||
g_GameAttributes.mapType != "scenario" && | g_GameAttributes.mapType != "scenario" && | ||||
!g_GameAttributes.settings.LockTeams, | !g_GameAttributes.settings.LockTeams, | ||||
"initOrder": 1000 | "initOrder": 1000 | ||||
Not Done Inline ActionsDoes it only look like it, or is it actually a bit of duplication per victory condition? Could we add a new global array g_VictoryConditions that one way or another is initialized with unique information, a function to repeat the rest, then inlining that here or extending this object elsewhere? elexis: Does it only look like it, or is it actually a bit of duplication per victory condition?
Could… | |||||
Not Done Inline ActionsWell conquest is different (and I am not in favor of removing that)... so we need to define the set function and the hidden tag to be custom for every victory condition. The other stuff could be unduplicated, but not sure if that is still worth it, could be done however bb: Well conquest is different (and I am not in favor of removing that)... so we need to define the… | |||||
Not Done Inline Actionss/could/should regicide: getVictoryConditionCheckbox({ "enabled": (...) => somethingCustom }); Where the scenario part is still done inside the function. If there wasn't this approach, the g_GameAttributes.settings.VictoryConditions duplication is dubious specifically, seems cleaner to do that upon launchGame in that case. elexis: s/could/should
I didn't spend my time to see cheap copypasta being added again.
```
regicide… | |||||
}, | }, | ||||
"enableCheats": { | "enableCheats": { | ||||
"title": () => translate("Cheats"), | "title": () => translate("Cheats"), | ||||
"tooltip": () => translate("Toggle the usability of cheats."), | "tooltip": () => translate("Toggle the usability of cheats."), | ||||
"default": () => !g_IsNetworked, | "default": () => !g_IsNetworked, | ||||
"hidden": () => !g_IsNetworked, | "hidden": () => !g_IsNetworked, | ||||
"defined": () => g_GameAttributes.settings.CheatsEnabled !== undefined, | "defined": () => g_GameAttributes.settings.CheatsEnabled !== undefined, | ||||
"get": () => g_GameAttributes.settings.CheatsEnabled, | "get": () => g_GameAttributes.settings.CheatsEnabled, | ||||
Show All 17 Lines | "enableRating": { | ||||
if (checked) | if (checked) | ||||
{ | { | ||||
g_Checkboxes.lockTeams.set(true); | g_Checkboxes.lockTeams.set(true); | ||||
g_Checkboxes.enableCheats.set(false); | g_Checkboxes.enableCheats.set(false); | ||||
} | } | ||||
}, | }, | ||||
"initOrder": 1000 | "initOrder": 1000 | ||||
}, | }, | ||||
}; | } | ||||
); | |||||
Not Done Inline Actionsoh, the first one to find a way to init an object like that elexis: oh, the first one to find a way to init an object like that | |||||
Done Inline Actionseach argument, i.e. {}, on a separate line elexis: each argument, i.e. `{},` on a separate line | |||||
/** | /** | ||||
* For setting up arbitrary GUI objects. | * For setting up arbitrary GUI objects. | ||||
*/ | */ | ||||
var g_MiscControls = { | var g_MiscControls = { | ||||
"chatPanel": { | "chatPanel": { | ||||
"hidden": () => { | "hidden": () => { | ||||
if (!g_IsNetworked) | if (!g_IsNetworked) | ||||
return true; | return true; | ||||
let size = Engine.GetGUIObjectByName("chatPanel").getComputedSize(); | let size = Engine.GetGUIObjectByName("chatPanel").getComputedSize(); | ||||
Not Done Inline ActionsVery good having moved this hardcoded structre / non-gamesetup logic out of here. elexis: Very good having moved this hardcoded structre / non-gamesetup logic out of here. | |||||
return size.right - size.left < g_MinChatWidth; | return size.right - size.left < g_MinChatWidth; | ||||
}, | }, | ||||
}, | }, | ||||
"chatInput": { | "chatInput": { | ||||
"tooltip": () => colorizeAutocompleteHotkey(translate("Press %(hotkey)s to autocomplete playernames or settings.")), | "tooltip": () => colorizeAutocompleteHotkey(translate("Press %(hotkey)s to autocomplete playernames or settings.")), | ||||
}, | }, | ||||
"cheatWarningText": { | "cheatWarningText": { | ||||
"hidden": () => !g_IsNetworked || !g_GameAttributes.settings.CheatsEnabled, | "hidden": () => !g_IsNetworked || !g_GameAttributes.settings.CheatsEnabled, | ||||
Done Inline ActionsNot sure if combining the lines using a filter would be better. elexis: Not sure if combining the lines using a `filter` would be better. | |||||
}, | }, | ||||
"cancelGame": { | "cancelGame": { | ||||
"tooltip": () => | "tooltip": () => | ||||
Engine.HasXmppClient() ? | Engine.HasXmppClient() ? | ||||
translate("Return to the lobby.") : | translate("Return to the lobby.") : | ||||
translate("Return to the main menu."), | translate("Return to the main menu."), | ||||
}, | }, | ||||
"startGame": { | "startGame": { | ||||
"caption": () => | "caption": () => | ||||
g_IsController ? translate("Start Game!") : g_ReadyData[g_IsReady].caption, | g_IsController ? translate("Start Game!") : g_ReadyData[g_IsReady].caption, | ||||
Not Done Inline ActionsWould be good to commit the yellow unchanged lines below separately and do one commit leaving improper whitespace IMO. elexis: Would be good to commit the yellow unchanged lines below separately and do one commit leaving… | |||||
Not Done Inline Actionsthere will be a "suggested by" tag in the commit.... bb: there will be a "suggested by" tag in the commit.... | |||||
"tooltip": (hoverIdx) => | "tooltip": (hoverIdx) => | ||||
!g_IsController ? | !g_IsController ? | ||||
g_ReadyData[g_IsReady].tooltip : | g_ReadyData[g_IsReady].tooltip : | ||||
!g_IsNetworked || Object.keys(g_PlayerAssignments).every(guid => | !g_IsNetworked || Object.keys(g_PlayerAssignments).every(guid => | ||||
g_PlayerAssignments[guid].status || g_PlayerAssignments[guid].player == -1) ? | g_PlayerAssignments[guid].status || g_PlayerAssignments[guid].player == -1) ? | ||||
translate("Start a new game with the current settings.") : | translate("Start a new game with the current settings.") : | ||||
translate("Start a new game with the current settings (disabled until all players are ready)"), | translate("Start a new game with the current settings (disabled until all players are ready)"), | ||||
"enabled": () => !g_IsController || | "enabled": () => !g_IsController || | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | function initDefaults() | ||||
for (let i in g_DefaultPlayerData) | for (let i in g_DefaultPlayerData) | ||||
{ | { | ||||
g_DefaultPlayerData[i].Civ = "random"; | g_DefaultPlayerData[i].Civ = "random"; | ||||
g_DefaultPlayerData[i].Team = -1; | g_DefaultPlayerData[i].Team = -1; | ||||
g_DefaultPlayerData[i].AIDiff = aiDifficulty; | g_DefaultPlayerData[i].AIDiff = aiDifficulty; | ||||
g_DefaultPlayerData[i].AIBehavior = aiBehavior; | g_DefaultPlayerData[i].AIBehavior = aiBehavior; | ||||
} | } | ||||
deepfreeze(g_DefaultPlayerData); | deepfreeze(g_DefaultPlayerData); | ||||
Not Done Inline Actionsmany weird moved lines, luckily they're tagged yellow elexis: many weird moved lines, luckily they're tagged yellow | |||||
Not Done Inline Actions(all that happened is an extra indentation due to the extra function) bb: (all that happened is an extra indentation due to the extra function) | |||||
g_DefaultVictoryConditions = g_VictoryConditions.filter(vc => !!vc.Default).map(vc => vc.Name); | |||||
deepfreeze(g_DefaultVictoryConditions); | |||||
Not Done Inline Actionscan be / could have been one line elexis: can be / could have been one line | |||||
Not Done Inline Actionsremoved anyhow bb: removed anyhow | |||||
} | } | ||||
/** | /** | ||||
* Sets default values for all g_GameAttribute settings which don't have a value set. | * Sets default values for all g_GameAttribute settings which don't have a value set. | ||||
*/ | */ | ||||
function supplementDefaults() | function supplementDefaults() | ||||
{ | { | ||||
g_GameAttributes.settings.VictoryConditions = g_GameAttributes.settings.VictoryConditions || clone(g_DefaultVictoryConditions); | |||||
Done Inline ActionsThe default mechanism in g_Checkboxes should set the default. The only thing that needs to happen here is ensuring it's an array. elexis: The `default` mechanism in g_Checkboxes should set the default. The only thing that needs to… | |||||
for (let dropdown in g_Dropdowns) | for (let dropdown in g_Dropdowns) | ||||
Not Done Inline ActionsStill sad to see two different kinds of logic. But this can be solved later: elexis: Still sad to see two different kinds of logic. But this can be solved later:
The next planned… | |||||
if (!g_Dropdowns[dropdown].defined()) | if (!g_Dropdowns[dropdown].defined()) | ||||
g_Dropdowns[dropdown].select(g_Dropdowns[dropdown].default()); | g_Dropdowns[dropdown].select(g_Dropdowns[dropdown].default()); | ||||
for (let checkbox in g_Checkboxes) | for (let checkbox in g_Checkboxes) | ||||
if (!g_Checkboxes[checkbox].defined()) | if (!g_Checkboxes[checkbox].defined()) | ||||
g_Checkboxes[checkbox].set(g_Checkboxes[checkbox].default()); | g_Checkboxes[checkbox].set(g_Checkboxes[checkbox].default()); | ||||
for (let dropdown in g_PlayerDropdowns) | for (let dropdown in g_PlayerDropdowns) | ||||
▲ Show 20 Lines • Show All 468 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Filter maps with filterFunc and by chosen map type. | * Filter maps with filterFunc and by chosen map type. | ||||
* | * | ||||
* @param {function} filterFunc - Filter function that should be applied. | * @param {function} filterFunc - Filter function that should be applied. | ||||
* @return {Array} the maps that match the filterFunc and the chosen map type. | * @return {Array} the maps that match the filterFunc and the chosen map type. | ||||
*/ | */ | ||||
function getFilteredMaps(filterFunc) | function getFilteredMaps(filterFunc) | ||||
{ | { | ||||
Done Inline ActionsWould be nice to remove the ability to execute code in this function, i.e. var getVictoryConditionCheckbox = name => ({ ... "enabled": !scenario && (enabled ? enabled() : true) ... }) This way one only has to read that one line to determine it's value rather than the entire function elexis: Would be nice to remove the ability to execute code in this function, i.e.
```
var… | |||||
if (!g_MapPath[g_GameAttributes.mapType]) | if (!g_MapPath[g_GameAttributes.mapType]) | ||||
{ | { | ||||
error("Unexpected map type: " + g_GameAttributes.mapType); | error("Unexpected map type: " + g_GameAttributes.mapType); | ||||
return []; | return []; | ||||
} | } | ||||
let maps = []; | let maps = []; | ||||
// TODO: Should verify these are valid maps before adding to list | // TODO: Should verify these are valid maps before adding to list | ||||
▲ Show 20 Lines • Show All 336 Lines • ▼ Show 20 Lines | function selectMap(name) | ||||
// Reset some map specific properties which are not necessarily redefined on each map | // Reset some map specific properties which are not necessarily redefined on each map | ||||
for (let prop of ["TriggerScripts", "CircularMap", "Garrison", "DisabledTemplates", "Biome", "SupportedBiomes", "SupportedTriggerDifficulties", "TriggerDifficulty"]) | for (let prop of ["TriggerScripts", "CircularMap", "Garrison", "DisabledTemplates", "Biome", "SupportedBiomes", "SupportedTriggerDifficulties", "TriggerDifficulty"]) | ||||
g_GameAttributes.settings[prop] = undefined; | g_GameAttributes.settings[prop] = undefined; | ||||
let mapData = loadMapData(name); | let mapData = loadMapData(name); | ||||
let mapSettings = mapData && mapData.settings ? clone(mapData.settings) : {}; | let mapSettings = mapData && mapData.settings ? clone(mapData.settings) : {}; | ||||
if (g_GameAttributes.mapType != "random") | if (g_GameAttributes.mapType != "random") | ||||
{ | |||||
delete g_GameAttributes.settings.Nomad; | delete g_GameAttributes.settings.Nomad; | ||||
let victoryIdx = g_VictoryConditions.Name.indexOf(mapSettings.GameType || "") != -1 ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default; | |||||
g_GameAttributes.settings.GameType = g_VictoryConditions.Name[victoryIdx]; | |||||
g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[victoryIdx]; | |||||
} | |||||
if (g_GameAttributes.mapType == "scenario") | if (g_GameAttributes.mapType == "scenario") | ||||
{ | { | ||||
delete g_GameAttributes.settings.RelicDuration; | delete g_GameAttributes.settings.RelicDuration; | ||||
delete g_GameAttributes.settings.WonderDuration; | delete g_GameAttributes.settings.WonderDuration; | ||||
delete g_GameAttributes.settings.LastManStanding; | delete g_GameAttributes.settings.LastManStanding; | ||||
delete g_GameAttributes.settings.RegicideGarrison; | delete g_GameAttributes.settings.RegicideGarrison; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | function launchGame() | ||||
if (!g_GameAttributes.map) | if (!g_GameAttributes.map) | ||||
return; | return; | ||||
savePersistMatchSettings(); | savePersistMatchSettings(); | ||||
// Select random map | // Select random map | ||||
if (g_GameAttributes.map == "random") | if (g_GameAttributes.map == "random") | ||||
{ | |||||
let victoryScriptsSelected = g_GameAttributes.settings.VictoryScripts; | |||||
let gameTypeSelected = g_GameAttributes.settings.GameType; | |||||
selectMap(pickRandom(g_Dropdowns.mapSelection.ids().slice(1))); | selectMap(pickRandom(g_Dropdowns.mapSelection.ids().slice(1))); | ||||
g_GameAttributes.settings.VictoryScripts = victoryScriptsSelected; | |||||
g_GameAttributes.settings.GameType = gameTypeSelected; | |||||
} | |||||
if (g_GameAttributes.settings.Biome == "random") | if (g_GameAttributes.settings.Biome == "random") | ||||
g_GameAttributes.settings.Biome = pickRandom( | g_GameAttributes.settings.Biome = pickRandom( | ||||
typeof g_GameAttributes.settings.SupportedBiomes == "string" ? | typeof g_GameAttributes.settings.SupportedBiomes == "string" ? | ||||
g_BiomeList.Id.slice(1).filter(biomeID => biomeID.startsWith(g_GameAttributes.settings.SupportedBiomes)) : | g_BiomeList.Id.slice(1).filter(biomeID => biomeID.startsWith(g_GameAttributes.settings.SupportedBiomes)) : | ||||
g_GameAttributes.settings.SupportedBiomes); | g_GameAttributes.settings.SupportedBiomes); | ||||
let victoryScripts = []; | |||||
Done Inline ActionsvictoryScripts or victoryConditionTriggerScripts should do if you want elexis: victoryScripts or victoryConditionTriggerScripts should do if you want | |||||
for (let vc of g_GameAttributes.settings.VictoryConditions) | |||||
victoryScripts = victoryScripts.concat(g_VictoryConditions[g_VictoryConditions.map(data => data.Name).indexOf(vc)].Scripts); | |||||
Not Done Inline Actionscould be uglified with a reduce elexis: could be uglified with a `reduce` | |||||
Done Inline Actions.reduce? Probably not unreasonable to do the uniqueness check before pushing the new scripts elexis: .reduce? Probably not unreasonable to do the uniqueness check before pushing the new scripts | |||||
Not Done Inline ActionsNice. bit complex, but I can trump that with the statue code on jebel barkal :P elexis: Nice. bit complex, but I can trump that with the statue code on jebel barkal :P | |||||
g_GameAttributes.settings.VictoryScripts = victoryScripts.filter((vc, i) => victoryScripts.indexOf(vc) == i) | |||||
Not Done Inline ActionsNote to self: test for persistmatchsettings / changemap persistsettings doom elexis: Note to self: test for persistmatchsettings / changemap persistsettings doom | |||||
bbAuthorUnsubmitted Not Done Inline Actionsmissing semicolon bb: missing semicolon | |||||
g_GameAttributes.settings.TriggerScripts = g_GameAttributes.settings.VictoryScripts.concat(g_GameAttributes.settings.TriggerScripts || []); | g_GameAttributes.settings.TriggerScripts = g_GameAttributes.settings.VictoryScripts.concat(g_GameAttributes.settings.TriggerScripts || []); | ||||
// Prevent reseting the readystate | // Prevent reseting the readystate | ||||
g_GameStarted = true; | g_GameStarted = true; | ||||
g_GameAttributes.settings.mapType = g_GameAttributes.mapType; | g_GameAttributes.settings.mapType = g_GameAttributes.mapType; | ||||
// Get a unique array of selectable cultures | // Get a unique array of selectable cultures | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | for (let name in g_PlayerDropdowns) | ||||
updateGUIDropdown(name, i); | updateGUIDropdown(name, i); | ||||
for (let name in g_PlayerMiscElements) | for (let name in g_PlayerMiscElements) | ||||
updateGUIMiscControl(name, i); | updateGUIMiscControl(name, i); | ||||
} | } | ||||
for (let name in g_MiscControls) | for (let name in g_MiscControls) | ||||
updateGUIMiscControl(name); | updateGUIMiscControl(name); | ||||
Done Inline Actionskeep elexis: keep | |||||
updateGameDescription(); | updateGameDescription(); | ||||
distributeSettings(); | distributeSettings(); | ||||
rightAlignCancelButton(); | rightAlignCancelButton(); | ||||
updateAutocompleteEntries(); | updateAutocompleteEntries(); | ||||
g_IsInGuiUpdate = false; | g_IsInGuiUpdate = false; | ||||
// Refresh AI config page | // Refresh AI config page | ||||
▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Lines | function sendRegisterGameStanzaImmediate() | ||||
let stanza = { | let stanza = { | ||||
"name": g_ServerName, | "name": g_ServerName, | ||||
"port": g_ServerPort, | "port": g_ServerPort, | ||||
"hostUsername": Engine.LobbyGetNick(), | "hostUsername": Engine.LobbyGetNick(), | ||||
"mapName": g_GameAttributes.map, | "mapName": g_GameAttributes.map, | ||||
"niceMapName": getMapDisplayName(g_GameAttributes.map), | "niceMapName": getMapDisplayName(g_GameAttributes.map), | ||||
"mapSize": g_GameAttributes.mapType == "random" ? g_GameAttributes.settings.Size : "Default", | "mapSize": g_GameAttributes.mapType == "random" ? g_GameAttributes.settings.Size : "Default", | ||||
"mapType": g_GameAttributes.mapType, | "mapType": g_GameAttributes.mapType, | ||||
"victoryCondition": g_GameAttributes.settings.GameType, | "victoryConditions": g_GameAttributes.settings.VictoryConditions.map(vc => translateVictoryCondition(vc)).join(", "), | ||||
Not Done Inline Actionsmissing translate elexis: missing translate | |||||
Not Done Inline ActionsYou mean the .join(", ")? but how should it be translated (I never came across a translateList function or equivalent)? bb: You mean the `.join(", ")`? but how should it be translated (I never came across a… | |||||
Not Done Inline ActionsJust a literally missing translate, i.e. .join(translate(", ")). We have some variants in our codebase already, IIRC with translation context elexis: Just a literally missing translate, i.e. `.join(translate(", "))`. We have some variants in our… | |||||
Not Done Inline Actionsok, but removing the translate here again, since this is the data send to the lobby bot, which shouldn't be translated (it should be translated in the lobby code, currently unused) bb: ok, but removing the translate here again, since this is the data send to the lobby bot, which… | |||||
Not Done Inline Actionsack elexis: ack | |||||
"nbp": clients.connectedPlayers, | "nbp": clients.connectedPlayers, | ||||
"maxnbp": g_GameAttributes.settings.PlayerData.length, | "maxnbp": g_GameAttributes.settings.PlayerData.length, | ||||
"players": clients.list, | "players": clients.list, | ||||
"stunIP": g_StunEndpoint ? g_StunEndpoint.ip : "", | "stunIP": g_StunEndpoint ? g_StunEndpoint.ip : "", | ||||
"stunPort": g_StunEndpoint ? g_StunEndpoint.port : "", | "stunPort": g_StunEndpoint ? g_StunEndpoint.port : "", | ||||
"mods": JSON.stringify(Engine.GetEngineInfo().mods), | "mods": JSON.stringify(Engine.GetEngineInfo().mods), | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |
No newlines besides the consts, one newline before the first var?