Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/Simulation2.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 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 967 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
const ScriptInterface& scriptInterface = GetScriptInterface(); | const ScriptInterface& scriptInterface = GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue aiData(cx, ICmpAIManager::GetAIs(scriptInterface)); | JS::RootedValue aiData(cx, ICmpAIManager::GetAIs(scriptInterface)); | ||||
// Build single JSON string with array of AI data | // Build single JSON string with array of AI data | ||||
JS::RootedValue ais(cx); | JS::RootedValue ais(cx); | ||||
if (!scriptInterface.Eval("({})", &ais) || !scriptInterface.SetProperty(ais, "AIData", aiData)) | |||||
if (!scriptInterface.CreateObject(&ais, "AIData", aiData)) | |||||
return std::string(); | return std::string(); | ||||
return scriptInterface.StringifyJSON(&ais); | return scriptInterface.StringifyJSON(&ais); | ||||
} | } |
Wildfire Games · Phabricator