mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 02:23:47 +00:00
Adds control groups to saved game data, based on patch by mk12. Fixes #1261.
This was SVN commit r11783.
This commit is contained in:
@@ -60,7 +60,8 @@ function loadGame()
|
||||
Engine.SwitchGuiPage("page_loading.xml", {
|
||||
"attribs": metadata.initAttributes,
|
||||
"isNetworked" : false,
|
||||
"playerAssignments": metadata.gui.playerAssignments
|
||||
"playerAssignments": metadata.gui.playerAssignments,
|
||||
"savedGUIData": metadata.gui
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,17 +100,11 @@ EntityGroups.prototype.getTemplateNames = function()
|
||||
|
||||
EntityGroups.prototype.getEntsByName = function(templateName)
|
||||
{
|
||||
var entTemplateNames = [];
|
||||
for each (var entTemplateName in this.ents)
|
||||
entTemplateNames.push(entTemplateName);
|
||||
|
||||
var i = 0;
|
||||
var ents = [];
|
||||
for (var ent in this.ents)
|
||||
{
|
||||
if (entTemplateNames[i] == templateName)
|
||||
if (this.ents[ent] == templateName)
|
||||
ents.push(parseInt(ent));
|
||||
i++;
|
||||
}
|
||||
|
||||
return ents;
|
||||
@@ -119,17 +113,11 @@ EntityGroups.prototype.getEntsByName = function(templateName)
|
||||
// Gets all ents in every group except ones of the specified group
|
||||
EntityGroups.prototype.getEntsByNameInverse = function(templateName)
|
||||
{
|
||||
var entTemplateNames = [];
|
||||
for each (var entTemplateName in this.ents)
|
||||
entTemplateNames.push(entTemplateName);
|
||||
|
||||
var i = 0;
|
||||
var ents = [];
|
||||
for (var ent in this.ents)
|
||||
{
|
||||
if (entTemplateNames[i] != templateName)
|
||||
if (this.ents[ent] != templateName)
|
||||
ents.push(parseInt(ent));
|
||||
i++;
|
||||
}
|
||||
|
||||
return ents;
|
||||
@@ -379,7 +367,7 @@ var g_Selection = new EntitySelection();
|
||||
//-------------------------------- -------------------------------- --------------------------------
|
||||
function EntityGroupsContainer()
|
||||
{
|
||||
this.groups = {};
|
||||
this.groups = [];
|
||||
for (var i = 0; i < 10; ++i)
|
||||
{
|
||||
this.groups[i] = new EntityGroups();
|
||||
|
||||
@@ -78,6 +78,11 @@ function init(initData, hotloadData)
|
||||
// Cache the player data
|
||||
// (This may be updated at runtime by handleNetMessage)
|
||||
g_Players = getPlayerData(g_PlayerAssignments);
|
||||
|
||||
if (initData.savedGUIData)
|
||||
{
|
||||
restoreSavedGameData(initData.savedGUIData);
|
||||
}
|
||||
}
|
||||
else // Needed for autostart loading option
|
||||
{
|
||||
@@ -182,10 +187,22 @@ function getSavedGameData()
|
||||
{
|
||||
var data = {};
|
||||
data.playerAssignments = g_PlayerAssignments;
|
||||
// TODO: control groups, etc
|
||||
data.groups = g_Groups.groups;
|
||||
// TODO: any other gui state?
|
||||
return data;
|
||||
}
|
||||
|
||||
function restoreSavedGameData(data)
|
||||
{
|
||||
// Restore control groups
|
||||
for (groupNumber in data.groups)
|
||||
{
|
||||
g_Groups.groups[groupNumber].groups = data.groups[groupNumber].groups;
|
||||
g_Groups.groups[groupNumber].ents = data.groups[groupNumber].ents;
|
||||
}
|
||||
updateGroups();
|
||||
}
|
||||
|
||||
var lastTickTime = new Date;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -330,9 +330,14 @@ void CNetTurnManager::QuickSave()
|
||||
LOGERROR(L"Failed to quicksave game");
|
||||
return;
|
||||
}
|
||||
LOGMESSAGERENDER(L"Quicksaved game");
|
||||
|
||||
m_QuickSaveState = stream.str();
|
||||
if (g_GUI)
|
||||
m_QuickSaveMetadata = g_GUI->GetScriptInterface().StringifyJSON(g_GUI->GetSavedGameData().get(), false);
|
||||
else
|
||||
m_QuickSaveMetadata = std::string();
|
||||
|
||||
LOGMESSAGERENDER(L"Quicksaved game");
|
||||
|
||||
}
|
||||
|
||||
@@ -353,6 +358,11 @@ void CNetTurnManager::QuickLoad()
|
||||
LOGERROR(L"Failed to quickload game");
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_GUI && !m_QuickSaveMetadata.empty())
|
||||
g_GUI->GetScriptInterface().CallFunctionVoid(OBJECT_TO_JSVAL(g_GUI->GetScriptObject()),
|
||||
"restoreSavedGameData", g_GUI->GetScriptInterface().ParseJSON(m_QuickSaveMetadata));
|
||||
|
||||
LOGMESSAGERENDER(L"Quickloaded game");
|
||||
|
||||
// See RewindTimeWarp
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2011 Wildfire Games.
|
||||
/* Copyright (C) 2012 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -183,6 +183,7 @@ private:
|
||||
size_t m_TimeWarpNumTurns; // 0 if disabled
|
||||
std::list<std::string> m_TimeWarpStates;
|
||||
std::string m_QuickSaveState; // TODO: should implement a proper disk-based quicksave system
|
||||
std::string m_QuickSaveMetadata;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user