mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 20:24:49 +00:00
Load map descriptions from their XML file.
Add basic hold-fire stance, and use it for some test maps. Add JSON data container to map XML files, to simplify the interaction between scripts and maps. Fix fixed-point printing so it roundtrips safely through map files. Fix camera startup positions in old-format maps. This was SVN commit r7844.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "AutoRooters.h"
|
||||
|
||||
#include "lib/debug.h"
|
||||
#include "lib/utf8.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/Profile.h"
|
||||
#include "ps/utf16string.h"
|
||||
@@ -628,6 +629,58 @@ std::wstring ScriptInterface::ToString(jsval obj)
|
||||
return source;
|
||||
}
|
||||
|
||||
CScriptValRooted ScriptInterface::ParseJSON(const utf16string& string)
|
||||
{
|
||||
jsval vp;
|
||||
JSONParser* parser = JS_BeginJSONParse(m->m_cx, &vp);
|
||||
if (!parser)
|
||||
{
|
||||
LOGERROR(L"ParseJSON failed to begin");
|
||||
return CScriptValRooted();
|
||||
}
|
||||
|
||||
if (!JS_ConsumeJSONText(m->m_cx, parser, string.c_str(), string.size()))
|
||||
{
|
||||
LOGERROR(L"ParseJSON failed to consume");
|
||||
return CScriptValRooted();
|
||||
}
|
||||
|
||||
if (!JS_FinishJSONParse(m->m_cx, parser, JSVAL_NULL))
|
||||
{
|
||||
LOGERROR(L"ParseJSON failed to finish");
|
||||
return CScriptValRooted();
|
||||
}
|
||||
|
||||
return CScriptValRooted(m->m_cx, vp);
|
||||
}
|
||||
|
||||
struct Stringifier
|
||||
{
|
||||
static JSBool callback(const jschar *buf, uint32 len, void *data)
|
||||
{
|
||||
utf16string str(buf, buf+len);
|
||||
std::wstring strw(str.begin(), str.end());
|
||||
|
||||
LibError err; // ignore Unicode errors
|
||||
static_cast<Stringifier*>(data)->stream << utf8_from_wstring(strw, &err);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
std::stringstream stream;
|
||||
};
|
||||
|
||||
std::string ScriptInterface::StringifyJSON(jsval obj)
|
||||
{
|
||||
Stringifier str;
|
||||
if (!JS_Stringify(m->m_cx, &obj, NULL, INT_TO_JSVAL(2), &Stringifier::callback, &str))
|
||||
{
|
||||
LOGERROR(L"StringifyJSON failed");
|
||||
return "";
|
||||
}
|
||||
|
||||
return str.stream.str();
|
||||
}
|
||||
|
||||
void ScriptInterface::ReportError(const char* msg)
|
||||
{
|
||||
// JS_ReportError by itself doesn't seem to set a JS-style exception, and so
|
||||
|
||||
Reference in New Issue
Block a user