Changeset View
Standalone View
binaries/data/mods/public/gui/session/session.js
Show First 20 Lines • Show All 259 Lines • ▼ Show 20 Lines | function init(initData, hotloadData) | ||||
{ | { | ||||
g_ReplaySelectionData = initData.replaySelectionData; | g_ReplaySelectionData = initData.replaySelectionData; | ||||
g_HasRejoined = initData.isRejoining; | g_HasRejoined = initData.isRejoining; | ||||
if (initData.savedGUIData) | if (initData.savedGUIData) | ||||
restoreSavedGameData(initData.savedGUIData); | restoreSavedGameData(initData.savedGUIData); | ||||
} | } | ||||
if (g_GameAttributes.campaignData) | |||||
g_CampaignSession = new CampaignSession(g_GameAttributes.campaignData); | |||||
let mapCache = new MapCache(); | let mapCache = new MapCache(); | ||||
g_Cheats = new Cheats(); | g_Cheats = new Cheats(); | ||||
g_DiplomacyColors = new DiplomacyColors(); | g_DiplomacyColors = new DiplomacyColors(); | ||||
g_PlayerViewControl = new PlayerViewControl(); | g_PlayerViewControl = new PlayerViewControl(); | ||||
g_PlayerViewControl.registerViewedPlayerChangeHandler(g_DiplomacyColors.updateDisplayedPlayerColors.bind(g_DiplomacyColors)); | g_PlayerViewControl.registerViewedPlayerChangeHandler(g_DiplomacyColors.updateDisplayedPlayerColors.bind(g_DiplomacyColors)); | ||||
g_DiplomacyColors.registerDiplomacyColorsChangeHandler(g_PlayerViewControl.rebuild.bind(g_PlayerViewControl)); | g_DiplomacyColors.registerDiplomacyColorsChangeHandler(g_PlayerViewControl.rebuild.bind(g_PlayerViewControl)); | ||||
g_DiplomacyColors.registerDiplomacyColorsChangeHandler(updateGUIObjects); | g_DiplomacyColors.registerDiplomacyColorsChangeHandler(updateGUIObjects); | ||||
g_PauseControl = new PauseControl(); | g_PauseControl = new PauseControl(); | ||||
▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | function endGame() | ||||
let simData = Engine.GuiInterfaceCall("GetReplayMetadata"); | let simData = Engine.GuiInterfaceCall("GetReplayMetadata"); | ||||
let playerID = Engine.GetPlayerID(); | let playerID = Engine.GetPlayerID(); | ||||
Engine.EndGame(); | Engine.EndGame(); | ||||
// After the replay file was closed in EndGame | // After the replay file was closed in EndGame | ||||
// Done here to keep EndGame small | // Done here to keep EndGame small | ||||
if (!g_IsReplay) | if (!g_IsReplay) | ||||
Engine.AddReplayToCache(replayDirectory); | Engine.AddReplayToCache(replayDirectory); | ||||
elexis: This function (`leaveGame`) is called when clicking on Menu -> Exit, when having officially won… | |||||
Not Done Inline ActionsThis assignment looks troublesome. The init attributes should never be changed. I guess one receives a copy instead of a deeply frozen reference. Engine.GetInitAttributes().campaignData duplo One could also examine whether passing Engine.GetInitAttributes() entirely to the summary screen would be good or bad. elexis: This assignment looks troublesome. The init attributes should never be changed. I guess one… | |||||
Not Done Inline ActionsPoint 1. still needs to be taken care of. Point 2.a is already dealt with imo, point 2.B could wait… wraitii: Point 1. still needs to be taken care of.
Point 2.a is already dealt with imo, point 2.B could… | |||||
Not Done Inline Actionspoint 1 done wraitii: point 1 done | |||||
if (g_IsController && Engine.HasXmppClient()) | if (g_IsController && Engine.HasXmppClient()) | ||||
Engine.SendUnregisterGame(); | Engine.SendUnregisterGame(); | ||||
Engine.SwitchGuiPage("page_summary.xml", { | let summaryData = { | ||||
"sim": simData, | "sim": simData, | ||||
"gui": { | "gui": { | ||||
"dialog": false, | "dialog": false, | ||||
"assignedPlayer": playerID, | "assignedPlayer": playerID, | ||||
"disconnected": g_Disconnected, | "disconnected": g_Disconnected, | ||||
"isReplay": g_IsReplay, | "isReplay": g_IsReplay, | ||||
"replayDirectory": !g_HasRejoined && replayDirectory, | "replayDirectory": !g_HasRejoined && replayDirectory, | ||||
"replaySelectionData": g_ReplaySelectionData | "replaySelectionData": g_ReplaySelectionData | ||||
} | } | ||||
}); | }; | ||||
Not Done Inline ActionsSo that's not simulation data? elexis: So that's not simulation data? | |||||
Not Done Inline ActionsI believe (been a while) this data can come from the campaign metadata itself, so keeping it separate makes sense imo. For example a campaign might keep track of how well you are doing, but that's not really 'Sim Data' to me. wraitii: I believe (been a while) this data can come from the campaign metadata itself, so keeping it… | |||||
Not Done Inline ActionsThat data comes from Engine.GetInitAttributes() but that should only contain the gamesettings which determine the simulation. elexis: That data comes from `Engine.GetInitAttributes()` but that should only contain the gamesettings… | |||||
if (g_GameAttributes.campaignData) | |||||
{ | |||||
let menu = g_CampaignSession.getMenu(); | |||||
if (g_GameAttributes.campaignData.skipSummary) | |||||
{ | |||||
Engine.SwitchGuiPage(menu); | |||||
return; | |||||
} | |||||
summaryData.campaignData = { "filename": g_GameAttributes.campaignData.run }; | |||||
summaryData.nextPage = menu; | |||||
} | |||||
Engine.SwitchGuiPage("page_summary.xml", summaryData); | |||||
} | } | ||||
// Return some data that we'll use when hotloading this file after changes | // Return some data that we'll use when hotloading this file after changes | ||||
function getHotloadData() | function getHotloadData() | ||||
{ | { | ||||
return { | return { | ||||
"selection": g_Selection.selected, | "selection": g_Selection.selected, | ||||
"playerAssignments": g_PlayerAssignments, | "playerAssignments": g_PlayerAssignments, | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | function updateGroups() | ||||
}; | }; | ||||
for (let i in Engine.GetGUIObjectByName("unitGroupPanel").children) | for (let i in Engine.GetGUIObjectByName("unitGroupPanel").children) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("unitGroupLabel[" + i + "]").caption = i; | Engine.GetGUIObjectByName("unitGroupLabel[" + i + "]").caption = i; | ||||
let button = Engine.GetGUIObjectByName("unitGroupButton[" + i + "]"); | let button = Engine.GetGUIObjectByName("unitGroupButton[" + i + "]"); | ||||
button.hidden = g_Groups.groups[i].getTotalCount() == 0; | button.hidden = g_Groups.groups[i].getTotalCount() == 0; | ||||
button.onPress = (function(i) { return function() { performGroup((Engine.HotkeyIsPressed("selection.add") ? "add" : "select"), i); }; })(i); | button.onPress = (function(i) { return function() { performGroup((Engine.HotkeyIsPressed("selection.add") ? "add" : "select"), i); }; })(i); | ||||
Lint: ESLintBear (no-shadow) 'i' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'i' is already declared in the upper scope.` | |||||
button.onDoublePress = (function(i) { return function() { performGroup("snap", i); }; })(i); | button.onDoublePress = (function(i) { return function() { performGroup("snap", i); }; })(i); | ||||
Lint: ESLintBear (no-shadow) 'i' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'i' is already declared in the upper scope.` | |||||
button.onPressRight = (function(i) { return function() { performGroup("breakUp", i); }; })(i); | button.onPressRight = (function(i) { return function() { performGroup("breakUp", i); }; })(i); | ||||
Lint: ESLintBear (no-shadow) 'i' is already declared in the upper scope. Lint: ESLintBear (no-shadow): `'i' is already declared in the upper scope.` | |||||
// Choose the icon of the most common template (or the most costly if it's not unique) | // Choose the icon of the most common template (or the most costly if it's not unique) | ||||
if (g_Groups.groups[i].getTotalCount() > 0) | if (g_Groups.groups[i].getTotalCount() > 0) | ||||
{ | { | ||||
let icon = GetTemplateData(GetEntityState(g_Groups.groups[i].getEntsGrouped().reduce((pre, cur) => { | let icon = GetTemplateData(GetEntityState(g_Groups.groups[i].getEntsGrouped().reduce((pre, cur) => { | ||||
if (pre.ents.length == cur.ents.length) | if (pre.ents.length == cur.ents.length) | ||||
return getCostSum(pre.ents[0]) > getCostSum(cur.ents[0]) ? pre : cur; | return getCostSum(pre.ents[0]) > getCostSum(cur.ents[0]) ? pre : cur; | ||||
return pre.ents.length > cur.ents.length ? pre : cur; | return pre.ents.length > cur.ents.length ? pre : cur; | ||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |
This function (leaveGame) is called when clicking on Menu -> Exit, when having officially won the game or finished the replay and being asked to leave.
Two bugs seem to arise:
either