mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Move Script* classes to Script namespace
- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
ScriptContext.* → Context.*
ScriptInterface.* → Interface.*
ScriptRequest.* → Request.*
ScriptEngine.* → Engine.*
ScriptConversions.* → Conversions.*
ScriptExceptions.* → Exceptions.*
ScriptForward.* → ForwardDeclarations.*
ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
ScriptInterface_impl → Interface_impl
ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
macro) by adding them to suppressions-list.txt (these are not caused
by this refactor)
Fixes #7516
This commit is contained in:
@@ -49,8 +49,8 @@
|
||||
#include "ps/Profiler2.h"
|
||||
#include "ps/VideoMode.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <SDL_clipboard.h>
|
||||
#include <SDL_events.h>
|
||||
@@ -611,8 +611,8 @@ void CConsole::ProcessBuffer(const wchar_t* szLine)
|
||||
}
|
||||
|
||||
// Process it as JavaScript
|
||||
std::shared_ptr<ScriptInterface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
|
||||
ScriptRequest rq(*pScriptInterface);
|
||||
std::shared_ptr<Script::Interface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
|
||||
Script::Request rq(*pScriptInterface);
|
||||
|
||||
JS::RootedValue rval(rq.cx);
|
||||
pScriptInterface->Eval(CStrW(szLine).ToUTF8().c_str(), &rval);
|
||||
|
||||
+10
-10
@@ -43,9 +43,9 @@
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptContext.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Context.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
#include "simulation2/components/ICmpPlayer.h"
|
||||
#include "simulation2/components/ICmpPlayerManager.h"
|
||||
@@ -204,8 +204,8 @@ bool CGame::StartVisualReplay(const OsPath& replayPath)
|
||||
std::string line;
|
||||
std::getline(*m_ReplayStream, line);
|
||||
|
||||
const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface();
|
||||
ScriptRequest rq(scriptInterface);
|
||||
const Script::Interface& scriptInterface = m_Simulation2->GetScriptInterface();
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
Script::ParseJSON(rq, line, &attribs);
|
||||
@@ -221,8 +221,8 @@ bool CGame::StartVisualReplay(const OsPath& replayPath)
|
||||
**/
|
||||
void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& savedState)
|
||||
{
|
||||
const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface();
|
||||
ScriptRequest rq(scriptInterface);
|
||||
const Script::Interface& scriptInterface = m_Simulation2->GetScriptInterface();
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
m_IsSavedGame = !savedState.empty();
|
||||
|
||||
@@ -358,12 +358,12 @@ PSRETURN CGame::ReallyStartGame()
|
||||
// Call the reallyStartGame GUI function, but only if it exists
|
||||
if (g_GUI && g_GUI->GetPageCount())
|
||||
{
|
||||
std::shared_ptr<ScriptInterface> scriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
|
||||
ScriptRequest rq(scriptInterface);
|
||||
std::shared_ptr<Script::Interface> scriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue global(rq.cx, rq.globalValue());
|
||||
if (Script::HasProperty(rq, global, "reallyStartGame"))
|
||||
ScriptFunction::CallVoid(rq, global, "reallyStartGame");
|
||||
Script::Function::CallVoid(rq, global, "reallyStartGame");
|
||||
}
|
||||
|
||||
debug_printf("GAME STARTED, ALL INIT COMPLETE\n");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
#include "lib/sysdep/sysdep.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <js/CallArgs.h>
|
||||
@@ -127,7 +127,7 @@ std::vector<CStr> CmdLineArgs::GetArgsWithoutName() const
|
||||
return m_ArgsWithoutName;
|
||||
}
|
||||
|
||||
template<> void Script::ToJSVal<CmdLineArgs>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CmdLineArgs& val)
|
||||
template<> void Script::ToJSVal<CmdLineArgs>(const Script::Request& rq, JS::MutableHandleValue ret, const CmdLineArgs& val)
|
||||
{
|
||||
if (!Script::CreateObject(rq, ret))
|
||||
return;
|
||||
|
||||
@@ -82,11 +82,11 @@
|
||||
#include "renderer/SceneRenderer.h"
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptContext.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/ScriptStats.h"
|
||||
#include "scriptinterface/Context.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
#include "scriptinterface/Stats.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
#include "simulation2/scripting/JSInterface_Simulation.h"
|
||||
#include "simulation2/system/Component.h"
|
||||
@@ -139,7 +139,7 @@ ERROR_TYPE(System, SDLInitFailed);
|
||||
ERROR_TYPE(System, VmodeFailed);
|
||||
ERROR_TYPE(System, RequiredExtensionsMissing);
|
||||
|
||||
thread_local std::shared_ptr<ScriptContext> g_ScriptContext;
|
||||
thread_local std::shared_ptr<Script::Context> g_ScriptContext;
|
||||
|
||||
bool g_InDevelopmentCopy;
|
||||
bool g_CheckedIfInDevelopmentCopy = false;
|
||||
@@ -237,7 +237,7 @@ void InitVfs(const CmdLineArgs& args)
|
||||
}
|
||||
|
||||
|
||||
static void InitPs(bool setup_gui, const CStrW& gui_page, ScriptInterface* srcScriptInterface, JS::HandleValue initData)
|
||||
static void InitPs(bool setup_gui, const CStrW& gui_page, Script::Interface* srcScriptInterface, JS::HandleValue initData)
|
||||
{
|
||||
g_Console->Init();
|
||||
LoadHotkeys(g_ConfigDB);
|
||||
@@ -528,7 +528,7 @@ bool Init(const CmdLineArgs& args, int flags)
|
||||
new CProfileViewer;
|
||||
new CProfileManager; // before any script code
|
||||
|
||||
g_ScriptStatsTable = new CScriptStatsTable;
|
||||
g_ScriptStatsTable = new Script::CScriptStatsTable;
|
||||
g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
|
||||
|
||||
// Set up the console early, so that debugging
|
||||
@@ -543,7 +543,7 @@ bool Init(const CmdLineArgs& args, int flags)
|
||||
// their own threads and also their own contexts.
|
||||
const int contextSize = 384 * 1024 * 1024;
|
||||
const int heapGrowthBytesGCTrigger = 12 * 1024 * 1024;
|
||||
g_ScriptContext = std::make_shared<ScriptContext>(contextSize, heapGrowthBytesGCTrigger);
|
||||
g_ScriptContext = std::make_shared<Script::Context>(contextSize, heapGrowthBytesGCTrigger);
|
||||
|
||||
// On the first Init (INIT_MODS), check for command-line arguments
|
||||
// or use the default mods from the config and enable those.
|
||||
@@ -551,7 +551,7 @@ bool Init(const CmdLineArgs& args, int flags)
|
||||
// to avoid overwriting the newly selected mods.
|
||||
if (flags & INIT_MODS)
|
||||
{
|
||||
ScriptInterface modInterface("Engine", "Mod", g_ScriptContext);
|
||||
Script::Interface modInterface("Engine", "Mod", g_ScriptContext);
|
||||
g_Mods.UpdateAvailableMods(modInterface);
|
||||
std::vector<CStr> mods;
|
||||
if (args.Has("mod"))
|
||||
@@ -623,8 +623,8 @@ bool Init(const CmdLineArgs& args, int flags)
|
||||
}
|
||||
|
||||
[[nodiscard]] std::unique_ptr<InputHandlers> InitGraphics(const CmdLineArgs& args, int flags,
|
||||
const std::vector<CStr>& installedMods, ScriptContext& scriptContext,
|
||||
ScriptInterface& scriptInterface)
|
||||
const std::vector<CStr>& installedMods, Script::Context& scriptContext,
|
||||
Script::Interface& scriptInterface)
|
||||
{
|
||||
const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;
|
||||
|
||||
@@ -678,7 +678,7 @@ bool Init(const CmdLineArgs& args, int flags)
|
||||
{
|
||||
const bool setup_gui = ((flags & INIT_NO_GUI) == 0);
|
||||
|
||||
ScriptRequest rq{g_GUI->GetScriptInterface()};
|
||||
Script::Request rq{g_GUI->GetScriptInterface()};
|
||||
JS::RootedValue data(rq.cx);
|
||||
Script::CreateObject(rq, &data, "isStartup", true);
|
||||
if (!installedMods.empty())
|
||||
@@ -766,8 +766,8 @@ bool Autostart(const CmdLineArgs& args)
|
||||
return false;
|
||||
|
||||
// Create some scriptinterface to store the js values for the settings.
|
||||
ScriptInterface scriptInterface("Engine", "Game Setup", g_ScriptContext);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Interface scriptInterface("Engine", "Game Setup", g_ScriptContext);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
// We use the javascript gameSettings to handle options, but that requires running JS.
|
||||
// Since we don't want to use the full Gui manager, we load an entrypoint script
|
||||
@@ -775,7 +775,7 @@ bool Autostart(const CmdLineArgs& args)
|
||||
|
||||
// TODO: this essentially duplicates the CGUI logic to load directory or scripts.
|
||||
std::unordered_set<VfsPath> templateCache;
|
||||
const auto autostartLoadScript = [&templateCache](const ScriptInterface& scriptInterface,
|
||||
const auto autostartLoadScript = [&templateCache](const Script::Interface& scriptInterface,
|
||||
const VfsPath& path)
|
||||
{
|
||||
if (!std::get<1>(templateCache.insert(path)))
|
||||
@@ -792,7 +792,7 @@ bool Autostart(const CmdLineArgs& args)
|
||||
scriptInterface.LoadGlobalScriptFile(path);
|
||||
};
|
||||
|
||||
const auto loadScriptCallback = ScriptFunction::Register(rq, "LoadScript", autostartLoadScript);
|
||||
const auto loadScriptCallback = Script::Function::Register(rq, "LoadScript", autostartLoadScript);
|
||||
// Load the entire folder to allow mods to extend the entrypoint without copying the whole file.
|
||||
autostartLoadScript(scriptInterface, VfsPath(L"autostart/"));
|
||||
|
||||
@@ -813,7 +813,7 @@ bool Autostart(const CmdLineArgs& args)
|
||||
}
|
||||
};
|
||||
|
||||
std::optional<ScriptFunction::StatefulCallback<GetTemplate>> getTemplateCallback;
|
||||
std::optional<Script::Function::StatefulCallback<GetTemplate>> getTemplateCallback;
|
||||
if (args.Has("autostart-nonvisual"))
|
||||
getTemplateCallback.emplace(rq, "GetTemplate", GetTemplate{});
|
||||
else
|
||||
@@ -838,7 +838,7 @@ bool Autostart(const CmdLineArgs& args)
|
||||
|
||||
JS::RootedValue resultValue{rq.cx};
|
||||
JS::RootedValue global(rq.cx, rq.globalValue());
|
||||
if (!ScriptFunction::Call(rq, global,
|
||||
if (!Script::Function::Call(rq, global,
|
||||
args.Has("autostart-client") ? "autostartClient" : "autostartHost", &resultValue,
|
||||
cmdLineArgs, args.Has("autostart-host")) && !resultValue.isObject())
|
||||
{
|
||||
@@ -885,8 +885,8 @@ bool AutostartVisualReplay(const std::string& replayFile)
|
||||
g_Game->SetPlayerID(-1);
|
||||
g_Game->StartVisualReplay(replayFile);
|
||||
|
||||
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Interface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
|
||||
Script::Request rq(scriptInterface);
|
||||
JS::RootedValue attrs(rq.cx, g_Game->GetSimulation2()->GetInitAttributes());
|
||||
|
||||
JS::RootedValue playerAssignments(rq.cx);
|
||||
@@ -910,8 +910,8 @@ bool AutostartVisualReplay(const std::string& replayFile)
|
||||
|
||||
void CancelLoad(const CStrW& message)
|
||||
{
|
||||
std::shared_ptr<ScriptInterface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
|
||||
ScriptRequest rq(pScriptInterface);
|
||||
std::shared_ptr<Script::Interface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
|
||||
Script::Request rq(pScriptInterface);
|
||||
|
||||
JS::RootedValue global(rq.cx, rq.globalValue());
|
||||
|
||||
@@ -920,7 +920,7 @@ void CancelLoad(const CStrW& message)
|
||||
if (g_GUI &&
|
||||
g_GUI->GetPageCount() &&
|
||||
Script::HasProperty(rq, global, "cancelOnLoadGameError"))
|
||||
ScriptFunction::CallVoid(rq, global, "cancelOnLoadGameError", message);
|
||||
Script::Function::CallVoid(rq, global, "cancelOnLoadGameError", message);
|
||||
}
|
||||
|
||||
bool InDevelopmentCopy()
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
class CmdLineArgs;
|
||||
class Paths;
|
||||
class ScriptContext;
|
||||
class ScriptInterface;
|
||||
namespace Script { class Context; }
|
||||
namespace Script { class Interface; }
|
||||
|
||||
/**
|
||||
* initialize global modules that are be needed before Init.
|
||||
@@ -80,8 +80,8 @@ using InputHandlers = std::queue<Input::Handler<Input::Reaction(&)(const SDL_Eve
|
||||
* `ShutdownNetworkAndUI` has to be called later.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<InputHandlers> InitGraphics(const CmdLineArgs& args, int flags,
|
||||
const std::vector<CStr>& installedMods, ScriptContext& scriptContext,
|
||||
ScriptInterface& scriptInterface);
|
||||
const std::vector<CStr>& installedMods, Script::Context& scriptContext,
|
||||
Script::Interface& scriptInterface);
|
||||
|
||||
/**
|
||||
* `ShutdownNetworkAndUI` has to be called later.
|
||||
|
||||
@@ -52,8 +52,8 @@
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
#include "scriptinterface/StructuredClone.h"
|
||||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace
|
||||
class Reporter
|
||||
{
|
||||
public:
|
||||
Reporter(const ScriptRequest& rq)
|
||||
Reporter(const Script::Request& rq)
|
||||
: m_Rq(rq), m_LibrarySettings(rq.cx)
|
||||
{
|
||||
Script::CreateObject(m_Rq, &m_LibrarySettings);
|
||||
@@ -134,21 +134,21 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const ScriptRequest& m_Rq;
|
||||
const Script::Request& m_Rq;
|
||||
JS::RootedValue m_LibrarySettings;
|
||||
};
|
||||
|
||||
class LibraryReporter : public Reporter
|
||||
{
|
||||
public:
|
||||
LibraryReporter(const ScriptRequest& rq, const char* name)
|
||||
LibraryReporter(const Script::Request& rq, const char* name)
|
||||
: Reporter(rq)
|
||||
{
|
||||
Add("name", name);
|
||||
}
|
||||
};
|
||||
|
||||
JS::Value MakeSDLReport(const ScriptRequest& rq)
|
||||
JS::Value MakeSDLReport(const Script::Request& rq)
|
||||
{
|
||||
LibraryReporter reporter{rq, "sdl"};
|
||||
|
||||
@@ -175,7 +175,7 @@ JS::Value MakeSDLReport(const ScriptRequest& rq)
|
||||
return reporter.MakeReport();
|
||||
}
|
||||
|
||||
JS::Value MakeFreeTypeReport(const ScriptRequest& rq)
|
||||
JS::Value MakeFreeTypeReport(const Script::Request& rq)
|
||||
{
|
||||
FT_Library FTLibrary;
|
||||
|
||||
@@ -194,7 +194,7 @@ JS::Value MakeFreeTypeReport(const ScriptRequest& rq)
|
||||
return libraryReporter.MakeReport();
|
||||
}
|
||||
|
||||
void ReportLibraries(const ScriptRequest& rq, JS::HandleValue settings)
|
||||
void ReportLibraries(const Script::Request& rq, JS::HandleValue settings)
|
||||
{
|
||||
JS::RootedValueVector librariesSettings{rq.cx};
|
||||
|
||||
@@ -336,14 +336,14 @@ void RunHardwareDetection(bool writeSystemInfoBeforeDetection, Renderer::Backend
|
||||
|
||||
PROFILE2("RunHardwareDetection");
|
||||
|
||||
ScriptInterface scriptInterface("Engine", "HWDetect", g_ScriptContext);
|
||||
Script::Interface scriptInterface("Engine", "HWDetect", g_ScriptContext);
|
||||
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JSI_Debug::RegisterScriptFunctions(scriptInterface); // Engine.DisplayErrorDialog
|
||||
JSI_ConfigDB::RegisterScriptFunctions(scriptInterface);
|
||||
|
||||
ScriptFunction::Register<SetDisableAudio>(rq, "SetDisableAudio");
|
||||
Script::Function::Register<SetDisableAudio>(rq, "SetDisableAudio");
|
||||
|
||||
// Load the detection script:
|
||||
|
||||
@@ -478,5 +478,5 @@ void RunHardwareDetection(bool writeSystemInfoBeforeDetection, Renderer::Backend
|
||||
|
||||
// Run the detection script:
|
||||
JS::RootedValue global(rq.cx, rq.globalValue());
|
||||
ScriptFunction::CallVoid(rq, global, "RunHardwareDetection", settings);
|
||||
Script::Function::CallVoid(rq, global, "RunHardwareDetection", settings);
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@
|
||||
#include "ps/Profile.h"
|
||||
#include "ps/TouchInput.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -32,8 +32,8 @@
|
||||
#include "ps/Profiler2.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
@@ -55,7 +55,7 @@
|
||||
#include "lib/os_path.h"
|
||||
#endif
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -112,7 +112,7 @@ bool LoadModJSON(const PIVFS& vfs, OsPath modsPath, OsPath mod, std::string& tex
|
||||
}
|
||||
}
|
||||
|
||||
bool ParseModJSON(const ScriptRequest& rq, const PIVFS& vfs, OsPath modsPath, OsPath mod, Mod::ModData& data)
|
||||
bool ParseModJSON(const Script::Request& rq, const PIVFS& vfs, OsPath modsPath, OsPath mod, Mod::ModData& data)
|
||||
{
|
||||
std::string text;
|
||||
if (!LoadModJSON(vfs, modsPath, mod, text))
|
||||
@@ -245,7 +245,7 @@ bool Mod::AreModsPlayCompatible(const std::vector<const Mod::ModData*>& modsA, c
|
||||
return true;
|
||||
}
|
||||
|
||||
void Mod::UpdateAvailableMods(const ScriptInterface& scriptInterface)
|
||||
void Mod::UpdateAvailableMods(const Script::Interface& scriptInterface)
|
||||
{
|
||||
PROFILE2("UpdateAvailableMods");
|
||||
|
||||
@@ -265,7 +265,7 @@ void Mod::UpdateAvailableMods(const ScriptInterface& scriptInterface)
|
||||
|
||||
PIVFS vfs = CreateVfs();
|
||||
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
for (DirectoryNames::iterator iter = modDirs.begin(); iter != modDirs.end(); ++iter)
|
||||
{
|
||||
ModData data;
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
#define g_Mods (Mod::Instance())
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
* TODO: if this did not need the scriptInterface to parse JSON,
|
||||
* we could run it in different contexts and possibly cleaner.
|
||||
*/
|
||||
void UpdateAvailableMods(const ScriptInterface& scriptInterface);
|
||||
void UpdateAvailableMods(const Script::Interface& scriptInterface);
|
||||
|
||||
/**
|
||||
* Enables specified mods (& mods required by the engine).
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -26,9 +26,9 @@
|
||||
#include "ps/Errors.h"
|
||||
#include "ps/Filesystem.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <js/PropertyAndElement.h>
|
||||
#include <js/RootingAPI.h>
|
||||
@@ -60,7 +60,7 @@ CModInstaller::~CModInstaller()
|
||||
|
||||
CModInstaller::ModInstallationResult CModInstaller::Install(
|
||||
const OsPath& mod,
|
||||
const std::shared_ptr<ScriptContext>& scriptContext,
|
||||
const std::shared_ptr<Script::Context>& scriptContext,
|
||||
bool keepFile)
|
||||
{
|
||||
const OsPath modTemp = m_TempDir / mod.Basename() / mod.Filename().ChangeExtension(L".zip");
|
||||
@@ -92,8 +92,8 @@ CModInstaller::ModInstallationResult CModInstaller::Install(
|
||||
// Extract the name of the mod
|
||||
CStr modName;
|
||||
{
|
||||
ScriptInterface scriptInterface("Engine", "ModInstaller", scriptContext);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Interface scriptInterface("Engine", "ModInstaller", scriptContext);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue json_val(rq.cx);
|
||||
if (!Script::ParseJSON(rq, modinfo.GetAsString(), &json_val))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class ScriptContext;
|
||||
namespace Script { class Context; }
|
||||
|
||||
/**
|
||||
* Install a mod into the mods directory.
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
*/
|
||||
ModInstallationResult Install(
|
||||
const OsPath& mod,
|
||||
const std::shared_ptr<ScriptContext>& scriptContext,
|
||||
const std::shared_ptr<Script::Context>& scriptContext,
|
||||
bool keepFile);
|
||||
|
||||
/**
|
||||
|
||||
+11
-11
@@ -40,9 +40,9 @@
|
||||
#include "ps/ModInstaller.h"
|
||||
#include "ps/Util.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/ScriptContext.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Context.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
@@ -59,7 +59,7 @@
|
||||
#include <js/Value.h>
|
||||
#include <system_error>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
ModIo* g_ModIo = nullptr;
|
||||
|
||||
@@ -412,7 +412,7 @@ void ModIo::CancelRequest()
|
||||
}
|
||||
}
|
||||
|
||||
bool ModIo::AdvanceRequest(const ScriptInterface& scriptInterface)
|
||||
bool ModIo::AdvanceRequest(const Script::Interface& scriptInterface)
|
||||
{
|
||||
// If the request was cancelled, stop trying to advance it
|
||||
if (m_DownloadProgressData.status != DownloadProgressStatus::GAMEID &&
|
||||
@@ -526,7 +526,7 @@ bool ModIo::AdvanceRequest(const ScriptInterface& scriptInterface)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModIo::ParseGameId(const ScriptInterface& scriptInterface, std::string& err)
|
||||
bool ModIo::ParseGameId(const Script::Interface& scriptInterface, std::string& err)
|
||||
{
|
||||
int id = -1;
|
||||
bool ret = ParseGameIdResponse(scriptInterface, m_ResponseData, id, err);
|
||||
@@ -538,7 +538,7 @@ bool ModIo::ParseGameId(const ScriptInterface& scriptInterface, std::string& err
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModIo::ParseMods(const ScriptInterface& scriptInterface, std::string& err)
|
||||
bool ModIo::ParseMods(const Script::Interface& scriptInterface, std::string& err)
|
||||
{
|
||||
bool ret = ParseModsResponse(scriptInterface, m_ResponseData, m_ModData, m_pk, err);
|
||||
m_ResponseData.clear();
|
||||
@@ -623,10 +623,10 @@ bool ModIo::VerifyDownloadedFile(std::string& err)
|
||||
*
|
||||
* @returns true iff it successfully parsed the id.
|
||||
*/
|
||||
bool ModIo::ParseGameIdResponse(const ScriptInterface& scriptInterface, const std::string& responseData, int& id, std::string& err)
|
||||
bool ModIo::ParseGameIdResponse(const Script::Interface& scriptInterface, const std::string& responseData, int& id, std::string& err)
|
||||
{
|
||||
#define CLEANUP() id = -1;
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue gameResponse(rq.cx);
|
||||
|
||||
@@ -689,12 +689,12 @@ bool ModIo::ParseGameIdResponse(const ScriptInterface& scriptInterface, const st
|
||||
* Only the listed properties are of interest to consumers, and we flatten
|
||||
* the modfile structure as that simplifies handling and there are no conflicts.
|
||||
*/
|
||||
bool ModIo::ParseModsResponse(const ScriptInterface& scriptInterface, const std::string& responseData, std::vector<ModIoModData>& modData, const PKStruct& pk, std::string& err)
|
||||
bool ModIo::ParseModsResponse(const Script::Interface& scriptInterface, const std::string& responseData, std::vector<ModIoModData>& modData, const PKStruct& pk, std::string& err)
|
||||
{
|
||||
// Make sure we don't end up passing partial results back
|
||||
#define CLEANUP() modData.clear();
|
||||
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue modResponse(rq.cx);
|
||||
|
||||
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -34,7 +34,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
// TODO: Allocate instance of the below two using sodium_malloc?
|
||||
struct PKStruct
|
||||
@@ -147,7 +147,7 @@ public:
|
||||
* @param scriptInterface used for parsing the data and possibly install the mod.
|
||||
* @return true if the download is complete (successful or not), false otherwise.
|
||||
*/
|
||||
bool AdvanceRequest(const ScriptInterface& scriptInterface);
|
||||
bool AdvanceRequest(const Script::Interface& scriptInterface);
|
||||
|
||||
/**
|
||||
* Cancel the current async request and clean things up
|
||||
@@ -171,15 +171,15 @@ private:
|
||||
CURLMcode SetupRequest(const std::string& url, bool fileDownload);
|
||||
void TearDownRequest();
|
||||
|
||||
bool ParseGameId(const ScriptInterface& scriptInterface, std::string& err);
|
||||
bool ParseMods(const ScriptInterface& scriptInterface, std::string& err);
|
||||
bool ParseGameId(const Script::Interface& scriptInterface, std::string& err);
|
||||
bool ParseMods(const Script::Interface& scriptInterface, std::string& err);
|
||||
|
||||
void DeleteDownloadedFile();
|
||||
bool VerifyDownloadedFile(std::string& err);
|
||||
|
||||
// Utility methods for parsing mod.io responses and metadata
|
||||
static bool ParseGameIdResponse(const ScriptInterface& scriptInterface, const std::string& responseData, int& id, std::string& err);
|
||||
static bool ParseModsResponse(const ScriptInterface& scriptInterface, const std::string& responseData, std::vector<ModIoModData>& modData, const PKStruct& pk, std::string& err);
|
||||
static bool ParseGameIdResponse(const Script::Interface& scriptInterface, const std::string& responseData, int& id, std::string& err);
|
||||
static bool ParseModsResponse(const Script::Interface& scriptInterface, const std::string& responseData, std::vector<ModIoModData>& modData, const PKStruct& pk, std::string& err);
|
||||
static bool ParseSignature(const std::vector<std::string>& minisigs, SigStruct& sig, const PKStruct& pk, std::string& err);
|
||||
|
||||
// Url parts
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "ps/Pyrogenesis.h"
|
||||
#include "ps/VideoMode.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_keycode.h>
|
||||
@@ -49,7 +49,7 @@
|
||||
#include <js/Value.h>
|
||||
#include <string>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
struct CProfileViewerInternals
|
||||
{
|
||||
@@ -448,12 +448,12 @@ namespace
|
||||
|
||||
struct DumpTable
|
||||
{
|
||||
const ScriptInterface& m_ScriptInterface;
|
||||
const Script::Interface& m_ScriptInterface;
|
||||
JS::PersistentRooted<JS::Value> m_Root;
|
||||
DumpTable(const ScriptInterface& scriptInterface, JS::HandleValue root) :
|
||||
DumpTable(const Script::Interface& scriptInterface, JS::HandleValue root) :
|
||||
m_ScriptInterface(scriptInterface)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
m_Root.init(rq.cx, root);
|
||||
}
|
||||
|
||||
@@ -462,13 +462,13 @@ namespace
|
||||
DumpTable(DumpTable && original) :
|
||||
m_ScriptInterface(original.m_ScriptInterface)
|
||||
{
|
||||
ScriptRequest rq(m_ScriptInterface);
|
||||
Script::Request rq(m_ScriptInterface);
|
||||
m_Root.init(rq.cx, original.m_Root.get());
|
||||
}
|
||||
|
||||
void operator() (AbstractProfileTable* table)
|
||||
{
|
||||
ScriptRequest rq(m_ScriptInterface);
|
||||
Script::Request rq(m_ScriptInterface);
|
||||
|
||||
JS::RootedValue t(rq.cx);
|
||||
Script::CreateObject(
|
||||
@@ -494,7 +494,7 @@ namespace
|
||||
|
||||
JS::Value DumpRows(AbstractProfileTable* table)
|
||||
{
|
||||
ScriptRequest rq(m_ScriptInterface);
|
||||
Script::Request rq(m_ScriptInterface);
|
||||
|
||||
JS::RootedValue data(rq.cx);
|
||||
Script::CreateObject(rq, &data);
|
||||
|
||||
+15
-15
@@ -41,10 +41,10 @@
|
||||
#include "ps/VisualReplay.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptContext.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/ScriptStats.h"
|
||||
#include "scriptinterface/Context.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
#include "scriptinterface/Stats.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
#include "simulation2/components/ICmpGuiInterface.h"
|
||||
#include "simulation2/helpers/Player.h"
|
||||
@@ -62,7 +62,7 @@
|
||||
*/
|
||||
static const int PROFILE_TURN_INTERVAL = 20;
|
||||
|
||||
CReplayLogger::CReplayLogger(const ScriptInterface& scriptInterface) :
|
||||
CReplayLogger::CReplayLogger(const Script::Interface& scriptInterface) :
|
||||
m_ScriptInterface(scriptInterface), m_Stream(NULL)
|
||||
{
|
||||
}
|
||||
@@ -74,7 +74,7 @@ CReplayLogger::~CReplayLogger()
|
||||
|
||||
void CReplayLogger::StartGame(JS::MutableHandleValue attribs)
|
||||
{
|
||||
ScriptRequest rq(m_ScriptInterface);
|
||||
Script::Request rq(m_ScriptInterface);
|
||||
|
||||
// Add timestamp, since the file-modification-date can change
|
||||
Script::SetProperty(rq, attribs, "timestamp", (double)std::time(nullptr));
|
||||
@@ -94,7 +94,7 @@ void CReplayLogger::StartGame(JS::MutableHandleValue attribs)
|
||||
|
||||
void CReplayLogger::Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands)
|
||||
{
|
||||
ScriptRequest rq(m_ScriptInterface);
|
||||
Script::Request rq(m_ScriptInterface);
|
||||
|
||||
*m_Stream << "turn " << n << " " << turnLength << "\n";
|
||||
|
||||
@@ -122,8 +122,8 @@ void CReplayLogger::SaveMetadata(const CSimulation2& simulation)
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptInterface& scriptInterface = simulation.GetScriptInterface();
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Interface& scriptInterface = simulation.GetScriptInterface();
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue arg(rq.cx);
|
||||
JS::RootedValue metadata(rq.cx);
|
||||
@@ -198,12 +198,12 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
|
||||
|
||||
new CProfileViewer;
|
||||
new CProfileManager;
|
||||
g_ScriptStatsTable = new CScriptStatsTable;
|
||||
g_ScriptStatsTable = new Script::CScriptStatsTable;
|
||||
g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
|
||||
|
||||
const int contextSize = 384 * 1024 * 1024;
|
||||
const int heapGrowthBytesGCTrigger = 12 * 1024 * 1024;
|
||||
g_ScriptContext = std::make_shared<ScriptContext>(contextSize, heapGrowthBytesGCTrigger);
|
||||
g_ScriptContext = std::make_shared<Script::Context>(contextSize, heapGrowthBytesGCTrigger);
|
||||
|
||||
std::vector<SimulationCommand> commands;
|
||||
u32 turn = 0;
|
||||
@@ -218,8 +218,8 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
|
||||
{
|
||||
std::string attribsStr;
|
||||
{
|
||||
ScriptInterface scriptInterface("Engine", "Replay", g_ScriptContext);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Interface scriptInterface("Engine", "Replay", g_ScriptContext);
|
||||
Script::Request rq(scriptInterface);
|
||||
std::getline(*m_Stream, attribsStr);
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
if (!Script::ParseJSON(rq, attribsStr, &attribs))
|
||||
@@ -266,7 +266,7 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
|
||||
|
||||
g_Game = new CGame(false, debugOption);
|
||||
|
||||
ScriptRequest rq(g_Game->GetSimulation2()->GetScriptInterface());
|
||||
Script::Request rq(g_Game->GetSimulation2()->GetScriptInterface());
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
ENSURE(Script::ParseJSON(rq, attribsStr, &attribs));
|
||||
g_Game->StartGame(&attribs, "");
|
||||
@@ -289,7 +289,7 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
|
||||
|
||||
std::string line;
|
||||
std::getline(*m_Stream, line);
|
||||
ScriptRequest rq(g_Game->GetSimulation2()->GetScriptInterface());
|
||||
Script::Request rq(g_Game->GetSimulation2()->GetScriptInterface());
|
||||
JS::RootedValue data(rq.cx);
|
||||
Script::ParseJSON(rq, line, &data);
|
||||
Script::DeepFreezeObject(rq, data);
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@
|
||||
#include <vector>
|
||||
|
||||
class CSimulation2;
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
struct SimulationCommand;
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ class CReplayLogger : public IReplayLogger
|
||||
{
|
||||
NONCOPYABLE(CReplayLogger);
|
||||
public:
|
||||
CReplayLogger(const ScriptInterface& scriptInterface);
|
||||
CReplayLogger(const Script::Interface& scriptInterface);
|
||||
~CReplayLogger();
|
||||
|
||||
virtual void StartGame(JS::MutableHandleValue attribs);
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
virtual OsPath GetDirectory() const;
|
||||
|
||||
private:
|
||||
const ScriptInterface& m_ScriptInterface;
|
||||
const Script::Interface& m_ScriptInterface;
|
||||
std::ostream* m_Stream;
|
||||
OsPath m_Directory;
|
||||
};
|
||||
|
||||
+13
-13
@@ -44,8 +44,8 @@
|
||||
#include "ps/Pyrogenesis.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
#include "scriptinterface/StructuredClone.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
// TODO: we ought to check version numbers when loading files
|
||||
|
||||
@@ -80,7 +80,7 @@ Status SavedGames::SavePrefix(const CStrW& prefix, const CStrW& description, CSi
|
||||
|
||||
Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const Script::StructuredClone& guiMetadataClone)
|
||||
{
|
||||
ScriptRequest rq(simulation.GetScriptInterface());
|
||||
Script::Request rq(simulation.GetScriptInterface());
|
||||
|
||||
// Determine the filename to save under
|
||||
const VfsPath basenameFormat(L"saves/" + name);
|
||||
@@ -180,7 +180,7 @@ class CGameLoader
|
||||
public:
|
||||
|
||||
/**
|
||||
* @param scriptInterface the ScriptInterface used for loading metadata.
|
||||
* @param scriptInterface the Script::Interface used for loading metadata.
|
||||
* @param[out] savedState serialized simulation state stored as string of bytes,
|
||||
* loaded from simulation.dat inside the archive.
|
||||
*
|
||||
@@ -189,11 +189,11 @@ public:
|
||||
* for the metadata because it would be error prone with rooting and the stack-based rooting
|
||||
* types and confusing (a chain of pointers pointing to other pointers).
|
||||
*/
|
||||
CGameLoader(const ScriptInterface& scriptInterface, std::string* savedState) :
|
||||
CGameLoader(const Script::Interface& scriptInterface, std::string* savedState) :
|
||||
m_ScriptInterface(scriptInterface),
|
||||
m_SavedState(savedState)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
m_Metadata.init(rq.cx);
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ public:
|
||||
std::string buffer;
|
||||
buffer.resize(fileInfo.Size());
|
||||
WARN_IF_ERR(archiveFile->Load("", DummySharedPtr((u8*)buffer.data()), buffer.size()));
|
||||
Script::ParseJSON(ScriptRequest(m_ScriptInterface), buffer, &m_Metadata);
|
||||
Script::ParseJSON(Script::Request(m_ScriptInterface), buffer, &m_Metadata);
|
||||
}
|
||||
else if (pathname == L"simulation.dat" && m_SavedState)
|
||||
{
|
||||
@@ -225,12 +225,12 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
const ScriptInterface& m_ScriptInterface;
|
||||
const Script::Interface& m_ScriptInterface;
|
||||
JS::PersistentRooted<JS::Value> m_Metadata;
|
||||
std::string* m_SavedState;
|
||||
};
|
||||
|
||||
std::optional<SavedGames::LoadResult> SavedGames::Load(const ScriptInterface& scriptInterface,
|
||||
std::optional<SavedGames::LoadResult> SavedGames::Load(const Script::Interface& scriptInterface,
|
||||
const std::wstring& name)
|
||||
{
|
||||
// Determine the filename to load
|
||||
@@ -269,17 +269,17 @@ std::optional<SavedGames::LoadResult> SavedGames::Load(const ScriptInterface& sc
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
const ScriptRequest rq{scriptInterface};
|
||||
const Script::Request rq{scriptInterface};
|
||||
JS::RootedValue metadata{rq.cx, loader.GetMetadata()};
|
||||
|
||||
// `std::make_optional` can't be used since `LoadResult` doesn't have a constructor.
|
||||
return {{metadata, std::move(savedState)}};
|
||||
}
|
||||
|
||||
JS::Value SavedGames::GetSavedGames(const ScriptInterface& scriptInterface)
|
||||
JS::Value SavedGames::GetSavedGames(const Script::Interface& scriptInterface)
|
||||
{
|
||||
PROFILE2("GetSavedGames");
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValueVector games{rq.cx};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
class CSimulation2;
|
||||
class CStrW;
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
/**
|
||||
* @file
|
||||
@@ -82,15 +82,15 @@ namespace SavedGames
|
||||
* @param scriptInterface
|
||||
* @return An empty `std::optional` if an error ocoured.
|
||||
*/
|
||||
std::optional<LoadResult> Load(const ScriptInterface& scriptInterface, const std::wstring& name);
|
||||
std::optional<LoadResult> Load(const Script::Interface& scriptInterface, const std::wstring& name);
|
||||
|
||||
/**
|
||||
* Get list of saved games for GUI script usage
|
||||
*
|
||||
* @param scriptInterface the ScriptInterface in which to create the return data.
|
||||
* @param scriptInterface the Script::Interface in which to create the return data.
|
||||
* @return array of objects containing saved game data
|
||||
*/
|
||||
JS::Value GetSavedGames(const ScriptInterface& scriptInterface);
|
||||
JS::Value GetSavedGames(const Script::Interface& scriptInterface);
|
||||
|
||||
/**
|
||||
* Permanently deletes the saved game archive with the given name
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
#include "renderer/backend/dummy/DeviceForward.h"
|
||||
#include "renderer/backend/gl/DeviceForward.h"
|
||||
#include "renderer/backend/vulkan/DeviceForward.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_error.h>
|
||||
|
||||
+17
-17
@@ -38,7 +38,7 @@
|
||||
#include "ps/Pyrogenesis.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_quit.h>
|
||||
@@ -91,7 +91,7 @@ bool VisualReplay::StartVisualReplay(const OsPath& directory)
|
||||
return g_Game->StartVisualReplay(replayFile);
|
||||
}
|
||||
|
||||
bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject)
|
||||
bool VisualReplay::ReadCacheFile(const Script::Interface& scriptInterface, JS::MutableHandleObject cachedReplaysObject)
|
||||
{
|
||||
if (!std::filesystem::is_regular_file(GetCacheFilePath().string()))
|
||||
return false;
|
||||
@@ -100,7 +100,7 @@ bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::Mut
|
||||
CStr cacheStr((std::istreambuf_iterator<char>(cacheStream)), std::istreambuf_iterator<char>());
|
||||
cacheStream.close();
|
||||
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue cachedReplays(rq.cx);
|
||||
if (Script::ParseJSON(rq, cacheStr, &cachedReplays))
|
||||
@@ -117,9 +117,9 @@ bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::Mut
|
||||
return false;
|
||||
}
|
||||
|
||||
void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays)
|
||||
void VisualReplay::StoreCacheFile(const Script::Interface& scriptInterface, JS::HandleObject replays)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue replaysRooted(rq.cx, JS::ObjectValue(*replays));
|
||||
std::ofstream cacheStream(OsString(GetTempCacheFilePath()), std::ofstream::out | std::ofstream::trunc);
|
||||
@@ -132,10 +132,10 @@ void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::Ha
|
||||
LOGERROR("Could not store the replay cache");
|
||||
}
|
||||
|
||||
JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles)
|
||||
JS::HandleObject VisualReplay::ReloadReplayCache(const Script::Interface& scriptInterface, bool compareFiles)
|
||||
{
|
||||
PROFILE2("ReloadReplayCache");
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
// Maps the filename onto the index, mtime and size
|
||||
using replayCacheMap = std::map<OsPath, std::tuple<u32, u64, off_t>>;
|
||||
@@ -252,11 +252,11 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptIn
|
||||
return replays;
|
||||
}
|
||||
|
||||
JS::Value VisualReplay::GetReplays(const ScriptInterface& scriptInterface, bool compareFiles)
|
||||
JS::Value VisualReplay::GetReplays(const Script::Interface& scriptInterface, bool compareFiles)
|
||||
{
|
||||
PROFILE2("GetReplays");
|
||||
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
JS::RootedObject replays(rq.cx, ReloadReplayCache(scriptInterface, compareFiles));
|
||||
// Only take entries with data
|
||||
JS::RootedValueVector replaysWithoutNullEntries{rq.cx};
|
||||
@@ -358,7 +358,7 @@ inline int getReplayDuration(std::istream* replayStream, const OsPath& fileName,
|
||||
return -1;
|
||||
}
|
||||
|
||||
JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory)
|
||||
JS::Value VisualReplay::LoadReplayData(const Script::Interface& scriptInterface, const OsPath& directory)
|
||||
{
|
||||
// The directory argument must not be constant, otherwise concatenating will fail
|
||||
const OsPath replayFile = GetDirectoryPath() / directory / L"commands.txt";
|
||||
@@ -394,7 +394,7 @@ JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, c
|
||||
// Parse header / first line
|
||||
CStr header;
|
||||
std::getline(*replayStream, header);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
if (!Script::ParseJSON(rq, header, &attribs))
|
||||
{
|
||||
@@ -452,10 +452,10 @@ bool VisualReplay::DeleteReplay(const OsPath& replayDirectory)
|
||||
return DirectoryExists(directory) && DeleteDirectory(directory) == INFO::OK;
|
||||
}
|
||||
|
||||
JS::Value VisualReplay::GetReplayAttributes(const ScriptInterface& scriptInterface, const OsPath& directoryName)
|
||||
JS::Value VisualReplay::GetReplayAttributes(const Script::Interface& scriptInterface, const OsPath& directoryName)
|
||||
{
|
||||
// Create empty JS object
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
Script::CreateObject(rq, &attribs);
|
||||
|
||||
@@ -476,10 +476,10 @@ JS::Value VisualReplay::GetReplayAttributes(const ScriptInterface& scriptInterfa
|
||||
return attribs;
|
||||
}
|
||||
|
||||
void VisualReplay::AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName)
|
||||
void VisualReplay::AddReplayToCache(const Script::Interface& scriptInterface, const CStrW& directoryName)
|
||||
{
|
||||
PROFILE2("AddReplayToCache");
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue replayData(rq.cx, LoadReplayData(scriptInterface, OsPath(directoryName)));
|
||||
if (replayData.isNull())
|
||||
@@ -509,12 +509,12 @@ bool VisualReplay::HasReplayMetadata(const OsPath& directoryName)
|
||||
return fileInfo.Size() > 0;
|
||||
}
|
||||
|
||||
JS::Value VisualReplay::GetReplayMetadata(const ScriptInterface& scriptInterface, const OsPath& directoryName)
|
||||
JS::Value VisualReplay::GetReplayMetadata(const Script::Interface& scriptInterface, const OsPath& directoryName)
|
||||
{
|
||||
if (!HasReplayMetadata(directoryName))
|
||||
return JS::NullValue();
|
||||
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
JS::RootedValue metadata(rq.cx);
|
||||
|
||||
std::ifstream* stream = new std::ifstream(OsString(GetDirectoryPath() / directoryName / L"metadata.json"));
|
||||
|
||||
+14
-14
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -23,8 +23,8 @@
|
||||
#include <js/TypeDecls.h>
|
||||
|
||||
class CStrW;
|
||||
class ScriptInterface;
|
||||
namespace JS { class Value; }
|
||||
namespace Script { class Interface; }
|
||||
|
||||
/**
|
||||
* Contains functions for visually replaying past games.
|
||||
@@ -56,44 +56,44 @@ bool StartVisualReplay(const OsPath& directory);
|
||||
/**
|
||||
* Reads the replay Cache file and parses it into a jsObject
|
||||
*
|
||||
* @param scriptInterface - the ScriptInterface in which to create the return data.
|
||||
* @param scriptInterface - the Script::Interface in which to create the return data.
|
||||
* @param cachedReplaysObject - the cached replays.
|
||||
* @return true on succes
|
||||
*/
|
||||
bool ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject);
|
||||
bool ReadCacheFile(const Script::Interface& scriptInterface, JS::MutableHandleObject cachedReplaysObject);
|
||||
|
||||
/**
|
||||
* Stores the replay list in the replay cache file
|
||||
*
|
||||
* @param scriptInterface - the ScriptInterface in which to create the return data.
|
||||
* @param scriptInterface - the Script::Interface in which to create the return data.
|
||||
* @param replays - the replay list to store.
|
||||
*/
|
||||
void StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays);
|
||||
void StoreCacheFile(const Script::Interface& scriptInterface, JS::HandleObject replays);
|
||||
|
||||
/**
|
||||
* Load the replay cache and check if there are new/deleted replays. If so, update the cache.
|
||||
*
|
||||
* @param scriptInterface - the ScriptInterface in which to create the return data.
|
||||
* @param scriptInterface - the Script::Interface in which to create the return data.
|
||||
* @param compareFiles - compare the directory name and the FileSize of the replays and the cache.
|
||||
* @return cache entries
|
||||
*/
|
||||
JS::HandleObject ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles);
|
||||
JS::HandleObject ReloadReplayCache(const Script::Interface& scriptInterface, bool compareFiles);
|
||||
|
||||
/**
|
||||
* Get a list of replays to display in the GUI.
|
||||
*
|
||||
* @param scriptInterface - the ScriptInterface in which to create the return data.
|
||||
* @param scriptInterface - the Script::Interface in which to create the return data.
|
||||
* @param compareFiles - reload the cache, which takes more time,
|
||||
* but nearly ensures, that no changed replay is missed.
|
||||
* @return array of objects containing replay data
|
||||
*/
|
||||
JS::Value GetReplays(const ScriptInterface& scriptInterface, bool compareFiles);
|
||||
JS::Value GetReplays(const Script::Interface& scriptInterface, bool compareFiles);
|
||||
|
||||
/**
|
||||
* Parses a commands.txt file and extracts metadata.
|
||||
* Works similarly to CGame::LoadReplayData().
|
||||
*/
|
||||
JS::Value LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory);
|
||||
JS::Value LoadReplayData(const Script::Interface& scriptInterface, const OsPath& directory);
|
||||
|
||||
/**
|
||||
* Permanently deletes the visual replay (including the parent directory)
|
||||
@@ -106,7 +106,7 @@ bool DeleteReplay(const OsPath& replayFile);
|
||||
/**
|
||||
* Returns the parsed header of the replay file (commands.txt).
|
||||
*/
|
||||
JS::Value GetReplayAttributes(const ScriptInterface& scriptInterface, const OsPath& directoryName);
|
||||
JS::Value GetReplayAttributes(const Script::Interface& scriptInterface, const OsPath& directoryName);
|
||||
|
||||
/**
|
||||
* Returns whether or not the metadata / summary screen data has been saved properly when the game ended.
|
||||
@@ -116,12 +116,12 @@ bool HasReplayMetadata(const OsPath& directoryName);
|
||||
/**
|
||||
* Returns the metadata of a replay.
|
||||
*/
|
||||
JS::Value GetReplayMetadata(const ScriptInterface& scriptInterface, const OsPath& directoryName);
|
||||
JS::Value GetReplayMetadata(const Script::Interface& scriptInterface, const OsPath& directoryName);
|
||||
|
||||
/**
|
||||
* Adds a replay to the replayCache.
|
||||
*/
|
||||
void AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName);
|
||||
void AddReplayToCache(const Script::Interface& scriptInterface, const CStrW& directoryName);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -66,7 +66,7 @@ CWorld::~CWorld() = default;
|
||||
/**
|
||||
* Initializes the game world with the attributes provided.
|
||||
**/
|
||||
void CWorld::RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::HandleValue settings, int playerID)
|
||||
void CWorld::RegisterInit(const CStrW& mapFile, const Script::Context& cx, JS::HandleValue settings, int playerID)
|
||||
{
|
||||
// Load the map, if one was specified
|
||||
if (mapFile.length())
|
||||
@@ -100,7 +100,7 @@ void CWorld::RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::Han
|
||||
}
|
||||
}
|
||||
|
||||
void CWorld::RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, int playerID)
|
||||
void CWorld::RegisterInitRMS(const CStrW& scriptFile, const Script::Context& cx, JS::HandleValue settings, int playerID)
|
||||
{
|
||||
// If scriptFile is empty, a blank map will be generated using settings (no RMS run)
|
||||
CTriggerManager* pTriggerManager = nullptr;
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -34,7 +34,7 @@ class CMapReader;
|
||||
class CStrW;
|
||||
class CTerrain;
|
||||
class CUnitManager;
|
||||
class ScriptContext;
|
||||
namespace Script { class Context; }
|
||||
|
||||
#ifndef ERROR_GROUP_GAME_DEFINED
|
||||
#define ERROR_GROUP_GAME_DEFINED
|
||||
@@ -56,12 +56,12 @@ public:
|
||||
/*
|
||||
Initialize the World - load the map and all objects
|
||||
*/
|
||||
void RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::HandleValue settings, int playerID);
|
||||
void RegisterInit(const CStrW& mapFile, const Script::Context& cx, JS::HandleValue settings, int playerID);
|
||||
|
||||
/*
|
||||
Initialize the World - generate and load the random map
|
||||
*/
|
||||
void RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, int playerID);
|
||||
void RegisterInitRMS(const CStrW& scriptFile, const Script::Context& cx, JS::HandleValue settings, int playerID);
|
||||
|
||||
/**
|
||||
* Explicitly delete m_MapReader once the map has finished loading.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -24,9 +24,9 @@
|
||||
#include "lib/file/vfs/vfs.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <js/Array.h>
|
||||
@@ -155,7 +155,7 @@ void XMBStorageWriter::OutputNames(WriteBuffer& writeBuffer, const std::unordere
|
||||
class JSNodeData
|
||||
{
|
||||
public:
|
||||
JSNodeData(const ScriptInterface& s) : scriptInterface(s), rq(s) {}
|
||||
JSNodeData(const Script::Interface& s) : scriptInterface(s), rq(s) {}
|
||||
|
||||
bool Setup(XMBStorageWriter& xmb, JS::HandleValue value);
|
||||
bool Output(WriteBuffer& writeBuffer, JS::HandleValue value) const;
|
||||
@@ -163,8 +163,8 @@ public:
|
||||
std::vector<std::pair<u32, std::string>> m_Attributes;
|
||||
std::vector<std::pair<u32, JS::Heap<JS::Value>>> m_Children;
|
||||
|
||||
const ScriptInterface& scriptInterface;
|
||||
const ScriptRequest rq;
|
||||
const Script::Interface& scriptInterface;
|
||||
const Script::Request rq;
|
||||
};
|
||||
|
||||
template<>
|
||||
@@ -470,7 +470,7 @@ bool XMBStorage::LoadXMLDoc(const xmlDocPtr doc)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool XMBStorage::LoadJSValue(const ScriptInterface& scriptInterface, JS::HandleValue value, const std::string& rootName)
|
||||
bool XMBStorage::LoadJSValue(const Script::Interface& scriptInterface, JS::HandleValue value, const std::string& rootName)
|
||||
{
|
||||
WriteBuffer writeBuffer;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
typedef struct _xmlDoc xmlDoc;
|
||||
typedef xmlDoc* xmlDocPtr;
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
* </a>
|
||||
* See also tests for some other examples.
|
||||
*/
|
||||
bool LoadJSValue(const ScriptInterface& scriptInterface, JS::HandleValue value, const std::string& rootName);
|
||||
bool LoadJSValue(const Script::Interface& scriptInterface, JS::HandleValue value, const std::string& rootName);
|
||||
|
||||
std::shared_ptr<u8> m_Buffer;
|
||||
size_t m_Size = 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -22,8 +22,8 @@
|
||||
#include "ps/XMB/XMBData.h"
|
||||
#include "ps/XMB/XMBStorage.h"
|
||||
#include "ps/XML/Xeromyces.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <js/RootingAPI.h>
|
||||
@@ -38,7 +38,7 @@ class TestXMBData : public CxxTest::TestSuite
|
||||
private:
|
||||
std::shared_ptr<u8> m_Buffer;
|
||||
|
||||
std::unique_ptr<ScriptInterface> m_ScriptInterface;
|
||||
std::unique_ptr<Script::Interface> m_ScriptInterface;
|
||||
|
||||
CXeromyces parseXML(const char* doc)
|
||||
{
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
|
||||
CXeromyces parseJS(const std::string rootName, const char* code)
|
||||
{
|
||||
ScriptRequest rq(*m_ScriptInterface);
|
||||
Script::Request rq(*m_ScriptInterface);
|
||||
JS::RootedValue val(rq.cx);
|
||||
m_ScriptInterface->Eval(code, &val);
|
||||
CXeromyces xmb;
|
||||
@@ -68,7 +68,7 @@ private:
|
||||
|
||||
void setUp()
|
||||
{
|
||||
m_ScriptInterface = std::make_unique<ScriptInterface>("Test", "Test", g_ScriptContext);
|
||||
m_ScriptInterface = std::make_unique<Script::Interface>("Test", "Test", g_ScriptContext);
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -208,20 +208,20 @@ void SetGUIScale(float scale)
|
||||
g_VideoMode.Rescale(scale);
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&HasChanges>(rq, "ConfigDB_HasChanges");
|
||||
ScriptFunction::Register<&SetChanges>(rq, "ConfigDB_SetChanges");
|
||||
ScriptFunction::Register<&GetValue>(rq, "ConfigDB_GetValue");
|
||||
ScriptFunction::Register<&CreateValue>(rq, "ConfigDB_CreateValue");
|
||||
ScriptFunction::Register<&CreateValues>(rq, "ConfigDB_CreateValues");
|
||||
ScriptFunction::Register<&RemoveValue>(rq, "ConfigDB_RemoveValue");
|
||||
ScriptFunction::Register<&RemoveValueAndSave>(rq, "ConfigDB_RemoveValueAndSave");
|
||||
ScriptFunction::Register<&SaveChanges>(rq, "ConfigDB_SaveChanges");
|
||||
ScriptFunction::Register<&SaveValue>(rq, "ConfigDB_SaveValue");
|
||||
ScriptFunction::Register<&CreateAndSaveValue>(rq, "ConfigDB_CreateAndSaveValue");
|
||||
ScriptFunction::Register<&Reload>(rq, "ConfigDB_Reload");
|
||||
ScriptFunction::Register<&PauseOnFocusLoss>(rq, "PauseOnFocusLoss");
|
||||
ScriptFunction::Register<&SetGUIScale>(rq, "SetGUIScale");
|
||||
Script::Function::Register<&HasChanges>(rq, "ConfigDB_HasChanges");
|
||||
Script::Function::Register<&SetChanges>(rq, "ConfigDB_SetChanges");
|
||||
Script::Function::Register<&GetValue>(rq, "ConfigDB_GetValue");
|
||||
Script::Function::Register<&CreateValue>(rq, "ConfigDB_CreateValue");
|
||||
Script::Function::Register<&CreateValues>(rq, "ConfigDB_CreateValues");
|
||||
Script::Function::Register<&RemoveValue>(rq, "ConfigDB_RemoveValue");
|
||||
Script::Function::Register<&RemoveValueAndSave>(rq, "ConfigDB_RemoveValueAndSave");
|
||||
Script::Function::Register<&SaveChanges>(rq, "ConfigDB_SaveChanges");
|
||||
Script::Function::Register<&SaveValue>(rq, "ConfigDB_SaveValue");
|
||||
Script::Function::Register<&CreateAndSaveValue>(rq, "ConfigDB_CreateAndSaveValue");
|
||||
Script::Function::Register<&Reload>(rq, "ConfigDB_Reload");
|
||||
Script::Function::Register<&PauseOnFocusLoss>(rq, "PauseOnFocusLoss");
|
||||
Script::Function::Register<&SetGUIScale>(rq, "SetGUIScale");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -19,11 +19,11 @@
|
||||
#define INCLUDED_JSI_CONFIGDB
|
||||
|
||||
extern bool g_PauseOnFocusLoss;
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_ConfigDB
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_CONFIGDB
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -27,7 +27,7 @@ namespace JS { class CallArgs; }
|
||||
|
||||
namespace JSI_Console
|
||||
{
|
||||
CConsole* ConsoleGetter(const ScriptRequest&, JS::CallArgs&)
|
||||
CConsole* ConsoleGetter(const Script::Request&, JS::CallArgs&)
|
||||
{
|
||||
if (!g_Console)
|
||||
{
|
||||
@@ -37,9 +37,9 @@ CConsole* ConsoleGetter(const ScriptRequest&, JS::CallArgs&)
|
||||
return g_Console;
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&CConsole::IsActive, ConsoleGetter>(rq, "Console_GetVisibleEnabled");
|
||||
ScriptFunction::Register<&CConsole::SetVisible, ConsoleGetter>(rq, "Console_SetVisibleEnabled");
|
||||
Script::Function::Register<&CConsole::IsActive, ConsoleGetter>(rq, "Console_GetVisibleEnabled");
|
||||
Script::Function::Register<&CConsole::SetVisible, ConsoleGetter>(rq, "Console_SetVisibleEnabled");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_CONSOLE
|
||||
#define INCLUDED_JSI_CONSOLE
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_Console
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_CONSOLE
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -100,14 +100,14 @@ std::wstring GetBuildVersion(bool longerHash = false)
|
||||
return buildVersion;
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&GetMicroseconds>(rq, "GetMicroseconds");
|
||||
ScriptFunction::Register<&Crash>(rq, "Crash");
|
||||
ScriptFunction::Register<&DebugWarn>(rq, "DebugWarn");
|
||||
ScriptFunction::Register<&DisplayErrorDialog>(rq, "DisplayErrorDialog");
|
||||
ScriptFunction::Register<&GetBuildDate>(rq, "GetBuildDate");
|
||||
ScriptFunction::Register<&GetBuildTimestamp>(rq, "GetBuildTimestamp");
|
||||
ScriptFunction::Register<&GetBuildVersion>(rq, "GetBuildVersion");
|
||||
Script::Function::Register<&GetMicroseconds>(rq, "GetMicroseconds");
|
||||
Script::Function::Register<&Crash>(rq, "Crash");
|
||||
Script::Function::Register<&DebugWarn>(rq, "DebugWarn");
|
||||
Script::Function::Register<&DisplayErrorDialog>(rq, "DisplayErrorDialog");
|
||||
Script::Function::Register<&GetBuildDate>(rq, "GetBuildDate");
|
||||
Script::Function::Register<&GetBuildTimestamp>(rq, "GetBuildTimestamp");
|
||||
Script::Function::Register<&GetBuildVersion>(rq, "GetBuildVersion");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_DEBUG
|
||||
#define INCLUDED_JSI_DEBUG
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_Debug
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_DEBUG
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "ps/Replay.h"
|
||||
#include "ps/World.h"
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
#include "scriptinterface/StructuredClone.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
#include "simulation2/system/TurnManager.h"
|
||||
@@ -47,11 +47,11 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
namespace JSI_Game
|
||||
{
|
||||
void StartGame(const ScriptInterface& guiInterface, JS::HandleValue attribs, int playerID, bool storeReplay)
|
||||
void StartGame(const Script::Interface& guiInterface, JS::HandleValue attribs, int playerID, bool storeReplay)
|
||||
{
|
||||
ENSURE(!g_NetServer);
|
||||
ENSURE(!g_NetClient);
|
||||
@@ -61,7 +61,7 @@ void StartGame(const ScriptInterface& guiInterface, JS::HandleValue attribs, int
|
||||
|
||||
// Convert from GUI script context to sim script context/
|
||||
CSimulation2* sim = g_Game->GetSimulation2();
|
||||
ScriptRequest rqSim(sim->GetScriptInterface());
|
||||
Script::Request rqSim(sim->GetScriptInterface());
|
||||
|
||||
JS::RootedValue gameAttribs(rqSim.cx, Script::CloneValueFromOtherCompartment(sim->GetScriptInterface(), guiInterface, attribs));
|
||||
|
||||
@@ -193,22 +193,22 @@ void DumpTerrainMipmap()
|
||||
LOGMESSAGERENDER("Terrain mipmap written to '%s'", realPath.string8());
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&StartGame>(rq, "StartGame");
|
||||
ScriptFunction::Register<&Script_EndGame>(rq, "EndGame");
|
||||
ScriptFunction::Register<&GetPlayerID>(rq, "GetPlayerID");
|
||||
ScriptFunction::Register<&SetPlayerID>(rq, "SetPlayerID");
|
||||
ScriptFunction::Register<&SetViewedPlayer>(rq, "SetViewedPlayer");
|
||||
ScriptFunction::Register<&GetSimRate>(rq, "GetSimRate");
|
||||
ScriptFunction::Register<&SetSimRate>(rq, "SetSimRate");
|
||||
ScriptFunction::Register<&GetPendingTurns>(rq, "GetPendingTurns");
|
||||
ScriptFunction::Register<&IsPaused>(rq, "IsPaused");
|
||||
ScriptFunction::Register<&SetPaused>(rq, "SetPaused");
|
||||
ScriptFunction::Register<&IsVisualReplay>(rq, "IsVisualReplay");
|
||||
ScriptFunction::Register<&GetCurrentReplayDirectory>(rq, "GetCurrentReplayDirectory");
|
||||
ScriptFunction::Register<&EnableTimeWarpRecording>(rq, "EnableTimeWarpRecording");
|
||||
ScriptFunction::Register<&RewindTimeWarp>(rq, "RewindTimeWarp");
|
||||
ScriptFunction::Register<&DumpTerrainMipmap>(rq, "DumpTerrainMipmap");
|
||||
Script::Function::Register<&StartGame>(rq, "StartGame");
|
||||
Script::Function::Register<&Script_EndGame>(rq, "EndGame");
|
||||
Script::Function::Register<&GetPlayerID>(rq, "GetPlayerID");
|
||||
Script::Function::Register<&SetPlayerID>(rq, "SetPlayerID");
|
||||
Script::Function::Register<&SetViewedPlayer>(rq, "SetViewedPlayer");
|
||||
Script::Function::Register<&GetSimRate>(rq, "GetSimRate");
|
||||
Script::Function::Register<&SetSimRate>(rq, "SetSimRate");
|
||||
Script::Function::Register<&GetPendingTurns>(rq, "GetPendingTurns");
|
||||
Script::Function::Register<&IsPaused>(rq, "IsPaused");
|
||||
Script::Function::Register<&SetPaused>(rq, "SetPaused");
|
||||
Script::Function::Register<&IsVisualReplay>(rq, "IsVisualReplay");
|
||||
Script::Function::Register<&GetCurrentReplayDirectory>(rq, "GetCurrentReplayDirectory");
|
||||
Script::Function::Register<&EnableTimeWarpRecording>(rq, "EnableTimeWarpRecording");
|
||||
Script::Function::Register<&RewindTimeWarp>(rq, "RewindTimeWarp");
|
||||
Script::Function::Register<&DumpTerrainMipmap>(rq, "DumpTerrainMipmap");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_GAME
|
||||
#define INCLUDED_JSI_GAME
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_Game
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_GAME
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -26,8 +26,8 @@
|
||||
#include "ps/KeyName.h"
|
||||
#include "ps/containers/StaticVector.h"
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <SDL_scancode.h>
|
||||
#include <js/PropertyAndElement.h>
|
||||
@@ -48,7 +48,7 @@
|
||||
* TODO: this could be moved to ScriptConversions.cpp if the need arises.
|
||||
*/
|
||||
template<typename T, typename U>
|
||||
static void ToJSVal_unordered_map(const ScriptRequest& rq, JS::MutableHandleValue ret, const std::unordered_map<T, U>& val)
|
||||
static void ToJSVal_unordered_map(const Script::Request& rq, JS::MutableHandleValue ret, const std::unordered_map<T, U>& val)
|
||||
{
|
||||
JS::RootedObject obj(rq.cx, JS_NewPlainObject(rq.cx));
|
||||
if (!obj)
|
||||
@@ -66,13 +66,13 @@ static void ToJSVal_unordered_map(const ScriptRequest& rq, JS::MutableHandleValu
|
||||
}
|
||||
|
||||
template<>
|
||||
void Script::ToJSVal<std::unordered_map<std::string, std::vector<std::vector<std::string>>>>(const ScriptRequest& rq, JS::MutableHandleValue ret, const std::unordered_map<std::string, std::vector<std::vector<std::string>>>& val)
|
||||
void Script::ToJSVal<std::unordered_map<std::string, std::vector<std::vector<std::string>>>>(const Script::Request& rq, JS::MutableHandleValue ret, const std::unordered_map<std::string, std::vector<std::vector<std::string>>>& val)
|
||||
{
|
||||
ToJSVal_unordered_map(rq, ret, val);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Script::ToJSVal<std::unordered_map<std::string, std::string>>(const ScriptRequest& rq, JS::MutableHandleValue ret, const std::unordered_map<std::string, std::string>& val)
|
||||
void Script::ToJSVal<std::unordered_map<std::string, std::string>>(const Script::Request& rq, JS::MutableHandleValue ret, const std::unordered_map<std::string, std::string>& val)
|
||||
{
|
||||
ToJSVal_unordered_map(rq, ret, val);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace
|
||||
/**
|
||||
* @return a (js) object mapping hotkey name (from cfg files) to a list ofscancode names
|
||||
*/
|
||||
JS::Value GetHotkeyMap(const ScriptRequest& rq)
|
||||
JS::Value GetHotkeyMap(const Script::Request& rq)
|
||||
{
|
||||
JS::RootedValue hotkeyMap(rq.cx);
|
||||
|
||||
@@ -108,7 +108,7 @@ JS::Value GetHotkeyMap(const ScriptRequest& rq)
|
||||
/**
|
||||
* @return a (js) object mapping scancode names to their locale-dependent name.
|
||||
*/
|
||||
JS::Value GetScancodeKeyNames(const ScriptRequest& rq)
|
||||
JS::Value GetScancodeKeyNames(const Script::Request& rq)
|
||||
{
|
||||
JS::RootedValue obj(rq.cx);
|
||||
std::unordered_map<std::string, std::string> map;
|
||||
@@ -128,7 +128,7 @@ void ReloadHotkeys()
|
||||
LoadHotkeys(g_ConfigDB);
|
||||
}
|
||||
|
||||
JS::Value GetConflicts(const ScriptRequest& rq, JS::HandleValue combination)
|
||||
JS::Value GetConflicts(const Script::Request& rq, JS::HandleValue combination)
|
||||
{
|
||||
std::vector<std::string> keys;
|
||||
if (!Script::FromJSVal(rq, combination, keys))
|
||||
@@ -172,11 +172,11 @@ JS::Value GetConflicts(const ScriptRequest& rq, JS::HandleValue combination)
|
||||
}
|
||||
}
|
||||
|
||||
void JSI_Hotkey::RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void JSI_Hotkey::RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&HotkeyIsPressed>(rq, "HotkeyIsPressed");
|
||||
ScriptFunction::Register<&GetHotkeyMap>(rq, "GetHotkeyMap");
|
||||
ScriptFunction::Register<&GetScancodeKeyNames>(rq, "GetScancodeKeyNames");
|
||||
ScriptFunction::Register<&ReloadHotkeys>(rq, "ReloadHotkeys");
|
||||
ScriptFunction::Register<&GetConflicts>(rq, "GetConflicts");
|
||||
Script::Function::Register<&HotkeyIsPressed>(rq, "HotkeyIsPressed");
|
||||
Script::Function::Register<&GetHotkeyMap>(rq, "GetHotkeyMap");
|
||||
Script::Function::Register<&GetScancodeKeyNames>(rq, "GetScancodeKeyNames");
|
||||
Script::Function::Register<&ReloadHotkeys>(rq, "ReloadHotkeys");
|
||||
Script::Function::Register<&GetConflicts>(rq, "GetConflicts");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_HOTKEY
|
||||
#define INCLUDED_JSI_HOTKEY
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_Hotkey
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_HOTKEY
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "ps/Globals.h"
|
||||
#include "ps/Util.h"
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
#include "tools/atlas/GameInterface/GameLoop.h"
|
||||
|
||||
#include <js/RootingAPI.h>
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <js/Value.h>
|
||||
#include <string>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
extern void QuitEngine(int exitStatus);
|
||||
|
||||
@@ -76,9 +76,9 @@ std::wstring GetMatchID()
|
||||
return ps_generate_guid().FromUTF8();
|
||||
}
|
||||
|
||||
JS::Value LoadMapSettings(const ScriptInterface& scriptInterface, const VfsPath& pathname)
|
||||
JS::Value LoadMapSettings(const Script::Interface& scriptInterface, const VfsPath& pathname)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
CMapSummaryReader reader;
|
||||
|
||||
@@ -134,18 +134,18 @@ std::string CalculateMD5(const std::string& input)
|
||||
return Hexify(digest, MD5::DIGESTSIZE);
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&QuitEngine>(rq, "Exit");
|
||||
ScriptFunction::Register<&AtlasIsAvailable>(rq, "AtlasIsAvailable");
|
||||
ScriptFunction::Register<&IsAtlasRunning>(rq, "IsAtlasRunning");
|
||||
ScriptFunction::Register<&OpenURL>(rq, "OpenURL");
|
||||
ScriptFunction::Register<&GetSystemUsername>(rq, "GetSystemUsername");
|
||||
ScriptFunction::Register<&GetMatchID>(rq, "GetMatchID");
|
||||
ScriptFunction::Register<&LoadMapSettings>(rq, "LoadMapSettings");
|
||||
ScriptFunction::Register<&GetFps>(rq, "GetFPS");
|
||||
ScriptFunction::Register<&GetTextSize>(rq, "GetTextSize");
|
||||
ScriptFunction::Register<&GetTextWidth>(rq, "GetTextWidth");
|
||||
ScriptFunction::Register<&CalculateMD5>(rq, "CalculateMD5");
|
||||
Script::Function::Register<&QuitEngine>(rq, "Exit");
|
||||
Script::Function::Register<&AtlasIsAvailable>(rq, "AtlasIsAvailable");
|
||||
Script::Function::Register<&IsAtlasRunning>(rq, "IsAtlasRunning");
|
||||
Script::Function::Register<&OpenURL>(rq, "OpenURL");
|
||||
Script::Function::Register<&GetSystemUsername>(rq, "GetSystemUsername");
|
||||
Script::Function::Register<&GetMatchID>(rq, "GetMatchID");
|
||||
Script::Function::Register<&LoadMapSettings>(rq, "LoadMapSettings");
|
||||
Script::Function::Register<&GetFps>(rq, "GetFPS");
|
||||
Script::Function::Register<&GetTextSize>(rq, "GetTextSize");
|
||||
Script::Function::Register<&GetTextWidth>(rq, "GetTextWidth");
|
||||
Script::Function::Register<&CalculateMD5>(rq, "CalculateMD5");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_MAIN
|
||||
#define INCLUDED_JSI_MAIN
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_Main
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_MAIN
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -26,8 +26,8 @@
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <js/Array.h>
|
||||
@@ -37,8 +37,8 @@
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace JS { class CallArgs; }
|
||||
namespace Script { class Interface; }
|
||||
|
||||
extern void RestartEngine();
|
||||
|
||||
@@ -46,7 +46,7 @@ extern void RestartEngine();
|
||||
using ModDataCPtr = const Mod::ModData*;
|
||||
|
||||
template<>
|
||||
void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const ModDataCPtr& data)
|
||||
void Script::ToJSVal(const Script::Request& rq, JS::MutableHandleValue ret, const ModDataCPtr& data)
|
||||
{
|
||||
ret.set(Script::CreateObject(rq));
|
||||
Script::SetProperty(rq, ret, "mod", data->m_Pathname);
|
||||
@@ -57,7 +57,7 @@ void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const
|
||||
|
||||
// Required by JSVAL_VECTOR, but can't be implemented.
|
||||
template<>
|
||||
bool Script::FromJSVal(const ScriptRequest &, const JS::HandleValue, ModDataCPtr&)
|
||||
bool Script::FromJSVal(const Script::Request &, const JS::HandleValue, ModDataCPtr&)
|
||||
{
|
||||
LOGERROR("Not implemented");
|
||||
return false;
|
||||
@@ -67,7 +67,7 @@ JSVAL_VECTOR(const Mod::ModData*);
|
||||
|
||||
// Implement FromJSVal as a non-pointer type.
|
||||
template<>
|
||||
void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const Mod::ModData& data)
|
||||
void Script::ToJSVal(const Script::Request& rq, JS::MutableHandleValue ret, const Mod::ModData& data)
|
||||
{
|
||||
ret.set(Script::CreateObject(rq));
|
||||
Script::SetProperty(rq, ret, "mod", data.m_Pathname);
|
||||
@@ -77,7 +77,7 @@ void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Script::FromJSVal(const ScriptRequest& rq, const JS::HandleValue val, Mod::ModData& data)
|
||||
bool Script::FromJSVal(const Script::Request& rq, const JS::HandleValue val, Mod::ModData& data)
|
||||
{
|
||||
// To avoid errors & for convenience, some retro-compatibility when reading
|
||||
// TODO: remove this once we hit A26.
|
||||
@@ -119,14 +119,14 @@ JSVAL_VECTOR(Mod::ModData);
|
||||
|
||||
namespace JSI_Mod
|
||||
{
|
||||
Mod* ModGetter(const ScriptRequest&, JS::CallArgs&)
|
||||
Mod* ModGetter(const Script::Request&, JS::CallArgs&)
|
||||
{
|
||||
return &g_Mods;
|
||||
}
|
||||
|
||||
JS::Value GetEngineInfo(const ScriptInterface& scriptInterface)
|
||||
JS::Value GetEngineInfo(const Script::Interface& scriptInterface)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
|
||||
JS::RootedValue mods(rq.cx);
|
||||
Script::ToJSVal(rq, &mods, g_Mods.GetEnabledModsData());
|
||||
@@ -144,7 +144,7 @@ JS::Value GetEngineInfo(const ScriptInterface& scriptInterface)
|
||||
return metainfo;
|
||||
}
|
||||
|
||||
JS::Value GetAvailableMods(const ScriptRequest& rq)
|
||||
JS::Value GetAvailableMods(const Script::Request& rq)
|
||||
{
|
||||
JS::RootedValue ret(rq.cx, Script::CreateObject(rq));
|
||||
for (const Mod::ModData& data : g_Mods.GetAvailableMods())
|
||||
@@ -186,14 +186,14 @@ bool HasIncompatibleMods()
|
||||
return g_Mods.GetIncompatibleMods().size() > 0;
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<GetEngineInfo>(rq, "GetEngineInfo");
|
||||
ScriptFunction::Register<GetAvailableMods>(rq, "GetAvailableMods");
|
||||
ScriptFunction::Register<&Mod::GetEnabledMods, ModGetter>(rq, "GetEnabledMods");
|
||||
ScriptFunction::Register<AreModsPlayCompatible>(rq, "AreModsPlayCompatible");
|
||||
ScriptFunction::Register<HasIncompatibleMods> (rq, "HasIncompatibleMods");
|
||||
ScriptFunction::Register<&Mod::GetIncompatibleMods, ModGetter>(rq, "GetIncompatibleMods");
|
||||
ScriptFunction::Register<&SetModsAndRestartEngine>(rq, "SetModsAndRestartEngine");
|
||||
Script::Function::Register<GetEngineInfo>(rq, "GetEngineInfo");
|
||||
Script::Function::Register<GetAvailableMods>(rq, "GetAvailableMods");
|
||||
Script::Function::Register<&Mod::GetEnabledMods, ModGetter>(rq, "GetEnabledMods");
|
||||
Script::Function::Register<AreModsPlayCompatible>(rq, "AreModsPlayCompatible");
|
||||
Script::Function::Register<HasIncompatibleMods> (rq, "HasIncompatibleMods");
|
||||
Script::Function::Register<&Mod::GetIncompatibleMods, ModGetter>(rq, "GetIncompatibleMods");
|
||||
Script::Function::Register<&SetModsAndRestartEngine>(rq, "SetModsAndRestartEngine");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_MOD
|
||||
#define INCLUDED_JSI_MOD
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_Mod
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_MOD
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "ps/ModIo.h"
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <js/RootingAPI.h>
|
||||
#include <js/TypeDecls.h>
|
||||
@@ -39,7 +39,7 @@ namespace JS { class CallArgs; }
|
||||
|
||||
namespace JSI_ModIo
|
||||
{
|
||||
ModIo* ModIoGetter(const ScriptRequest&, JS::CallArgs&)
|
||||
ModIo* ModIoGetter(const Script::Request&, JS::CallArgs&)
|
||||
{
|
||||
if (!g_ModIo)
|
||||
{
|
||||
@@ -60,7 +60,7 @@ void StartGetGameId()
|
||||
}
|
||||
|
||||
// TODO: could provide a FromJSVal for ModIoModData
|
||||
JS::Value GetMods(const ScriptRequest& rq)
|
||||
JS::Value GetMods(const Script::Request& rq)
|
||||
{
|
||||
if (!g_ModIo)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ const std::map<DownloadProgressStatus, std::string> statusStrings = {
|
||||
};
|
||||
|
||||
// TODO: could provide a FromJSVal for DownloadProgressData
|
||||
JS::Value GetDownloadProgress(const ScriptRequest& rq)
|
||||
JS::Value GetDownloadProgress(const Script::Request& rq)
|
||||
{
|
||||
if (!g_ModIo)
|
||||
{
|
||||
@@ -125,14 +125,14 @@ JS::Value GetDownloadProgress(const ScriptRequest& rq)
|
||||
return progressData;
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&StartGetGameId>(rq, "ModIoStartGetGameId");
|
||||
ScriptFunction::Register<&ModIo::StartListMods, &ModIoGetter>(rq, "ModIoStartListMods");
|
||||
ScriptFunction::Register<&ModIo::StartDownloadMod, &ModIoGetter>(rq, "ModIoStartDownloadMod");
|
||||
ScriptFunction::Register<&ModIo::AdvanceRequest, &ModIoGetter>(rq, "ModIoAdvanceRequest");
|
||||
ScriptFunction::Register<&ModIo::CancelRequest, &ModIoGetter>(rq, "ModIoCancelRequest");
|
||||
ScriptFunction::Register<&GetMods>(rq, "ModIoGetMods");
|
||||
ScriptFunction::Register<&GetDownloadProgress>(rq, "ModIoGetDownloadProgress");
|
||||
Script::Function::Register<&StartGetGameId>(rq, "ModIoStartGetGameId");
|
||||
Script::Function::Register<&ModIo::StartListMods, &ModIoGetter>(rq, "ModIoStartListMods");
|
||||
Script::Function::Register<&ModIo::StartDownloadMod, &ModIoGetter>(rq, "ModIoStartDownloadMod");
|
||||
Script::Function::Register<&ModIo::AdvanceRequest, &ModIoGetter>(rq, "ModIoAdvanceRequest");
|
||||
Script::Function::Register<&ModIo::CancelRequest, &ModIoGetter>(rq, "ModIoCancelRequest");
|
||||
Script::Function::Register<&GetMods>(rq, "ModIoGetMods");
|
||||
Script::Function::Register<&GetDownloadProgress>(rq, "ModIoGetDownloadProgress");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_MODIO
|
||||
#define INCLUDED_JSI_MODIO
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_ModIo
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_MODIO
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "ps/SavedGame.h"
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
#include "scriptinterface/StructuredClone.h"
|
||||
#include "simulation2/Simulation2.h"
|
||||
#include "simulation2/system/TurnManager.h"
|
||||
@@ -40,11 +40,11 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
namespace JSI_SavedGame
|
||||
{
|
||||
JS::Value GetSavedGames(const ScriptInterface& scriptInterface)
|
||||
JS::Value GetSavedGames(const Script::Interface& scriptInterface)
|
||||
{
|
||||
return SavedGames::GetSavedGames(scriptInterface);
|
||||
}
|
||||
@@ -54,14 +54,14 @@ bool DeleteSavedGame(const std::wstring& name)
|
||||
return SavedGames::DeleteSavedGame(name);
|
||||
}
|
||||
|
||||
void SaveGame(const ScriptRequest& rq, const std::wstring& filename, const std::wstring& description, JS::HandleValue GUIMetadata)
|
||||
void SaveGame(const Script::Request& rq, const std::wstring& filename, const std::wstring& description, JS::HandleValue GUIMetadata)
|
||||
{
|
||||
Script::StructuredClone GUIMetadataClone = Script::WriteStructuredClone(rq, GUIMetadata);
|
||||
if (SavedGames::Save(filename, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0)
|
||||
LOGERROR("Failed to save game");
|
||||
}
|
||||
|
||||
void SaveGamePrefix(const ScriptRequest& rq, const std::wstring& prefix, const std::wstring& description, JS::HandleValue GUIMetadata)
|
||||
void SaveGamePrefix(const Script::Request& rq, const std::wstring& prefix, const std::wstring& description, JS::HandleValue GUIMetadata)
|
||||
{
|
||||
Script::StructuredClone GUIMetadataClone = Script::WriteStructuredClone(rq, GUIMetadata);
|
||||
if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0)
|
||||
@@ -96,7 +96,7 @@ void QuickLoad()
|
||||
if (!g_GUI || !maybeMetadata.has_value())
|
||||
return;
|
||||
|
||||
const ScriptRequest rq{g_Game->GetSimulation2()->GetScriptInterface()};
|
||||
const Script::Request rq{g_Game->GetSimulation2()->GetScriptInterface()};
|
||||
JS::RootedValue metadata{rq.cx, maybeMetadata.value()};
|
||||
|
||||
// Provide a copy, so that GUI components don't have to clone to get mutable objects
|
||||
@@ -109,20 +109,20 @@ void QuickLoad()
|
||||
LOGMESSAGERENDER("Quickloaded game");
|
||||
}
|
||||
|
||||
JS::Value LoadSavedGameMetadata(const ScriptInterface& scriptInterface, const std::wstring& name)
|
||||
JS::Value LoadSavedGameMetadata(const Script::Interface& scriptInterface, const std::wstring& name)
|
||||
{
|
||||
std::optional<SavedGames::LoadResult> data{SavedGames::Load(scriptInterface, name)};
|
||||
|
||||
return data ? data->metadata : JS::UndefinedValue();
|
||||
}
|
||||
|
||||
JS::Value StartSavedGame(const ScriptInterface& scriptInterface, const std::wstring& name)
|
||||
JS::Value StartSavedGame(const Script::Interface& scriptInterface, const std::wstring& name)
|
||||
{
|
||||
// We need to be careful with different compartments and contexts.
|
||||
// The GUI calls this function from the GUI context and expects the return value in the same context.
|
||||
// The game we start from here creates another context and expects data in this context.
|
||||
|
||||
ScriptRequest rqGui(scriptInterface);
|
||||
Script::Request rqGui(scriptInterface);
|
||||
|
||||
ENSURE(!g_NetServer);
|
||||
ENSURE(!g_NetClient);
|
||||
@@ -139,7 +139,7 @@ JS::Value StartSavedGame(const ScriptInterface& scriptInterface, const std::wstr
|
||||
|
||||
{
|
||||
CSimulation2* sim = g_Game->GetSimulation2();
|
||||
ScriptRequest rqGame(sim->GetScriptInterface());
|
||||
Script::Request rqGame(sim->GetScriptInterface());
|
||||
|
||||
JS::RootedValue gameContextMetadata(rqGame.cx, Script::CloneValueFromOtherCompartment(sim->GetScriptInterface(), scriptInterface, guiContextMetadata));
|
||||
JS::RootedValue gameInitAttributes(rqGame.cx);
|
||||
@@ -162,16 +162,16 @@ void ActivateRejoinTest()
|
||||
g_Game->GetSimulation2()->ActivateRejoinTest(g_Game->GetTurnManager()->GetCurrentTurn() + 1);
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&GetSavedGames>(rq, "GetSavedGames");
|
||||
ScriptFunction::Register<&DeleteSavedGame>(rq, "DeleteSavedGame");
|
||||
ScriptFunction::Register<&SaveGame>(rq, "SaveGame");
|
||||
ScriptFunction::Register<&SaveGamePrefix>(rq, "SaveGamePrefix");
|
||||
ScriptFunction::Register<&QuickSave>(rq, "QuickSave");
|
||||
ScriptFunction::Register<&QuickLoad>(rq, "QuickLoad");
|
||||
ScriptFunction::Register<&ActivateRejoinTest>(rq, "ActivateRejoinTest");
|
||||
ScriptFunction::Register<&LoadSavedGameMetadata>(rq, "LoadSavedGameMetadata");
|
||||
ScriptFunction::Register<&StartSavedGame>(rq, "StartSavedGame");
|
||||
Script::Function::Register<&GetSavedGames>(rq, "GetSavedGames");
|
||||
Script::Function::Register<&DeleteSavedGame>(rq, "DeleteSavedGame");
|
||||
Script::Function::Register<&SaveGame>(rq, "SaveGame");
|
||||
Script::Function::Register<&SaveGamePrefix>(rq, "SaveGamePrefix");
|
||||
Script::Function::Register<&QuickSave>(rq, "QuickSave");
|
||||
Script::Function::Register<&QuickLoad>(rq, "QuickLoad");
|
||||
Script::Function::Register<&ActivateRejoinTest>(rq, "ActivateRejoinTest");
|
||||
Script::Function::Register<&LoadSavedGameMetadata>(rq, "LoadSavedGameMetadata");
|
||||
Script::Function::Register<&StartSavedGame>(rq, "StartSavedGame");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_SAVEDGAME
|
||||
#define INCLUDED_JSI_SAVEDGAME
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_SavedGame
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_SAVEDGAME
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -58,12 +58,12 @@ std::string GetUserReportConfigPath()
|
||||
return configPath.string8();
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&IsUserReportEnabled>(rq, "IsUserReportEnabled");
|
||||
ScriptFunction::Register<&SetUserReportEnabled>(rq, "SetUserReportEnabled");
|
||||
ScriptFunction::Register<&GetUserReportStatus>(rq, "GetUserReportStatus");
|
||||
ScriptFunction::Register<&GetUserReportLogPath>(rq, "GetUserReportLogPath");
|
||||
ScriptFunction::Register<&GetUserReportConfigPath>(rq, "GetUserReportConfigPath");
|
||||
Script::Function::Register<&IsUserReportEnabled>(rq, "IsUserReportEnabled");
|
||||
Script::Function::Register<&SetUserReportEnabled>(rq, "SetUserReportEnabled");
|
||||
Script::Function::Register<&GetUserReportStatus>(rq, "GetUserReportStatus");
|
||||
Script::Function::Register<&GetUserReportLogPath>(rq, "GetUserReportLogPath");
|
||||
Script::Function::Register<&GetUserReportConfigPath>(rq, "GetUserReportConfigPath");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_USERREPORT
|
||||
#define INCLUDED_JSI_USERREPORT
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_UserReport
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_USERREPORT
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
#include "scriptinterface/JSON.h"
|
||||
#include "scriptinterface/Object.h"
|
||||
#include "scriptinterface/ScriptConversions.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Conversions.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -56,7 +56,7 @@
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
|
||||
class ScriptInterface;
|
||||
namespace Script { class Interface; }
|
||||
|
||||
namespace JSI_VFS
|
||||
{
|
||||
@@ -119,11 +119,11 @@ bool PathRestrictionMet(const std::wstring& filePath)
|
||||
// state held across multiple BuildDirEntListCB calls; init by BuildDirEntList.
|
||||
struct BuildDirEntListState
|
||||
{
|
||||
const ScriptRequest& rq;
|
||||
const Script::Request& rq;
|
||||
JS::PersistentRootedObject filename_array;
|
||||
int cur_idx;
|
||||
|
||||
BuildDirEntListState(const ScriptRequest& rq)
|
||||
BuildDirEntListState(const Script::Request& rq)
|
||||
: rq(rq),
|
||||
filename_array(rq.cx),
|
||||
cur_idx(0)
|
||||
@@ -150,7 +150,7 @@ static Status BuildDirEntListCB(const VfsPath& pathname, const CFileInfo&, uintp
|
||||
// filter_string: default "" matches everything; otherwise, see vfs_next_dirent.
|
||||
// recurse: should subdirectories be included in the search? default false.
|
||||
template<auto& restriction>
|
||||
JS::Value BuildDirEntList(const ScriptRequest& rq, const std::wstring& path, const std::wstring& filterStr,
|
||||
JS::Value BuildDirEntList(const Script::Request& rq, const std::wstring& path, const std::wstring& filterStr,
|
||||
bool recurse)
|
||||
{
|
||||
if (!PathRestrictionMet<restriction>(path))
|
||||
@@ -190,7 +190,7 @@ unsigned int GetFileSize(const std::wstring& filename)
|
||||
|
||||
// Return file contents in a string. Assume file is UTF-8 encoded text.
|
||||
template<auto& restriction>
|
||||
JS::Value ReadFile(const ScriptRequest& rq, const std::wstring& filename)
|
||||
JS::Value ReadFile(const Script::Request& rq, const std::wstring& filename)
|
||||
{
|
||||
if (!PathRestrictionMet<restriction>(filename))
|
||||
return JS::NullValue();
|
||||
@@ -212,7 +212,7 @@ JS::Value ReadFile(const ScriptRequest& rq, const std::wstring& filename)
|
||||
|
||||
// Return file contents as an array of lines. Assume file is UTF-8 encoded text.
|
||||
template<auto& restriction>
|
||||
JS::Value ReadFileLines(const ScriptRequest& rq, const std::wstring& filename)
|
||||
JS::Value ReadFileLines(const Script::Request& rq, const std::wstring& filename)
|
||||
{
|
||||
if (!PathRestrictionMet<restriction>(filename))
|
||||
return JS::NullValue();
|
||||
@@ -247,9 +247,9 @@ JS::Value ReadFileLines(const ScriptRequest& rq, const std::wstring& filename)
|
||||
|
||||
// Return file contents parsed as a JS Object
|
||||
template<auto& restriction>
|
||||
JS::Value ReadJSONFile(const ScriptInterface& scriptInterface, const std::wstring& filePath)
|
||||
JS::Value ReadJSONFile(const Script::Interface& scriptInterface, const std::wstring& filePath)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
if (!PathRestrictionMet<restriction>(filePath))
|
||||
return JS::NullValue();
|
||||
|
||||
@@ -260,10 +260,10 @@ JS::Value ReadJSONFile(const ScriptInterface& scriptInterface, const std::wstrin
|
||||
|
||||
// Save given JS Object to a JSON file
|
||||
template<auto& restriction>
|
||||
void WriteJSONFile(const ScriptInterface& scriptInterface, const std::wstring& filePath,
|
||||
void WriteJSONFile(const Script::Interface& scriptInterface, const std::wstring& filePath,
|
||||
JS::HandleValue val1)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
Script::Request rq(scriptInterface);
|
||||
if (!PathRestrictionMet<restriction>(filePath))
|
||||
return;
|
||||
|
||||
@@ -301,32 +301,32 @@ bool DeleteCampaignSave(const CStrW& filePath)
|
||||
return !ec;
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions_ReadWriteAnywhere(const ScriptRequest& rq,
|
||||
void RegisterScriptFunctions_ReadWriteAnywhere(const Script::Request& rq,
|
||||
const u16 flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */)
|
||||
{
|
||||
ScriptFunction::Register<&BuildDirEntList<PathRestriction::GUI>>(rq, "ListDirectoryFiles", flags);
|
||||
ScriptFunction::Register<&FileExists<PathRestriction::GUI>>(rq, "FileExists", flags);
|
||||
ScriptFunction::Register<&GetFileSize>(rq, "GetFileSize", flags);
|
||||
ScriptFunction::Register<&ReadFile<PathRestriction::GUI>>(rq, "ReadFile", flags);
|
||||
ScriptFunction::Register<&ReadFileLines<PathRestriction::GUI>>(rq, "ReadFileLines", flags);
|
||||
ScriptFunction::Register<&ReadJSONFile<PathRestriction::GUI>>(rq, "ReadJSONFile", flags);
|
||||
ScriptFunction::Register<&WriteJSONFile<PathRestriction::GUI>>(rq, "WriteJSONFile", flags);
|
||||
ScriptFunction::Register<&DeleteCampaignSave>(rq, "DeleteCampaignSave", flags);
|
||||
Script::Function::Register<&BuildDirEntList<PathRestriction::GUI>>(rq, "ListDirectoryFiles", flags);
|
||||
Script::Function::Register<&FileExists<PathRestriction::GUI>>(rq, "FileExists", flags);
|
||||
Script::Function::Register<&GetFileSize>(rq, "GetFileSize", flags);
|
||||
Script::Function::Register<&ReadFile<PathRestriction::GUI>>(rq, "ReadFile", flags);
|
||||
Script::Function::Register<&ReadFileLines<PathRestriction::GUI>>(rq, "ReadFileLines", flags);
|
||||
Script::Function::Register<&ReadJSONFile<PathRestriction::GUI>>(rq, "ReadJSONFile", flags);
|
||||
Script::Function::Register<&WriteJSONFile<PathRestriction::GUI>>(rq, "WriteJSONFile", flags);
|
||||
Script::Function::Register<&DeleteCampaignSave>(rq, "DeleteCampaignSave", flags);
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions_ReadOnlySimulation(const ScriptRequest& rq,
|
||||
void RegisterScriptFunctions_ReadOnlySimulation(const Script::Request& rq,
|
||||
const u16 flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */)
|
||||
{
|
||||
ScriptFunction::Register<&BuildDirEntList<PathRestriction::SIMULATION>>(rq, "ListDirectoryFiles", flags);
|
||||
ScriptFunction::Register<&FileExists<PathRestriction::SIMULATION>>(rq, "FileExists", flags);
|
||||
ScriptFunction::Register<&ReadJSONFile<PathRestriction::SIMULATION>>(rq, "ReadJSONFile", flags);
|
||||
Script::Function::Register<&BuildDirEntList<PathRestriction::SIMULATION>>(rq, "ListDirectoryFiles", flags);
|
||||
Script::Function::Register<&FileExists<PathRestriction::SIMULATION>>(rq, "FileExists", flags);
|
||||
Script::Function::Register<&ReadJSONFile<PathRestriction::SIMULATION>>(rq, "ReadJSONFile", flags);
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions_ReadOnlySimulationMaps(const ScriptRequest& rq,
|
||||
void RegisterScriptFunctions_ReadOnlySimulationMaps(const Script::Request& rq,
|
||||
const u16 flags /*= JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT */)
|
||||
{
|
||||
ScriptFunction::Register<&BuildDirEntList<PathRestriction::MAPS>>(rq, "ListDirectoryFiles", flags);
|
||||
ScriptFunction::Register<&FileExists<PathRestriction::MAPS>>(rq, "FileExists", flags);
|
||||
ScriptFunction::Register<&ReadJSONFile<PathRestriction::MAPS>>(rq, "ReadJSONFile", flags);
|
||||
Script::Function::Register<&BuildDirEntList<PathRestriction::MAPS>>(rq, "ListDirectoryFiles", flags);
|
||||
Script::Function::Register<&FileExists<PathRestriction::MAPS>>(rq, "FileExists", flags);
|
||||
Script::Function::Register<&ReadJSONFile<PathRestriction::MAPS>>(rq, "ReadJSONFile", flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -22,15 +22,15 @@
|
||||
|
||||
#include <js/PropertyDescriptor.h>
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_VFS
|
||||
{
|
||||
void RegisterScriptFunctions_ReadWriteAnywhere(const ScriptRequest& rq,
|
||||
void RegisterScriptFunctions_ReadWriteAnywhere(const Script::Request& rq,
|
||||
const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
void RegisterScriptFunctions_ReadOnlySimulation(const ScriptRequest& rq,
|
||||
void RegisterScriptFunctions_ReadOnlySimulation(const Script::Request& rq,
|
||||
const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
void RegisterScriptFunctions_ReadOnlySimulationMaps(const ScriptRequest& rq,
|
||||
void RegisterScriptFunctions_ReadOnlySimulationMaps(const Script::Request& rq,
|
||||
const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -35,15 +35,15 @@ CStrW GetReplayDirectoryName(const CStrW& directoryName)
|
||||
return wstring_from_utf8(OsPath(VisualReplay::GetDirectoryPath() / directoryName).string8());
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
void RegisterScriptFunctions(const Script::Request& rq)
|
||||
{
|
||||
ScriptFunction::Register<&VisualReplay::GetReplays>(rq, "GetReplays");
|
||||
ScriptFunction::Register<&VisualReplay::DeleteReplay>(rq, "DeleteReplay");
|
||||
ScriptFunction::Register<&VisualReplay::StartVisualReplay>(rq, "StartVisualReplay");
|
||||
ScriptFunction::Register<&VisualReplay::GetReplayAttributes>(rq, "GetReplayAttributes");
|
||||
ScriptFunction::Register<&VisualReplay::GetReplayMetadata>(rq, "GetReplayMetadata");
|
||||
ScriptFunction::Register<&VisualReplay::HasReplayMetadata>(rq, "HasReplayMetadata");
|
||||
ScriptFunction::Register<&VisualReplay::AddReplayToCache>(rq, "AddReplayToCache");
|
||||
ScriptFunction::Register<&GetReplayDirectoryName>(rq, "GetReplayDirectoryName");
|
||||
Script::Function::Register<&VisualReplay::GetReplays>(rq, "GetReplays");
|
||||
Script::Function::Register<&VisualReplay::DeleteReplay>(rq, "DeleteReplay");
|
||||
Script::Function::Register<&VisualReplay::StartVisualReplay>(rq, "StartVisualReplay");
|
||||
Script::Function::Register<&VisualReplay::GetReplayAttributes>(rq, "GetReplayAttributes");
|
||||
Script::Function::Register<&VisualReplay::GetReplayMetadata>(rq, "GetReplayMetadata");
|
||||
Script::Function::Register<&VisualReplay::HasReplayMetadata>(rq, "HasReplayMetadata");
|
||||
Script::Function::Register<&VisualReplay::AddReplayToCache>(rq, "AddReplayToCache");
|
||||
Script::Function::Register<&GetReplayDirectoryName>(rq, "GetReplayDirectoryName");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -18,11 +18,11 @@
|
||||
#ifndef INCLUDED_JSI_VISUALREPLAY
|
||||
#define INCLUDED_JSI_VISUALREPLAY
|
||||
|
||||
class ScriptRequest;
|
||||
namespace Script { class Request; }
|
||||
|
||||
namespace JSI_VisualReplay
|
||||
{
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq);
|
||||
void RegisterScriptFunctions(const Script::Request& rq);
|
||||
}
|
||||
|
||||
#endif // INCLUDED_JSI_VISUALREPLAY
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
#include "ps/CStr.h"
|
||||
#include "ps/Mod.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/ScriptRequest.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
#include "scriptinterface/Request.h"
|
||||
|
||||
#include <js/RootingAPI.h>
|
||||
#include <js/TypeDecls.h>
|
||||
@@ -91,9 +91,9 @@ public:
|
||||
|
||||
void test_compatible()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", g_ScriptContext);
|
||||
Script::Interface script("Test", "Test", g_ScriptContext);
|
||||
|
||||
ScriptRequest rq(script);
|
||||
Script::Request rq(script);
|
||||
JS::RootedObject obj(rq.cx, JS_NewPlainObject(rq.cx));
|
||||
|
||||
m_Mods.m_AvailableMods = {
|
||||
@@ -141,9 +141,9 @@ public:
|
||||
|
||||
void test_different_name_and_path()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", g_ScriptContext);
|
||||
Script::Interface script("Test", "Test", g_ScriptContext);
|
||||
|
||||
ScriptRequest rq(script);
|
||||
Script::Request rq(script);
|
||||
JS::RootedObject obj(rq.cx, JS_NewPlainObject(rq.cx));
|
||||
|
||||
m_Mods.m_AvailableMods = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/ModIo.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/Interface.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
void test_id_parsing()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", g_ScriptContext);
|
||||
Script::Interface script("Test", "Test", g_ScriptContext);
|
||||
|
||||
#define TS_ASSERT_PARSE(input, expected_error, expected_id) \
|
||||
{ \
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
|
||||
void test_mods_parsing()
|
||||
{
|
||||
ScriptInterface script("Test", "Test", g_ScriptContext);
|
||||
Script::Interface script("Test", "Test", g_ScriptContext);
|
||||
|
||||
PKStruct pk;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user