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

summaryrefslogtreecommitdiff
path: root/source/game/StarUniverseClient.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-07-17 22:20:39 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-07-17 22:20:39 +1000
commit34bb0b54222c1c0f3450c56e76f89f192d77374b (patch)
tree09e119625d066d16e3a81a8f6c0c424c4159f058 /source/game/StarUniverseClient.cpp
parent848b11399f2e34d7f1e0523e214287bfdcc5816c (diff)
Initial voice HUD indicator setup
Diffstat (limited to 'source/game/StarUniverseClient.cpp')
-rw-r--r--source/game/StarUniverseClient.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/source/game/StarUniverseClient.cpp b/source/game/StarUniverseClient.cpp
index 1622518..bc1b0b9 100644
--- a/source/game/StarUniverseClient.cpp
+++ b/source/game/StarUniverseClient.cpp
@@ -30,6 +30,7 @@ UniverseClient::UniverseClient(PlayerStoragePtr playerStorage, StatisticsPtr sta
m_playerStorage = move(playerStorage);
m_statistics = move(statistics);
m_pause = false;
+ m_luaRoot = make_shared<LuaRoot>();
reset();
}
@@ -86,7 +87,7 @@ Maybe<String> UniverseClient::connect(UniverseConnection connection, bool allowA
return String(strf("Join failed! Server does not support connections with protocol version {}", StarProtocolVersion));
connection.pushSingle(make_shared<ClientConnectPacket>(Root::singleton().assets()->digest(), allowAssetsMismatch, m_mainPlayer->uuid(), m_mainPlayer->name(),
- m_mainPlayer->species(), m_playerStorage->loadShipData(m_mainPlayer->uuid()), ShipUpgrades(m_mainPlayer->shipUpgrades()),
+ m_mainPlayer->species(), m_playerStorage->loadShipData(m_mainPlayer->uuid()), m_mainPlayer->shipUpgrades(),
m_mainPlayer->log()->introComplete(), account));
connection.sendAll(timeout);
@@ -219,8 +220,11 @@ void UniverseClient::update() {
m_statistics->update();
- if (!m_pause)
+ if (!m_pause) {
m_worldClient->update();
+ for (auto& p : m_scriptContexts)
+ p.second->update();
+ }
m_connection->push(m_worldClient->getOutgoingPackets());
if (!m_pause)
@@ -444,6 +448,28 @@ void UniverseClient::setLuaCallbacks(String const& groupName, LuaCallbacks const
m_worldClient->setLuaCallbacks(groupName, callbacks);
}
+void UniverseClient::startLua() {
+ auto assets = Root::singleton().assets();
+ for (auto& p : assets->json("/client.config:universeScriptContexts").toObject()) {
+ auto scriptComponent = make_shared<ScriptComponent>();
+ scriptComponent->setLuaRoot(m_luaRoot);
+ scriptComponent->setScripts(jsonToStringList(p.second.toArray()));
+
+ for (auto& pair : m_luaCallbacks)
+ scriptComponent->addCallbacks(pair.first, pair.second);
+
+ m_scriptContexts.set(p.first, scriptComponent);
+ scriptComponent->init();
+ }
+}
+
+void UniverseClient::stopLua() {
+ for (auto& p : m_scriptContexts)
+ p.second->uninit();
+
+ m_scriptContexts.clear();
+}
+
ClockConstPtr UniverseClient::universeClock() const {
return m_universeClock;
}
@@ -539,6 +565,8 @@ void UniverseClient::handlePackets(List<PacketPtr> const& packets) {
}
void UniverseClient::reset() {
+ stopLua();
+
m_universeClock.reset();
m_worldClient.reset();
m_celestialDatabase.reset();