Changeset View
Changeset View
Standalone View
Standalone View
source/ps/SavedGame.cpp
Show All 25 Lines | |||||
#include "lib/file/io/io.h" | #include "lib/file/io/io.h" | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "maths/Vector3D.h" | #include "maths/Vector3D.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Mod.h" | #include "ps/Mod.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/StructuredClone.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
// TODO: we ought to check version numbers when loading files | // TODO: we ought to check version numbers when loading files | ||||
Status SavedGames::SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, const ScriptInterface::StructuredClone& guiMetadataClone) | Status SavedGames::SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& simulation, const Script::StructuredClone& guiMetadataClone) | ||||
{ | { | ||||
// Determine the filename to save under | // Determine the filename to save under | ||||
const VfsPath basenameFormat(L"saves/" + prefix + L"-%04d"); | const VfsPath basenameFormat(L"saves/" + prefix + L"-%04d"); | ||||
const VfsPath filenameFormat = basenameFormat.ChangeExtension(L".0adsave"); | const VfsPath filenameFormat = basenameFormat.ChangeExtension(L".0adsave"); | ||||
VfsPath filename; | VfsPath filename; | ||||
// Don't make this a static global like NextNumberedFilename expects, because | // Don't make this a static global like NextNumberedFilename expects, because | ||||
// that wouldn't work when 'prefix' changes, and because it's not thread-safe | // that wouldn't work when 'prefix' changes, and because it's not thread-safe | ||||
size_t nextSaveNumber = 0; | size_t nextSaveNumber = 0; | ||||
vfs::NextNumberedFilename(g_VFS, filenameFormat, nextSaveNumber, filename); | vfs::NextNumberedFilename(g_VFS, filenameFormat, nextSaveNumber, filename); | ||||
return Save(filename.Filename().string(), description, simulation, guiMetadataClone); | return Save(filename.Filename().string(), description, simulation, guiMetadataClone); | ||||
} | } | ||||
Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const ScriptInterface::StructuredClone& guiMetadataClone) | Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const Script::StructuredClone& guiMetadataClone) | ||||
{ | { | ||||
ScriptRequest rq(simulation.GetScriptInterface()); | ScriptRequest rq(simulation.GetScriptInterface()); | ||||
// Determine the filename to save under | // Determine the filename to save under | ||||
const VfsPath basenameFormat(L"saves/" + name); | const VfsPath basenameFormat(L"saves/" + name); | ||||
const VfsPath filename = basenameFormat.ChangeExtension(L".0adsave"); | const VfsPath filename = basenameFormat.ChangeExtension(L".0adsave"); | ||||
// ArchiveWriter_Zip can only write to OsPaths, not VfsPaths, | // ArchiveWriter_Zip can only write to OsPaths, not VfsPaths, | ||||
Show All 25 Lines | ScriptInterface::CreateObject( | ||||
&metadata, | &metadata, | ||||
"engine_version", engine_version, | "engine_version", engine_version, | ||||
"time", static_cast<double>(now), | "time", static_cast<double>(now), | ||||
"playerID", g_Game->GetPlayerID(), | "playerID", g_Game->GetPlayerID(), | ||||
"mods", mods, | "mods", mods, | ||||
"initAttributes", initAttributes); | "initAttributes", initAttributes); | ||||
JS::RootedValue guiMetadata(rq.cx); | JS::RootedValue guiMetadata(rq.cx); | ||||
simulation.GetScriptInterface().ReadStructuredClone(guiMetadataClone, &guiMetadata); | Script::ReadStructuredClone(rq, guiMetadataClone, &guiMetadata); | ||||
// get some camera data | // get some camera data | ||||
const CVector3D cameraPosition = g_Game->GetView()->GetCameraPosition(); | const CVector3D cameraPosition = g_Game->GetView()->GetCameraPosition(); | ||||
const CVector3D cameraRotation = g_Game->GetView()->GetCameraRotation(); | const CVector3D cameraRotation = g_Game->GetView()->GetCameraRotation(); | ||||
JS::RootedValue cameraMetadata(rq.cx); | JS::RootedValue cameraMetadata(rq.cx); | ||||
ScriptInterface::CreateObject( | ScriptInterface::CreateObject( | ||||
▲ Show 20 Lines • Show All 197 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator