From c036a7d7e356a2f77c8a7e3310572ee706cc652e Mon Sep 17 00:00:00 2001 From: historic_bruno Date: Mon, 7 May 2012 04:18:54 +0000 Subject: [PATCH] Adds control groups to saved game data, based on patch by mk12. Fixes #1261. This was SVN commit r11783. --- .../data/mods/public/gui/savedgames/load.js | 3 ++- .../data/mods/public/gui/session/selection.js | 18 +++--------------- .../data/mods/public/gui/session/session.js | 19 ++++++++++++++++++- source/network/NetTurnManager.cpp | 14 ++++++++++++-- source/network/NetTurnManager.h | 3 ++- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/binaries/data/mods/public/gui/savedgames/load.js b/binaries/data/mods/public/gui/savedgames/load.js index 7b88add85c..0587a0c395 100644 --- a/binaries/data/mods/public/gui/savedgames/load.js +++ b/binaries/data/mods/public/gui/savedgames/load.js @@ -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 }); } } diff --git a/binaries/data/mods/public/gui/session/selection.js b/binaries/data/mods/public/gui/session/selection.js index 7d6d0b4859..d9edcbc918 100644 --- a/binaries/data/mods/public/gui/session/selection.js +++ b/binaries/data/mods/public/gui/session/selection.js @@ -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(); diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index e334319847..1204df596e 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -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; /** diff --git a/source/network/NetTurnManager.cpp b/source/network/NetTurnManager.cpp index 2ef1ace867..f57c4353ec 100644 --- a/source/network/NetTurnManager.cpp +++ b/source/network/NetTurnManager.cpp @@ -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 diff --git a/source/network/NetTurnManager.h b/source/network/NetTurnManager.h index 6c4ded5e0c..852214ff6a 100644 --- a/source/network/NetTurnManager.h +++ b/source/network/NetTurnManager.h @@ -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 m_TimeWarpStates; std::string m_QuickSaveState; // TODO: should implement a proper disk-based quicksave system + std::string m_QuickSaveMetadata; }; /**