forked from 0ad/0ad
Move statistics from GuiInterface.GetSimulationState to GuiInterface.GetExtendedSimulationState
This was SVN commit r8603.
This commit is contained in:
parent
15327ac40b
commit
c1c8f64f0d
@ -89,8 +89,8 @@ function init(initData, hotloadData)
|
||||
|
||||
function leaveGame()
|
||||
{
|
||||
var simState = Engine.GuiInterfaceCall("GetSimulationState");
|
||||
var playerState = simState.players[Engine.GetPlayerID()];
|
||||
var extendedSimState = Engine.GuiInterfaceCall("GetExtendedSimulationState");
|
||||
var playerState = extendedSimState.players[Engine.GetPlayerID()];
|
||||
|
||||
var gameResult;
|
||||
if (playerState.state == "won")
|
||||
@ -119,8 +119,8 @@ function leaveGame()
|
||||
|
||||
Engine.SwitchGuiPage("page_summary.xml",
|
||||
{ "gameResult" : gameResult,
|
||||
"timeElapsed" : simState.timeElapsed,
|
||||
"playerStates": simState.players
|
||||
"timeElapsed" : extendedSimState.timeElapsed,
|
||||
"playerStates": extendedSimState.players
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,16 @@ GuiInterface.prototype.Init = function()
|
||||
this.rallyPoints = undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* All of the functions defined below are called via Engine.GuiInterfaceCall(name, arg) from GUI scripts, and executed here with arguments (player, arg)
|
||||
*/
|
||||
|
||||
GuiInterface.prototype.GetSimulationState = function(player)
|
||||
{
|
||||
var ret = {
|
||||
"players": [],
|
||||
"timeElapsed": 0
|
||||
"players": []
|
||||
};
|
||||
|
||||
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||
ret.timeElapsed = cmpTimer.GetTime();
|
||||
|
||||
var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
var n = cmpPlayerMan.GetNumPlayers();
|
||||
for (var i = 0; i < n; ++i)
|
||||
@ -45,8 +45,7 @@ GuiInterface.prototype.GetSimulationState = function(player)
|
||||
"state": cmpPlayer.GetState(),
|
||||
"team": cmpPlayer.GetTeam(),
|
||||
"diplomacy": cmpPlayer.GetDiplomacy(),
|
||||
"phase": cmpPlayer.GetPhase(),
|
||||
"statistics": cmpPlayerStatisticsTracker.GetStatistics()
|
||||
"phase": cmpPlayer.GetPhase()
|
||||
};
|
||||
ret.players.push(playerData);
|
||||
}
|
||||
@ -57,6 +56,28 @@ GuiInterface.prototype.GetSimulationState = function(player)
|
||||
ret.circularMap = cmpRangeManager.GetLosCircular();
|
||||
}
|
||||
|
||||
// Add timeElapsed
|
||||
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||
ret.timeElapsed = cmpTimer.GetTime();
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
GuiInterface.prototype.GetExtendedSimulationState = function(player)
|
||||
{
|
||||
// Get basic simulation info
|
||||
var ret = this.GetSimulationState();
|
||||
|
||||
// Add statistics to each player
|
||||
var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
var n = cmpPlayerMan.GetNumPlayers();
|
||||
for (var i = 0; i < n; ++i)
|
||||
{
|
||||
var playerEnt = cmpPlayerMan.GetPlayerByID(i);
|
||||
var cmpPlayerStatisticsTracker = Engine.QueryInterface(playerEnt, IID_StatisticsTracker);
|
||||
ret.players[i].statistics = cmpPlayerStatisticsTracker.GetStatistics();
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
@ -449,6 +470,7 @@ GuiInterface.prototype.SetRangeDebugOverlay = function(player, enabled)
|
||||
var exposedFunctions = {
|
||||
|
||||
"GetSimulationState": 1,
|
||||
"GetExtendedSimulationState": 1,
|
||||
"GetEntityState": 1,
|
||||
"GetTemplateData": 1,
|
||||
"GetNextNotification": 1,
|
||||
|
@ -112,6 +112,39 @@ AddMock(101, IID_StatisticsTracker, {
|
||||
});
|
||||
|
||||
TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
|
||||
players: [
|
||||
{
|
||||
name: "Player 1",
|
||||
civ: "gaia",
|
||||
colour: { r:1, g:1, b:1, a:1 },
|
||||
popCount: 10,
|
||||
popLimit: 20,
|
||||
resourceCounts: { food: 100 },
|
||||
trainingQueueBlocked: false,
|
||||
state: "active",
|
||||
team: -1,
|
||||
diplomacy: [],
|
||||
phase: "",
|
||||
},
|
||||
{
|
||||
name: "Player 2",
|
||||
civ: "celt",
|
||||
colour: { r:1, g:0, b:0, a:1 },
|
||||
popCount: 40,
|
||||
popLimit: 30,
|
||||
resourceCounts: { food: 200 },
|
||||
trainingQueueBlocked: false,
|
||||
state: "active",
|
||||
team: -1,
|
||||
diplomacy: [1],
|
||||
phase: "village",
|
||||
}
|
||||
],
|
||||
circularMap: false,
|
||||
timeElapsed: 0,
|
||||
});
|
||||
|
||||
TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
|
||||
players: [
|
||||
{
|
||||
name: "Player 1",
|
||||
@ -168,8 +201,8 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
|
||||
},
|
||||
}
|
||||
],
|
||||
timeElapsed: 0,
|
||||
circularMap: false,
|
||||
timeElapsed: 0,
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user