Changeset View
Standalone View
binaries/data/mods/public/gui/summary/summary.js
Show First 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | function init(data) | ||||
{ | { | ||||
g_SelectedPanel = data.selectedData.panel; | g_SelectedPanel = data.selectedData.panel; | ||||
g_SelectedChart = data.selectedData.charts; | g_SelectedChart = data.selectedData.charts; | ||||
} | } | ||||
initTeamData(); | initTeamData(); | ||||
calculateTeamCounterDataHelper(); | calculateTeamCounterDataHelper(); | ||||
Engine.GetGUIObjectByName("toggleTeamBox").checked = g_Teams && | |||||
data && data.selectedData && data.selectedData.teamCharts; | |||||
// Output globals | // Output globals | ||||
initGUIWindow(); | initGUIWindow(); | ||||
initPlayerBoxPositions(); | initPlayerBoxPositions(); | ||||
initGUICharts(); | initGUICharts(); | ||||
initGUILabels(); | initGUILabels(); | ||||
initGUIButtons(); | initGUIButtons(); | ||||
selectPanel(Engine.GetGUIObjectByName(g_SelectedPanel)); | selectPanel(Engine.GetGUIObjectByName(g_SelectedPanel)); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | function selectPanel(panel) | ||||
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; | g_SelectedPanel = panel.name; | ||||
} | } | ||||
function initGUICharts() | function updateChartColorAndLegend() | ||||
{ | { | ||||
let player_colors = []; | let playerColors = []; | ||||
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]; | ||||
player_colors.push( | playerColors.push( | ||||
Math.floor(playerState.color.r * 255) + " " + | Math.floor(playerState.color.r * 255) + " " + | ||||
Math.floor(playerState.color.g * 255) + " " + | Math.floor(playerState.color.g * 255) + " " + | ||||
Math.floor(playerState.color.b * 255) | Math.floor(playerState.color.b * 255) | ||||
); | ); | ||||
} | } | ||||
for (let i = 0; i < 2; ++i) | for (let i = 0; i < 2; ++i) | ||||
Engine.GetGUIObjectByName("chart[" + i + "]").series_color = player_colors; | Engine.GetGUIObjectByName("chart[" + i + "]").series_color = | ||||
Engine.GetGUIObjectByName("toggleTeamBox").checked ? | |||||
g_Teams.filter(el => el !== null).map(players => playerColors[players[0] - 1]) : | |||||
Stan: Could probably cache g_Teams.filter(el => el !== null) instead of computing it multiple times. | |||||
Done Inline ActionsI don't think so, because g_Teams can be either an Array or false. Imarok: I don't think so, because g_Teams can be either an Array or `false`.
(We could add a second… | |||||
playerColors; | |||||
let chartLegend = Engine.GetGUIObjectByName("chartLegend"); | let chartLegend = Engine.GetGUIObjectByName("chartLegend"); | ||||
chartLegend.caption = g_GameData.sim.playerStates.slice(1).map( | chartLegend.caption = Engine.GetGUIObjectByName("toggleTeamBox").checked ? | ||||
(state, index) => coloredText("■", player_colors[index]) + " " + state.name | g_Teams.filter(el => el !== null).map( | ||||
players => coloredText("■", playerColors[players[0] - 1]) + " " + players.map(player => | |||||
Done Inline Actionsno translate? Stan: no translate? | |||||
Done Inline ActionsHmm, I think we couldn't do the coloring of only the square then, right? Imarok: Hmm, I think we couldn't do the coloring of only the square then, right?
| |||||
Done Inline ActionsAlso maybe setStringTags instead of coloredText (D2151)? Freagarach: Also maybe `setStringTags` instead of `coloredText` (D2151)? | |||||
g_GameData.sim.playerStates[player].name | |||||
).join(translateWithContext("Player listing", ", ")) | |||||
).join(" ") : | |||||
g_GameData.sim.playerStates.slice(1).map( | |||||
(state, index) => coloredText("■", playerColors[index]) + " " + state.name | |||||
).join(" "); | ).join(" "); | ||||
} | |||||
function initGUICharts() | |||||
{ | |||||
updateChartColorAndLegend(); | |||||
let chart1Part = Engine.GetGUIObjectByName("chart[1]Part"); | let chart1Part = Engine.GetGUIObjectByName("chart[1]Part"); | ||||
let chart1PartSize = chart1Part.size; | let chart1PartSize = chart1Part.size; | ||||
chart1PartSize.rright += 50; | chart1PartSize.rright += 50; | ||||
chart1PartSize.rleft += 50; | chart1PartSize.rleft += 50; | ||||
chart1PartSize.right -= 5; | chart1PartSize.right -= 5; | ||||
chart1PartSize.left -= 5; | chart1PartSize.left -= 5; | ||||
chart1Part.size = chart1PartSize; | chart1Part.size = chart1PartSize; | ||||
Engine.GetGUIObjectByName("toggleTeam").hidden = !g_Teams; | |||||
} | } | ||||
function resizeDropdown(dropdown) | function resizeDropdown(dropdown) | ||||
{ | { | ||||
let size = dropdown.size; | let size = dropdown.size; | ||||
size.bottom = dropdown.size.top + | size.bottom = dropdown.size.top + | ||||
(Engine.GetTextWidth(dropdown.font, dropdown.list[dropdown.selected]) > | (Engine.GetTextWidth(dropdown.font, dropdown.list[dropdown.selected]) > | ||||
dropdown.size.right - dropdown.size.left - 32 ? 42 : 27); | dropdown.size.right - dropdown.size.left - 32 ? 42 : 27); | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||
function updateChart(number, category, item, itemNumber, type) | function updateChart(number, category, item, itemNumber, type) | ||||
{ | { | ||||
if (!g_ScorePanelsData[category].counters[itemNumber].fn) | if (!g_ScorePanelsData[category].counters[itemNumber].fn) | ||||
return; | return; | ||||
let chart = Engine.GetGUIObjectByName("chart[" + number + "]"); | let chart = Engine.GetGUIObjectByName("chart[" + number + "]"); | ||||
chart.format_y = g_ScorePanelsData[category].headings[itemNumber + 1].format || "INTEGER"; | chart.format_y = g_ScorePanelsData[category].headings[itemNumber + 1].format || "INTEGER"; | ||||
Engine.GetGUIObjectByName("chart[" + number + "]XAxisLabel").caption = translate("Time elapsed"); | Engine.GetGUIObjectByName("chart[" + number + "]XAxisLabel").caption = translate("Time elapsed"); | ||||
let series = []; | let series = []; | ||||
if (Engine.GetGUIObjectByName("toggleTeamBox").checked) | |||||
for (let team in g_Teams) | |||||
{ | |||||
let data = []; | |||||
for (let index in g_GameData.sim.playerStates[1].sequences.time) | |||||
{ | |||||
let value = g_ScorePanelsData[category].teamCounterFn(team, index, item, | |||||
g_ScorePanelsData[category].counters, g_ScorePanelsData[category].headings); | |||||
if (type) | |||||
value = value[type]; | |||||
data.push([g_GameData.sim.playerStates[1].sequences.time[index], value]); | |||||
} | |||||
series.push(data); | |||||
} | |||||
else | |||||
for (let j = 1; j <= g_PlayerCount; ++j) | for (let j = 1; j <= g_PlayerCount; ++j) | ||||
{ | { | ||||
let playerState = g_GameData.sim.playerStates[j]; | let playerState = g_GameData.sim.playerStates[j]; | ||||
let data = []; | let data = []; | ||||
for (let index in playerState.sequences.time) | for (let index in playerState.sequences.time) | ||||
{ | { | ||||
let value = g_ScorePanelsData[category].counters[itemNumber].fn(playerState, index, item); | let value = g_ScorePanelsData[category].counters[itemNumber].fn(playerState, index, item); | ||||
if (type) | if (type) | ||||
value = value[type]; | value = value[type]; | ||||
data.push([playerState.sequences.time[index], value]); | data.push([playerState.sequences.time[index], value]); | ||||
} | } | ||||
series.push(data); | series.push(data); | ||||
} | } | ||||
Not Done Inline ActionsIf I'm not mistaken the duplication should be reducible. (There are some differences, but it should be possible to pass them as arguments) elexis: If I'm not mistaken the duplication should be reducible. (There are some differences, but it… | |||||
Done Inline ActionsI thought about that when writing the code, but came to the conclusion that it's too different to make a deduplication produce a straight-forward result:
Imarok: I thought about that when writing the code, but came to the conclusion that it's too different… | |||||
Not Done Inline Actionsif (Engine.GetGUIObjectByName("toggleTeamBox").checked) for (let team in g_Teams) { let playerState = g_GameData.sim.playerStates[1]; let valueFunction = (...) => g_ScorePanelsData[category].teamCounterFn(team, index, item, g_ScorePanelsData[category].counters, g_ScorePanelsData[category].headings); for (let index in playerState.sequences.time) constructValueThingSwearword(playerState, valueFunction); } else for (let j = 1; j <= g_PlayerCount; ++j) { let playerState = g_GameData.sim.playerStates[j]; let valueFunction = (...) => g_ScorePanelsData[category].counters[itemNumber].fn(playerState, index, item); constructValueThingSwearword(playerState, valueFunction); } function constructValueThingSwearword(playerState, valueFunction) { let data = []; for (let index in playerState.sequences.time) { let value = valueFunction(...); if (type) value = value[type]; data.push([playerState.sequences.time[index], value]); } series.push(data); } I don't mind if this is rejected with prejudice or used and credited (or anything else anyone could care about) elexis: ```
if (Engine.GetGUIObjectByName("toggleTeamBox").checked)
for (let team in g_Teams)
{… | |||||
Done Inline ActionsAnd that won't work because teamCounterFn and fn are called with different arguments. Imarok: And that won't work because `teamCounterFn` and `fn` are called with different arguments.
And… | |||||
Not Done Inline ActionsNot if you pass a function instead of a number/string/object as argument and have the swearword function call that function with all arguments the two callers use, afaics. elexis: Not if you pass a function instead of a number/string/object as argument and have the swearword… | |||||
Not Done Inline ActionsBasically resolve (...) and we can say for sure if its good or not, but it looks good to me since exactly the duplicate part is abstracted, which means it's not only less lines to read but also less complex, less nesting. elexis: Basically resolve (...) and we can say for sure if its good or not, but it looks good to me… | |||||
Not Done Inline Actionsand less fragmentation (since the shared code and unique code are on alternating lines, with the function, they are separated into one group per logic layer), if successful elexis: and less fragmentation (since the shared code and unique code are on alternating lines, with… | |||||
Done Inline ActionsI don't get your point. Imarok: I don't get your point.
In one case we have to do
`valueFunction(team, index, item… | |||||
chart.series = series; | chart.series = series; | ||||
} | } | ||||
function adjustTabDividers(tabSize) | function adjustTabDividers(tabSize) | ||||
{ | { | ||||
let leftSpacer = Engine.GetGUIObjectByName("tabDividerLeft"); | let leftSpacer = Engine.GetGUIObjectByName("tabDividerLeft"); | ||||
let rightSpacer = Engine.GetGUIObjectByName("tabDividerRight"); | let rightSpacer = Engine.GetGUIObjectByName("tabDividerRight"); | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | function updatePanelData(panelInfo) | ||||
if (g_Teams && teamCounterFn) | if (g_Teams && teamCounterFn) | ||||
updateCountersTeam(teamCounterFn, panelInfo.counters, panelInfo.headings, index); | updateCountersTeam(teamCounterFn, panelInfo.counters, panelInfo.headings, index); | ||||
} | } | ||||
function continueButton() | function continueButton() | ||||
{ | { | ||||
let summarySelectedData = { | let summarySelectedData = { | ||||
"panel": g_SelectedPanel, | "panel": g_SelectedPanel, | ||||
"charts": g_SelectedChart | "charts": g_SelectedChart, | ||||
"teamCharts": Engine.GetGUIObjectByName("toggleTeamBox").checked | |||||
}; | }; | ||||
if (g_GameData.gui.isInGame) | if (g_GameData.gui.isInGame) | ||||
Engine.PopGuiPageCB({ | Engine.PopGuiPageCB({ | ||||
"explicitResume": 0, | "explicitResume": 0, | ||||
"summarySelectedData": summarySelectedData | "summarySelectedData": summarySelectedData | ||||
}); | }); | ||||
else if (g_GameData.gui.dialog) | else if (g_GameData.gui.dialog) | ||||
Engine.PopGuiPage(); | Engine.PopGuiPage(); | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |
Could probably cache g_Teams.filter(el => el !== null) instead of computing it multiple times.