Changeset View
Standalone View
source/ps/SavedGame.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const shared_ptr<ScriptInterface::StructuredClone>& guiMetadataClone) | ||||
std::stringstream simStateStream; | std::stringstream simStateStream; | ||||
if (!simulation.SerializeState(simStateStream)) | if (!simulation.SerializeState(simStateStream)) | ||||
WARN_RETURN(ERR::FAIL); | WARN_RETURN(ERR::FAIL); | ||||
JS::RootedValue metadata(cx); | JS::RootedValue metadata(cx); | ||||
JS::RootedValue initAttributes(cx, simulation.GetInitAttributes()); | JS::RootedValue initAttributes(cx, simulation.GetInitAttributes()); | ||||
simulation.GetScriptInterface().Eval("({})", &metadata); | simulation.GetScriptInterface().Eval("({})", &metadata); | ||||
simulation.GetScriptInterface().SetProperty(metadata, "engine_version", std::string(engine_version)); | simulation.GetScriptInterface().SetProperty(metadata, "engine_version", std::string(engine_version)); | ||||
simulation.GetScriptInterface().SetProperty(metadata, "mods", g_modsLoaded); | simulation.GetScriptInterface().SetProperty(metadata, "mods", JS::RootedValue(cx, Mod::GetLoadedModsWithVersions(simulation.GetScriptInterface()))); | ||||
simulation.GetScriptInterface().SetProperty(metadata, "time", (double)now); | simulation.GetScriptInterface().SetProperty(metadata, "time", (double)now); | ||||
simulation.GetScriptInterface().SetProperty(metadata, "playerID", g_Game->GetPlayerID()); | simulation.GetScriptInterface().SetProperty(metadata, "playerID", g_Game->GetPlayerID()); | ||||
simulation.GetScriptInterface().SetProperty(metadata, "initAttributes", initAttributes); | simulation.GetScriptInterface().SetProperty(metadata, "initAttributes", initAttributes); | ||||
JS::RootedValue guiMetadata(cx); | JS::RootedValue guiMetadata(cx); | ||||
simulation.GetScriptInterface().ReadStructuredClone(guiMetadataClone, &guiMetadata); | simulation.GetScriptInterface().ReadStructuredClone(guiMetadataClone, &guiMetadata); | ||||
// get some camera data | // get some camera data | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | bool SavedGames::DeleteSavedGame(const std::wstring& name) | ||||
// Delete actual file | // Delete actual file | ||||
if (wunlink(realpath) != 0) | if (wunlink(realpath) != 0) | ||||
return false; // Error | return false; // Error | ||||
// Successfully deleted file | // Successfully deleted file | ||||
return true; | return true; | ||||
} | } | ||||
JS::Value SavedGames::GetEngineInfo(const ScriptInterface& scriptInterface) | JS::Value SavedGames::GetEngineInfo(const ScriptInterface& scriptInterface) | ||||
elexis: This function should be moved to Mods since SaveGames were only the original of multiple use… | |||||
ImarokAuthorUnsubmitted Done Inline ActionsIt also contains the engine_version, but I still agree. Imarok: It also contains the engine_version, but I still agree. | |||||
ImarokAuthorUnsubmitted Not Done Inline ActionsImarok: rP21242 | |||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue metainfo(cx); | JS::RootedValue metainfo(cx); | ||||
Done Inline ActionsI think, it make sense to refract GetAvailableMods to use const ScriptInterface&, because it just gets the ScriptInterface from the CxPrivate. vladislavbelov: I think, it make sense to refract `GetAvailableMods` to use `const ScriptInterface&`, because… | |||||
scriptInterface.Eval("({})", &metainfo); | scriptInterface.Eval("({})", &metainfo); | ||||
scriptInterface.SetProperty(metainfo, "engine_version", std::string(engine_version)); | scriptInterface.SetProperty(metainfo, "engine_version", std::string(engine_version)); | ||||
scriptInterface.SetProperty(metainfo, "mods", g_modsLoaded); | scriptInterface.SetProperty(metainfo, "mods", JS::RootedValue(cx, Mod::GetLoadedModsWithVersions(scriptInterface))); | ||||
Done Inline ActionsPerhaps it would be nicer to pass only one property instead of two` Like an object where the keys are modnames and the values are mod versions. Mod names currently aren't well defined, but they probably still match the set of word that can be JS property names. (D1093 defines the name as a nonempty alphanum or something). Perhaps further code can be removed, possibly g_modsLoaded. elexis: Perhaps it would be nicer to pass only one property instead of two` Like an object where the… | |||||
Done Inline ActionsSeriosuly, isnt mods redundant with mod_versions now? elexis: Seriosuly, isnt `mods` redundant with `mod_versions` now? | |||||
Done Inline Actionsno, the first is an array with the names while the second is just an array of version numbers. Imarok: no, the first is an array with the names while the second is just an array of version numbers. | |||||
Done Inline Actions
According to some stackoverflow threads a js property name can be any valid string...
I think it's also needed somewhere else Imarok: > Perhaps it would be nicer to pass only one property instead of two` Like an object where the… | |||||
Done Inline Actions
Not a good idea, as we loose the loading order... (https://github.com/0ad/0ad/blob/073fbbd7b5adecfc9c84ea03e19567c64bfb6727/binaries/data/mods/public/gui/common/functions_utility_loadsave.js#L68) Imarok: > > Perhaps it would be nicer to pass only one property instead of two` Like an object where… | |||||
scriptInterface.FreezeObject(metainfo, true); | scriptInterface.FreezeObject(metainfo, true); | ||||
return metainfo; | return metainfo; | ||||
} | } |
This function should be moved to Mods since SaveGames were only the original of multiple use cases.
IMO can do this without review afterwards.