Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/EditorInterface/scripting/JSInterface_Editor.cpp
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
/* Copyright (C) 2023 Wildfire Games. | |||||||||||
* This file is part of 0 A.D. | |||||||||||
* | |||||||||||
* 0 A.D. is free software: you can redistribute it and/or modify | |||||||||||
* it under the terms of the GNU General Public License as published by | |||||||||||
* the Free Software Foundation, either version 2 of the License, or | |||||||||||
* (at your option) any later version. | |||||||||||
* | |||||||||||
* 0 A.D. is distributed in the hope that it will be useful, | |||||||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||||||||
* GNU General Public License for more details. | |||||||||||
* | |||||||||||
* You should have received a copy of the GNU General Public License | |||||||||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | |||||||||||
*/ | |||||||||||
#include "precompiled.h" | |||||||||||
#include "JSInterface_Editor.h" | |||||||||||
#include "graphics/GameView.h" | |||||||||||
#include "graphics/MapWriter.h" | |||||||||||
#include "ps/Game.h" | |||||||||||
#include "ps/World.h" | |||||||||||
#include "renderer/Renderer.h" | |||||||||||
#include "renderer/SceneRenderer.h" | |||||||||||
#include "renderer/WaterManager.h" | |||||||||||
#include "scriptinterface/FunctionWrapper.h" | |||||||||||
#include "scriptinterface/StructuredClone.h" | |||||||||||
#include "simulation2/Simulation2.h" | |||||||||||
#include "simulation2/components/ICmpAIManager.h" | |||||||||||
#include "simulation2/components/ICmpRangeManager.h" | |||||||||||
#include "simulation2/components/ICmpTemplateManager.h" | |||||||||||
namespace JSI_Editor | |||||||||||
{ | |||||||||||
void SetMapSettings(const ScriptInterface& scriptInterface, JS::HandleValue data) | |||||||||||
{ | |||||||||||
if (!g_Game || !g_Game->IsEditorGame()) | |||||||||||
return; | |||||||||||
CSimulation2* sim = g_Game->GetSimulation2(); | |||||||||||
ENSURE(sim); | |||||||||||
ScriptRequest rqSim(sim->GetScriptInterface()); | |||||||||||
JS::RootedValue mapSettings(rqSim.cx, Script::CloneValueFromOtherCompartment(sim->GetScriptInterface(), scriptInterface, data)); | |||||||||||
sim->SetMapSettings(mapSettings); | |||||||||||
} | |||||||||||
JS::Value GetMapSettings(const ScriptInterface& scriptInterface) | |||||||||||
{ | |||||||||||
if (!g_Game || !g_Game->IsEditorGame()) | |||||||||||
return JS::UndefinedHandleValue; | |||||||||||
CSimulation2* sim = g_Game->GetSimulation2(); | |||||||||||
ENSURE(sim); | |||||||||||
ScriptRequest rqSim(sim->GetScriptInterface()); | |||||||||||
JS::RootedValue mapSettings(rqSim.cx); | |||||||||||
sim->GetMapSettings(&mapSettings); | |||||||||||
return Script::CloneValueFromOtherCompartment(scriptInterface, sim->GetScriptInterface(), mapSettings); | |||||||||||
} | |||||||||||
bool IsEditorRunning(const ScriptInterface& UNUSED(scriptInterface)) | |||||||||||
{ | |||||||||||
if (!g_Game) | |||||||||||
return false; | |||||||||||
return g_Game->IsEditorGame(); | |||||||||||
} | |||||||||||
void RevealMap(const ScriptInterface& UNUSED(scriptInterface)) | |||||||||||
{ | |||||||||||
if (!g_Game || !g_Game->IsEditorGame()) | |||||||||||
return; | |||||||||||
CSimulation2* sim = g_Game->GetSimulation2(); | |||||||||||
ENSURE(sim); | |||||||||||
CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY); | |||||||||||
if (cmpRangeManager) | |||||||||||
cmpRangeManager->SetLosRevealAll(-1, true); | |||||||||||
} | |||||||||||
std::vector<std::vector<std::wstring>> GetCivData(const ScriptInterface& UNUSED(scriptInterface)) | |||||||||||
{ | |||||||||||
if (!g_Game || !g_Game->IsEditorGame()) | |||||||||||
{ | |||||||||||
std::vector<std::vector<std::wstring>> emptyValue; | |||||||||||
Stan: #include <string>
#include <vector> | |||||||||||
return emptyValue; | |||||||||||
} | |||||||||||
CSimulation2* sim = g_Game->GetSimulation2(); | |||||||||||
ENSURE(sim); | |||||||||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(*sim, SYSTEM_ENTITY); | |||||||||||
return cmpTemplateManager->GetCivData(); | |||||||||||
} | |||||||||||
JS::Value GetAIData(const ScriptInterface& scriptInterface) | |||||||||||
{ | |||||||||||
if (!g_Game || !g_Game->IsEditorGame()) | |||||||||||
return JS::UndefinedHandleValue; | |||||||||||
CSimulation2* sim = g_Game->GetSimulation2(); | |||||||||||
ENSURE(sim); | |||||||||||
ScriptRequest rqSim(sim->GetScriptInterface()); | |||||||||||
JS::RootedValue aiData(rqSim.cx, ICmpAIManager::GetAIs(sim->GetScriptInterface())); | |||||||||||
return Script::CloneValueFromOtherCompartment(scriptInterface, sim->GetScriptInterface(), aiData); | |||||||||||
} | |||||||||||
void SaveMap(const ScriptInterface& UNUSED(scriptInterface), std::wstring filename) | |||||||||||
{ | |||||||||||
if (!g_Game || !g_Game->IsEditorGame()) | |||||||||||
return; | |||||||||||
CMapWriter writer; | |||||||||||
VfsPath pathname = VfsPath(filename).ChangeExtension(L".pmp"); | |||||||||||
writer.SaveMap(pathname, | |||||||||||
g_Game->GetWorld()->GetTerrain(), | |||||||||||
&g_Renderer.GetSceneRenderer().GetWaterManager(), &g_Renderer.GetSceneRenderer().GetSkyManager(), | |||||||||||
&g_LightEnv, g_Game->GetView()->GetCamera(), g_Game->GetView()->GetCinema(), | |||||||||||
&g_Renderer.GetPostprocManager(), | |||||||||||
g_Game->GetSimulation2()); | |||||||||||
} | |||||||||||
void RegisterScriptFunctions(const ScriptRequest& rq) | |||||||||||
{ | |||||||||||
ScriptFunction::Register<&IsEditorRunning>(rq, "IsEditorRunning"); | |||||||||||
ScriptFunction::Register<&SetMapSettings>(rq, "SetMapSettings"); | |||||||||||
ScriptFunction::Register<&GetMapSettings>(rq, "GetMapSettings"); | |||||||||||
ScriptFunction::Register<&RevealMap>(rq, "RevealMap"); | |||||||||||
ScriptFunction::Register<&GetCivData>(rq, "GetCivData"); | |||||||||||
ScriptFunction::Register<&GetAIData>(rq, "GetAIData"); | |||||||||||
ScriptFunction::Register<&SaveMap>(rq, "SaveMap"); | |||||||||||
} | |||||||||||
} | |||||||||||
Not Done Inline Actions#include <sstream> Stan: #include <sstream> | |||||||||||
Not Done Inline Actions#include <memory> Stan: #include <memory> | |||||||||||
Not Done Inline Actions
Stan: | |||||||||||
Not Done Inline Actions
Stan: | |||||||||||
Not Done Inline Actionsstatic_cast<u8*> Stan: static_cast<u8*> |
Wildfire Games · Phabricator
#include <string>
#include <vector>