Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-07-23 13:49:34 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-07-23 13:49:34 +1000
commit121d27446b42c960014b2e69999dad73322b05f3 (patch)
tree2a1bbbd55de5628fcd03b64d0c49710e26d64243
parentd93b02682994730a2b4d33c6604e0b997b7ee977 (diff)
world.callScriptContext
-rw-r--r--source/game/StarWorldServer.cpp7
-rw-r--r--source/game/StarWorldServer.hpp7
-rw-r--r--source/game/scripting/StarWorldLuaBindings.cpp8
-rw-r--r--source/game/scripting/StarWorldLuaBindings.hpp1
4 files changed, 21 insertions, 2 deletions
diff --git a/source/game/StarWorldServer.cpp b/source/game/StarWorldServer.cpp
index f519dc4..0685e9e 100644
--- a/source/game/StarWorldServer.cpp
+++ b/source/game/StarWorldServer.cpp
@@ -1578,6 +1578,13 @@ bool WorldServer::regionActive(RectI const& region) {
return true;
}
+WorldServer::ScriptComponentPtr WorldServer::scriptContext(String const& contextName) {
+ if (auto context = m_scriptContexts.ptr(contextName))
+ return *context;
+ else
+ return nullptr;
+}
+
RpcPromise<Vec2I> WorldServer::enqueuePlacement(List<BiomeItemDistribution> distributions, Maybe<DungeonId> id) {
return m_worldStorage->enqueuePlacement(move(distributions), id);
}
diff --git a/source/game/StarWorldServer.hpp b/source/game/StarWorldServer.hpp
index 8c240d4..163cc1b 100644
--- a/source/game/StarWorldServer.hpp
+++ b/source/game/StarWorldServer.hpp
@@ -49,6 +49,9 @@ extern EnumMap<WorldServerFidelity> const WorldServerFidelityNames;
class WorldServer : public World {
public:
+ typedef LuaMessageHandlingComponent<LuaUpdatableComponent<LuaWorldComponent<LuaBaseComponent>>> ScriptComponent;
+ typedef shared_ptr<ScriptComponent> ScriptComponentPtr;
+
// Create a new world with the given template, writing new storage file.
WorldServer(WorldTemplatePtr const& worldTemplate, IODevicePtr storage);
// Synonym for WorldServer(make_shared<WorldTemplate>(size), storage);
@@ -193,6 +196,8 @@ public:
// Returns true if a region is fully active without signaling it.
bool regionActive(RectI const& region);
+ ScriptComponentPtr scriptContext(String const& contextName);
+
// Queues a microdungeon for placement
RpcPromise<Vec2I> enqueuePlacement(List<BiomeItemDistribution> distributions, Maybe<DungeonId> id);
@@ -350,8 +355,6 @@ private:
WireProcessorPtr m_wireProcessor;
LuaRootPtr m_luaRoot;
- typedef LuaMessageHandlingComponent<LuaUpdatableComponent<LuaWorldComponent<LuaBaseComponent>>> ScriptComponent;
- typedef shared_ptr<ScriptComponent> ScriptComponentPtr;
StringMap<ScriptComponentPtr> m_scriptContexts;
WorldGeometry m_geometry;
diff --git a/source/game/scripting/StarWorldLuaBindings.cpp b/source/game/scripting/StarWorldLuaBindings.cpp
index da4f7c8..6d1648e 100644
--- a/source/game/scripting/StarWorldLuaBindings.cpp
+++ b/source/game/scripting/StarWorldLuaBindings.cpp
@@ -383,6 +383,7 @@ namespace LuaBindings {
callbacks.registerCallbackWithSignature<void, Vec2F, Maybe<bool>>("setPlayerStart", bind(ServerWorldCallbacks::setPlayerStart, world, _1, _2));
callbacks.registerCallbackWithSignature<List<EntityId>>("players", bind(ServerWorldCallbacks::players, world));
callbacks.registerCallbackWithSignature<LuaString, LuaEngine&>("fidelity", bind(ServerWorldCallbacks::fidelity, world, _1));
+ callbacks.registerCallbackWithSignature<Maybe<LuaValue>, String, String, LuaVariadic<LuaValue>>("callScriptContext", bind(ServerWorldCallbacks::callScriptContext, world, _1, _2, _3));
callbacks.registerCallbackWithSignature<double>("skyTime", [serverWorld]() {
return serverWorld->sky()->epochTime();
@@ -1168,6 +1169,13 @@ namespace LuaBindings {
return engine.createString(WorldServerFidelityNames.getRight(as<WorldServer>(world)->fidelity()));
}
+ Maybe<LuaValue> ServerWorldCallbacks::callScriptContext(World* world, String const& contextName, String const& function, LuaVariadic<LuaValue> const& args) {
+ auto context = as<WorldServer>(world)->scriptContext(contextName);
+ if (!context)
+ throw StarException::format("Context {} does not exist", contextName);
+ return context->invoke(function, args);
+ }
+
void WorldDebugCallbacks::debugPoint(Vec2F const& arg1, Color const& arg2) {
SpatialLogger::logPoint("world", arg1, arg2.toRgba());
}
diff --git a/source/game/scripting/StarWorldLuaBindings.hpp b/source/game/scripting/StarWorldLuaBindings.hpp
index 87a0367..725e824 100644
--- a/source/game/scripting/StarWorldLuaBindings.hpp
+++ b/source/game/scripting/StarWorldLuaBindings.hpp
@@ -86,6 +86,7 @@ namespace LuaBindings {
void setPlayerStart(World* world, Vec2F const& playerStart, Maybe<bool> respawnInWorld);
List<EntityId> players(World* world);
LuaString fidelity(World* world, LuaEngine& engine);
+ Maybe<LuaValue> callScriptContext(World* world, String const& contextName, String const& function, LuaVariadic<LuaValue> const& args);
}
namespace WorldDebugCallbacks {