mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:29:50 +00:00
Split off JSON-related function from ScriptInterface, clean up headers.
Follows 34b1920e7b.
JSON functions and ToString are movec to their own headers.
Also clean out a few PersistentRooted usage to use the 2-phase init to
clean up scriptInterface usage.
With these functions split off, we can finally clean out headers and
remove ScriptInterface.h from most of them, in favour of smaller and
more precise headers.
Take the opportunity to clarify some comments regarding Mutability.
Differential Revision: https://code.wildfiregames.com/D3961
This was SVN commit r25434.
This commit is contained in:
@@ -33,8 +33,7 @@
|
||||
#include "ps/Pyrogenesis.h"
|
||||
#include "ps/Replay.h"
|
||||
#include "ps/Util.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptExtraHeaders.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
@@ -85,7 +84,7 @@ bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::Mut
|
||||
ScriptRequest rq(scriptInterface);
|
||||
|
||||
JS::RootedValue cachedReplays(rq.cx);
|
||||
if (scriptInterface.ParseJSON(cacheStr, &cachedReplays))
|
||||
if (Script::ParseJSON(rq, cacheStr, &cachedReplays))
|
||||
{
|
||||
cachedReplaysObject.set(&cachedReplays.toObject());
|
||||
bool isArray;
|
||||
@@ -104,7 +103,7 @@ void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::Ha
|
||||
|
||||
JS::RootedValue replaysRooted(rq.cx, JS::ObjectValue(*replays));
|
||||
std::ofstream cacheStream(OsString(GetTempCacheFilePath()).c_str(), std::ofstream::out | std::ofstream::trunc);
|
||||
cacheStream << scriptInterface.StringifyJSON(&replaysRooted);
|
||||
cacheStream << Script::StringifyJSON(rq, &replaysRooted);
|
||||
cacheStream.close();
|
||||
|
||||
wunlink(GetCacheFilePath());
|
||||
@@ -375,7 +374,7 @@ JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, c
|
||||
std::getline(*replayStream, header);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
if (!scriptInterface.ParseJSON(header, &attribs))
|
||||
if (!Script::ParseJSON(rq, header, &attribs))
|
||||
{
|
||||
LOGERROR("Couldn't parse replay header of %s", replayFile.string8().c_str());
|
||||
SAFE_DELETE(replayStream);
|
||||
@@ -450,7 +449,7 @@ JS::Value VisualReplay::GetReplayAttributes(const ScriptInterface& scriptInterfa
|
||||
|
||||
// Read and return first line
|
||||
std::getline(*replayStream, line);
|
||||
scriptInterface.ParseJSON(line, &attribs);
|
||||
Script::ParseJSON(rq, line, &attribs);
|
||||
SAFE_DELETE(replayStream);;
|
||||
return attribs;
|
||||
}
|
||||
@@ -502,7 +501,7 @@ JS::Value VisualReplay::GetReplayMetadata(const ScriptInterface& scriptInterface
|
||||
std::getline(*stream, line);
|
||||
stream->close();
|
||||
SAFE_DELETE(stream);
|
||||
scriptInterface.ParseJSON(line, &metadata);
|
||||
Script::ParseJSON(rq, line, &metadata);
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user