Savegame cleanup.

Remove the player assignments altogether (506350d6fa) as the C++ part
already saves the playerID.
Grab the playerID directly from the game instead of passing it around
needlessly.

This was SVN commit r18357.
This commit is contained in:
elexis 2016-06-10 19:04:57 +00:00
parent 6ba90a2555
commit c94cd66a57
5 changed files with 12 additions and 17 deletions

View File

@ -105,8 +105,8 @@ function reallyLoadGame(gameId)
"isNetworked" : false,
"playerAssignments": {
"local": {
"name": metadata.initAttributes.settings.PlayerData[metadata.gui.assignedPlayer].Name,
"player": metadata.gui.assignedPlayer
"name": metadata.initAttributes.settings.PlayerData[metadata.playerID].Name,
"player": metadata.playerID
}
},
"savedGUIData": metadata.gui

View File

@ -544,10 +544,7 @@ function getHotloadData()
function getSavedGameData()
{
let guid = g_IsNetworked ? Engine.GetPlayerGUID() : "local";
return {
"assignedPlayer": g_PlayerAssignments[guid].player,
"groups": g_Groups.groups
};
}

View File

@ -304,7 +304,7 @@ JS::Value StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstr
sim->GetScriptInterface().GetProperty(gameContextMetadata, "initAttributes", &gameInitAttributes);
int playerID;
sim->GetScriptInterface().GetProperty(gameContextMetadata, "player", playerID);
sim->GetScriptInterface().GetProperty(gameContextMetadata, "playerID", playerID);
// Start the game
g_Game->SetPlayerID(playerID);
@ -317,14 +317,14 @@ JS::Value StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstr
void SaveGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename, const std::wstring& description, JS::HandleValue GUIMetadata)
{
shared_ptr<ScriptInterface::StructuredClone> GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata);
if (SavedGames::Save(filename, description, *g_Game->GetSimulation2(), GUIMetadataClone, g_Game->GetPlayerID()) < 0)
if (SavedGames::Save(filename, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0)
LOGERROR("Failed to save game");
}
void SaveGamePrefix(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& prefix, const std::wstring& description, JS::HandleValue GUIMetadata)
{
shared_ptr<ScriptInterface::StructuredClone> GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata);
if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone, g_Game->GetPlayerID()) < 0)
if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0)
LOGERROR("Failed to save game");
}

View File

@ -39,7 +39,7 @@ static const int SAVED_GAME_VERSION_MINOR = 0; // increment on compatible change
// TODO: we ought to check version numbers when loading files
Status SavedGames::SavePrefix(const std::wstring& prefix, const std::wstring& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone, int playerID)
Status SavedGames::SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone)
{
// Determine the filename to save under
const VfsPath basenameFormat(L"saves/" + prefix + L"-%04d");
@ -51,10 +51,10 @@ Status SavedGames::SavePrefix(const std::wstring& prefix, const std::wstring& de
size_t nextSaveNumber = 0;
vfs::NextNumberedFilename(g_VFS, filenameFormat, nextSaveNumber, filename);
return Save(filename.Filename().string(), description, simulation, guiMetadataClone, playerID);
return Save(filename.Filename().string(), description, simulation, guiMetadataClone);
}
Status SavedGames::Save(const std::wstring& name, const std::wstring& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone, int playerID)
Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone)
{
JSContext* cx = simulation.GetScriptInterface().GetContext();
JSAutoRequest rq(cx);
@ -90,7 +90,7 @@ Status SavedGames::Save(const std::wstring& name, const std::wstring& descriptio
simulation.GetScriptInterface().SetProperty(metadata, "engine_version", std::string(engine_version));
simulation.GetScriptInterface().SetProperty(metadata, "mods", g_modsLoaded);
simulation.GetScriptInterface().SetProperty(metadata, "time", (double)now);
simulation.GetScriptInterface().SetProperty(metadata, "player", playerID);
simulation.GetScriptInterface().SetProperty(metadata, "playerID", g_Game->GetPlayerID());
simulation.GetScriptInterface().SetProperty(metadata, "initAttributes", initAttributes);
JS::RootedValue guiMetadata(cx);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -44,10 +44,9 @@ namespace SavedGames
* @param description A user-given description of the save
* @param simulation
* @param gui if not NULL, store some UI-related data with the saved game
* @param playerID ID of the player who saved this file
* @return INFO::OK if successfully saved, else an error Status
*/
Status Save(const std::wstring& name, const std::wstring& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone, int playerID);
Status Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone);
/**
* Create new saved game archive with given prefix and simulation data
@ -56,10 +55,9 @@ Status Save(const std::wstring& name, const std::wstring& description, CSimulati
* @param description A user-given description of the save
* @param simulation
* @param gui if not NULL, store some UI-related data with the saved game
* @param playerID ID of the player who saved this file
* @return INFO::OK if successfully saved, else an error Status
*/
Status SavePrefix(const std::wstring& prefix, const std::wstring& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone, int playerID);
Status SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, shared_ptr<ScriptInterface::StructuredClone> guiMetadataClone);
/**
* Load saved game archive with the given name