diff --git a/binaries/data/mods/public/gui/savedgames/load.js b/binaries/data/mods/public/gui/savedgames/load.js index c6c367540e..3a3b9ac6a8 100644 --- a/binaries/data/mods/public/gui/savedgames/load.js +++ b/binaries/data/mods/public/gui/savedgames/load.js @@ -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 diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index f21261e836..c1a0d9d46a 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -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 }; } diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 74256b44cb..f5fe29d772 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -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 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 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"); } diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp index f4dafd984e..3056c5403f 100644 --- a/source/ps/SavedGame.cpp +++ b/source/ps/SavedGame.cpp @@ -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 guiMetadataClone, int playerID) +Status SavedGames::SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, shared_ptr 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 guiMetadataClone, int playerID) +Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, shared_ptr 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); diff --git a/source/ps/SavedGame.h b/source/ps/SavedGame.h index e89a6e7b07..1bd666f06e 100644 --- a/source/ps/SavedGame.h +++ b/source/ps/SavedGame.h @@ -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 guiMetadataClone, int playerID); +Status Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, shared_ptr 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 guiMetadataClone, int playerID); +Status SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, shared_ptr guiMetadataClone); /** * Load saved game archive with the given name