Changeset View
Standalone View
binaries/data/mods/public/gui/summary/summary.js
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Translation: Unicode encoded infinity symbol indicating a division by zero in the summary screen. | * Translation: Unicode encoded infinity symbol indicating a division by zero in the summary screen. | ||||
*/ | */ | ||||
var g_InfinitySymbol = translate("\u221E"); | var g_InfinitySymbol = translate("\u221E"); | ||||
var g_Teams = []; | var g_Teams = []; | ||||
// TODO set g_PlayerCount as playerCounters.length | // TODO set g_PlayerCount as playerCounters.length | ||||
var g_PlayerCount = 0; | var g_PlayerCount = 0; | ||||
bb: cap the comment | |||||
var g_GameData; | var g_GameData; | ||||
var g_ResourceData = new Resources(); | var g_ResourceData = new Resources(); | ||||
// Selected chart indexes | // Selected chart indexes | ||||
var g_SelectedChart = { | var g_SelectedChart = { | ||||
"category": [0, 0], | "category": [0, 0], | ||||
"value": [0, 0], | "value": [0, 0], | ||||
Not Done Inline Actionsspaces around + bb: spaces around `+` | |||||
"type": [0, 0] | "type": [0, 0] | ||||
}; | }; | ||||
Not Done Inline ActionsThis system is driving on the fact there is exactly one such panel. It would be better to make a g_OtherPanels = ["charts"] in layout.js and concat that one with the object.keys array. from that we can then work our way to get the wanted behaviour (going to the next, except when last tab the first) bb: This system is driving on the fact there is exactly one such panel. It would be better to make… | |||||
Not Done Inline Actionsmake jsDoc and period bb: make jsDoc and period | |||||
Done Inline Actionsthis is the 5st time the same array of object keys is used, perhaps store it? bb: this is the 5st time the same array of object keys is used, perhaps store it? | |||||
/* | |||||
Not Done Inline ActionsWith the exception of typed arrays, there is only one JS number type I'm aware of and that's called number. The comment implies the type, so the type definition could be avoided too. elexis: With the exception of typed arrays, there is only one JS number type I'm aware of and that's… | |||||
* Array of the panel button names. | |||||
Not Done Inline Actionslet => var bb: let => var | |||||
*/ | |||||
var g_PanelButtons = []; | |||||
/* | |||||
Not Done Inline ActionsNotice this check is correct, but not required, however its good for optimization I guess, so meh => just keep the check bb: Notice this check is correct, but not required, however its good for optimization I guess, so… | |||||
* Remember the name of the currently opened view panel. | |||||
Not Done Inline Actionslet i = 0; i < panels.length; ++i ? (That way the +i below can become just i) bb: let i = 0; i < panels.length; ++i ?
(That way the `+i` below can become just `i`) | |||||
Not Done Inline Actionsmaybe is correct, maybe not: why do we need to have g_DefaultPanel? and can't we just set here g_ViewPanel = "scorePanelButton" and then just let the init overwrite that when it wants to (like it already does). bb: maybe is correct, maybe not: why do we need to have `g_DefaultPanel`? and can't we just set… | |||||
*/ | |||||
var g_SelectedPanel = undefined; | |||||
elexisUnsubmitted Not Done Inline Actions= undefined; should be removed (we got a linter rule) elexis: `= undefined;` should be removed (we got a linter rule) | |||||
Not Done Inline Actionsmaybe rename to j or so, to avoid confusion bb: maybe rename to j or so, to avoid confusion | |||||
Not Done Inline ActionsShow next/previous panel.? bb: Show next/previous panel.? | |||||
function init(data) | function init(data) | ||||
Not Done Inline Actionsseems to be no need for this => inline bb: seems to be no need for this => inline | |||||
Not Done Inline Actionsnuke [] around direction bb: nuke [] around `direction` | |||||
{ | { | ||||
Not Done Inline Actionsnot sure +i+1 and +i-1 must be with spaces +i + 1 and +i - 1 ffffffff: not sure +i+1 and +i-1 must be with spaces +i + 1 and +i - 1 | |||||
Not Done Inline Actionsmeh ok like this bb: meh ok like this | |||||
Not Done Inline Actionscurrently elexis: currently | |||||
Not Done Inline Actions@elexis reload the page bb: @elexis reload the page | |||||
Not Done Inline Actionseven when we declare let j = 0; instead of let panel = panels[0]; on line 134, this line can be inlined in line 145 bb: even when we declare `let j = 0;` instead of `let panel = panels[0];` on line 134, this line… | |||||
// Fill globals | // Fill globals | ||||
Not Done Inline Actionsnuke the optionality in the argument, just make it a required one and put the 1 in the call bb: nuke the optionality in the argument, just make it a required one and put the `1` in the call | |||||
Not Done Inline ActionsIt is a js disgrace to take the remainder as negative for negative values imo, (index + direction + panels.length) % panels.length bb: It is a js disgrace to take the remainder as negative for negative values imo, `(index +… | |||||
Not Done Inline Actionssee previous comment bb: see previous comment | |||||
g_GameData = data; | g_GameData = data; | ||||
g_ScorePanelsData = getScorePanelsData(); | g_ScorePanelsData = getScorePanelsData(); | ||||
g_PanelButtons = Object.keys(g_ScorePanelsData).concat(["charts"]).map(panel => panel + "PanelButton"); | |||||
Not Done Inline ActionsCorrect since if g_ViewPanel == "" then slicing just remains "" and that is not an element of panels. (Noting for self, no change needed) bb: Correct since if `g_ViewPanel == ""` then slicing just remains `""` and that is not an element… | |||||
g_SelectedPanel = g_PanelButtons[0]; | |||||
Not Done Inline ActionsAww well (index + direction) % panels.length means (index + direction) modulo panels.length So that returns the remainder of dividing (index + direction) by panels.length, in the range [0, panels.length - 1]. So -1 % panels.length returns panels.length - 1 thus so we can remove the second ternary. Also nextIndex is used only once so inline. bb: Aww well `(index + direction) % panels.length` means `(index + direction) modulo panels.length`… | |||||
Not Done Inline Actionsno -1 % panels.length = -1 ffffffff: no
-1 % panels.length = -1 | |||||
if (data && data.selectedData) | |||||
Not Done Inline Actionswhat about index = panels.indexOf(g_ViewPanel.slice(0, -"PanelButton".length)); bb: what about `index = panels.indexOf(g_ViewPanel.slice(0, -"PanelButton".length));` | |||||
{ | |||||
g_SelectedPanel = data.selectedData.panel; | |||||
g_SelectedChart = data.selectedData.charts; | |||||
Not Done Inline Actionsrethinking this: using some modulo calculation and ternary would make the code cleaner so we get i = (g_ViewPanel == "" || index == -1) ? 0 : (index + direction) % panels.length; bb: rethinking this: using some modulo calculation and ternary would make the code cleaner so we… | |||||
bbUnsubmitted Not Done Inline Actions\0/ that has annoyed me a lot bb: \0/ that has annoyed me a lot | |||||
} | |||||
initTeamData(); | initTeamData(); | ||||
calculateTeamCounterDataHelper(); | calculateTeamCounterDataHelper(); | ||||
Not Done Inline ActionsAnd with all that i can and inlined bb: And with all that `i` can and inlined | |||||
Not Done Inline Actionsmaking the function a nice short two liner bb: making the function a nice short two liner | |||||
// Output globals | // Output globals | ||||
Not Done Inline Actionsnewline before bb: newline before | |||||
initPlayerBoxPositions(); | initPlayerBoxPositions(); | ||||
initGUICharts(); | initGUICharts(); | ||||
initGUILabelsAndButtons(); | initGUILabelsAndButtons(); | ||||
selectPanel(Engine.GetGUIObjectByName("scorePanelButton")); | selectPanel(Engine.GetGUIObjectByName(g_SelectedPanel)); | ||||
for (let tab of g_PanelButtons.map(button => Engine.GetGUIObjectByName(button))) | |||||
bbUnsubmitted Not Done Inline Actionsthat is looping twice over the same thing, first in the map then the for. Move the map into the for scope so: for (let button of g_PanelsButton) { tab = Engine.GetGUIObjectByName(button); // (or find a better name for tabObject) blabla() } bb: that is looping twice over the same thing, first in the map then the for. Move the map into the… | |||||
elexisUnsubmitted Not Done Inline Actionsagree elexis: agree | |||||
{ | |||||
tab.onMouseWheelUp = () => selectNextTab(1); | |||||
tab.onMouseWheelDown = () => selectNextTab(-1); | |||||
} | |||||
} | |||||
/* | |||||
* Show next/previous panel. | |||||
* @param direction - 1/-1 forward, backward panel. | |||||
*/ | |||||
function selectNextTab(direction) | |||||
{ | |||||
selectPanel(Engine.GetGUIObjectByName(g_PanelButtons[ | |||||
(g_PanelButtons.indexOf(g_SelectedPanel) + direction + g_PanelButtons.length) % g_PanelButtons.length])); | |||||
} | } | ||||
function selectPanel(panel) | function selectPanel(panel) | ||||
{ | { | ||||
// TODO: move panel buttons to a custom parent object | // TODO: move panel buttons to a custom parent object | ||||
for (let button of Engine.GetGUIObjectByName("summaryWindow").children) | for (let button of Engine.GetGUIObjectByName("summaryWindow").children) | ||||
if (button.name.endsWith("PanelButton")) | if (button.name.endsWith("PanelButton")) | ||||
button.sprite = "ModernTabHorizontalBackground"; | button.sprite = "ModernTabHorizontalBackground"; | ||||
panel.sprite = "ModernTabHorizontalForeground"; | panel.sprite = "ModernTabHorizontalForeground"; | ||||
adjustTabDividers(panel.size); | adjustTabDividers(panel.size); | ||||
let generalPanel = Engine.GetGUIObjectByName("generalPanel"); | let generalPanel = Engine.GetGUIObjectByName("generalPanel"); | ||||
let chartsPanel = Engine.GetGUIObjectByName("chartsPanel"); | let chartsPanel = Engine.GetGUIObjectByName("chartsPanel"); | ||||
let chartsHidden = panel.name != "chartsPanelButton"; | let chartsHidden = panel.name != "chartsPanelButton"; | ||||
generalPanel.hidden = !chartsHidden; | generalPanel.hidden = !chartsHidden; | ||||
chartsPanel.hidden = chartsHidden; | chartsPanel.hidden = chartsHidden; | ||||
if (chartsHidden) | if (chartsHidden) | ||||
updatePanelData(g_ScorePanelsData[panel.name.substr(0, panel.name.length - "PanelButton".length)]); | updatePanelData(g_ScorePanelsData[panel.name.substr(0, panel.name.length - "PanelButton".length)]); | ||||
else | else | ||||
[0, 1].forEach(updateCategoryDropdown); | [0, 1].forEach(updateCategoryDropdown); | ||||
g_SelectedPanel = panel.name; | |||||
} | } | ||||
function initGUICharts() | function initGUICharts() | ||||
{ | { | ||||
let player_colors = []; | let player_colors = []; | ||||
for (let i = 1; i <= g_PlayerCount; ++i) | for (let i = 1; i <= g_PlayerCount; ++i) | ||||
{ | { | ||||
let playerState = g_GameData.sim.playerStates[i]; | let playerState = g_GameData.sim.playerStates[i]; | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | if (playerState.team != -1) | ||||
rowPlayer = "playerBoxt[" + playerState.team + "][" + positionObject + "]"; | rowPlayer = "playerBoxt[" + playerState.team + "][" + positionObject + "]"; | ||||
playerOutcome = "playerOutcomet[" + playerState.team + "][" + positionObject + "]"; | playerOutcome = "playerOutcomet[" + playerState.team + "][" + positionObject + "]"; | ||||
playerNameColumn = "playerNamet[" + playerState.team + "][" + positionObject + "]"; | playerNameColumn = "playerNamet[" + playerState.team + "][" + positionObject + "]"; | ||||
playerCivicBoxColumn = "civIcont[" + playerState.team + "][" + positionObject + "]"; | playerCivicBoxColumn = "civIcont[" + playerState.team + "][" + positionObject + "]"; | ||||
playerCounterValue = "valueDataTeam[" + playerState.team + "][" + positionObject + "]"; | playerCounterValue = "valueDataTeam[" + playerState.team + "][" + positionObject + "]"; | ||||
} | } | ||||
let colorString = "color: " + | let colorString = "color: " + | ||||
Math.floor(playerState.color.r * 255) + " " + | Math.floor(playerState.color.r * 255) + " " + | ||||
Not Done Inline Actions{ "bbLint": "on", "needsFix": true, "errorType": "objectSpaces" } bb: { "bbLint": "on", "needsFix": true, "errorType": "objectSpaces" } | |||||
Math.floor(playerState.color.g * 255) + " " + | Math.floor(playerState.color.g * 255) + " " + | ||||
Math.floor(playerState.color.b * 255); | Math.floor(playerState.color.b * 255); | ||||
let rowPlayerObject = Engine.GetGUIObjectByName(rowPlayer); | let rowPlayerObject = Engine.GetGUIObjectByName(rowPlayer); | ||||
rowPlayerObject.hidden = false; | rowPlayerObject.hidden = false; | ||||
rowPlayerObject.sprite = colorString + " " + g_PlayerBoxAlpha; | rowPlayerObject.sprite = colorString + " " + g_PlayerBoxAlpha; | ||||
let boxSize = rowPlayerObject.size; | let boxSize = rowPlayerObject.size; | ||||
Show All 27 Lines | messageBox( | ||||
[null, startReplay] | [null, startReplay] | ||||
); | ); | ||||
else | else | ||||
startReplay(); | startReplay(); | ||||
} | } | ||||
function continueButton() | function continueButton() | ||||
{ | { | ||||
let summarySelectedData = { | |||||
"panel": g_SelectedPanel, | |||||
"charts": g_SelectedChart | |||||
}; | |||||
if (g_GameData.gui.isInGame) | if (g_GameData.gui.isInGame) | ||||
Engine.PopGuiPageCB(0); | Engine.PopGuiPageCB({ | ||||
"explicitResume": 0, | |||||
"summarySelectedData": summarySelectedData | |||||
}); | |||||
else if (g_GameData.gui.isReplay) | else if (g_GameData.gui.isReplay) | ||||
Engine.SwitchGuiPage("page_replaymenu.xml", { | Engine.SwitchGuiPage("page_replaymenu.xml", { | ||||
"replaySelectionData": g_GameData.gui.replaySelectionData | "replaySelectionData": g_GameData.gui.replaySelectionData, | ||||
"summarySelectedData": summarySelectedData | |||||
}); | }); | ||||
else if (Engine.HasXmppClient()) | else if (Engine.HasXmppClient()) | ||||
Engine.SwitchGuiPage("page_lobby.xml"); | Engine.SwitchGuiPage("page_lobby.xml"); | ||||
else | else | ||||
Engine.SwitchGuiPage("page_pregame.xml"); | Engine.SwitchGuiPage("page_pregame.xml"); | ||||
} | } | ||||
function startReplay() | function startReplay() | ||||
Show All 20 Lines | Engine.SwitchGuiPage("page_loading.xml", { | ||||
"isReplay": true, | "isReplay": true, | ||||
"replaySelectionData": g_GameData.gui.replaySelectionData | "replaySelectionData": g_GameData.gui.replaySelectionData | ||||
}); | }); | ||||
} | } | ||||
function initGUILabelsAndButtons() | function initGUILabelsAndButtons() | ||||
{ | { | ||||
let assignedState = g_GameData.sim.playerStates[g_GameData.gui.assignedPlayer || -1]; | let assignedState = g_GameData.sim.playerStates[g_GameData.gui.assignedPlayer || -1]; | ||||
Not Done Inline Actionsnope bb: nope | |||||
Engine.GetGUIObjectByName("summaryText").caption = | Engine.GetGUIObjectByName("summaryText").caption = | ||||
g_GameData.gui.isInGame ? | g_GameData.gui.isInGame ? | ||||
translate("Current Scores") : | translate("Current Scores") : | ||||
g_GameData.gui.isReplay ? | g_GameData.gui.isReplay ? | ||||
translate("Scores at the end of the game.") : | translate("Scores at the end of the game.") : | ||||
g_GameData.gui.disconnected ? | g_GameData.gui.disconnected ? | ||||
translate("You have been disconnected.") : | translate("You have been disconnected.") : | ||||
!assignedState ? | !assignedState ? | ||||
Show All 11 Lines | function initGUILabelsAndButtons() | ||||
let mapType = g_Settings.MapTypes.find(type => type.Name == g_GameData.sim.mapSettings.mapType); | let mapType = g_Settings.MapTypes.find(type => type.Name == g_GameData.sim.mapSettings.mapType); | ||||
let mapSize = g_Settings.MapSizes.find(size => size.Tiles == g_GameData.sim.mapSettings.Size || 0); | let mapSize = g_Settings.MapSizes.find(size => size.Tiles == g_GameData.sim.mapSettings.Size || 0); | ||||
Engine.GetGUIObjectByName("mapName").caption = sprintf( | Engine.GetGUIObjectByName("mapName").caption = sprintf( | ||||
translate("%(mapName)s - %(mapType)s"), { | translate("%(mapName)s - %(mapType)s"), { | ||||
"mapName": translate(g_GameData.sim.mapSettings.Name), | "mapName": translate(g_GameData.sim.mapSettings.Name), | ||||
"mapType": mapSize ? mapSize.Name : (mapType ? mapType.Title : "") | "mapType": mapSize ? mapSize.Name : (mapType ? mapType.Title : "") | ||||
}); | }); | ||||
Not Done Inline ActionsAs we use this thing twice now Object.keys(g_ScorePanelsData).concat(["charts"]) make it a global, also do Object.keys(g_ScorePanelsData).push("charts") bb: As we use this thing twice now `Object.keys(g_ScorePanelsData).concat(["charts"])` make it a… | |||||
Not Done Inline Actionscant use push when afterwards wanna use another function on return cause push doesnt return an array. can concat stay? ffffffff: cant use push when afterwards wanna use another function on return cause push doesnt return an… | |||||
Not Done Inline Actions"scorePanelButton" looks like a magical value to me => put it in a global g_DefaultPanel bb: "scorePanelButton" looks like a magical value to me => put it in a global `g_DefaultPanel` | |||||
Not Done Inline ActionsWhen being in the little space between the buttons, the scrolling doesn't work, probably just meh, since it would run in some inconsistencies when we allow it. bb: When being in the little space between the buttons, the scrolling doesn't work, probably just… | |||||
Not Done Inline ActionsNice, didn't notice so far. Would also be useful in the other GUI pages with tabs and consistent. elexis: Nice, didn't notice so far. Would also be useful in the other GUI pages with tabs and… | |||||
Engine.GetGUIObjectByName("replayButton").hidden = g_GameData.gui.isInGame || !g_GameData.gui.replayDirectory; | Engine.GetGUIObjectByName("replayButton").hidden = g_GameData.gui.isInGame || !g_GameData.gui.replayDirectory; | ||||
} | } | ||||
Not Done Inline Actionswith removing g_DefaultPanel this would simplify to selectPanel(Engine.GetGUIObjectByName(g_ViewPanel)); bb: with removing `g_DefaultPanel` this would simplify to `selectPanel(Engine.GetGUIObjectByName… | |||||
function initTeamData() | function initTeamData() | ||||
{ | { | ||||
// Panels | // Panels | ||||
g_PlayerCount = g_GameData.sim.playerStates.length - 1; | g_PlayerCount = g_GameData.sim.playerStates.length - 1; | ||||
Not Done Inline Actionssome more juice here. ffffffff: some more juice here.
go next/prev panel on mouse scroll wheel up/down over the tab buttons. | |||||
Not Done Inline ActionsThat should be documented too in the intro.txt Note to self: add things to the wiki when committed bb: That should be documented too in the intro.txt
Note to self: add things to the wiki when… | |||||
if (g_GameData.sim.mapSettings.LockTeams) | if (g_GameData.sim.mapSettings.LockTeams) | ||||
{ | { | ||||
Not Done Inline Actionswould be better to swap negate the statement and swap the cases bb: would be better to swap negate the statement and swap the cases
`g_ViewPanel == "" ? | |||||
// Count teams | // Count teams | ||||
for (let player = 1; player <= g_PlayerCount; ++player) | for (let player = 1; player <= g_PlayerCount; ++player) | ||||
{ | { | ||||
let playerTeam = g_GameData.sim.playerStates[player].team; | let playerTeam = g_GameData.sim.playerStates[player].team; | ||||
if (!g_Teams[playerTeam]) | if (!g_Teams[playerTeam]) | ||||
g_Teams[playerTeam] = []; | g_Teams[playerTeam] = []; | ||||
g_Teams[playerTeam].push(player); | g_Teams[playerTeam].push(player); | ||||
} | } | ||||
if (g_Teams.every(team => team && team.length < 2)) | if (g_Teams.every(team => team && team.length < 2)) | ||||
g_Teams = false; // Each player has his own team. Displaying teams makes no sense. | g_Teams = false; // Each player has his own team. Displaying teams makes no sense. | ||||
} | } | ||||
else | else | ||||
g_Teams = false; | g_Teams = false; | ||||
// Erase teams data if teams are not displayed | // Erase teams data if teams are not displayed | ||||
if (!g_Teams) | if (!g_Teams) | ||||
for (let p = 0; p < g_PlayerCount; ++p) | for (let p = 0; p < g_PlayerCount; ++p) | ||||
g_GameData.sim.playerStates[p+1].team = -1; | g_GameData.sim.playerStates[p+1].team = -1; | ||||
} | } | ||||
Not Done Inline Actionsk => button bb: `k` => `button` |
cap the comment