diff options
author | LaG1924 <lag1924@gmail.com> | 2021-07-05 15:36:28 +0200 |
---|---|---|
committer | LaG1924 <lag1924@gmail.com> | 2021-07-05 15:36:28 +0200 |
commit | 28cda3a34c85a35be2e1e4fa35b10fae5d0956d7 (patch) | |
tree | 4e2fa2a75f76778b1982a84c5a17d8d8744dd078 | |
parent | Fixed shader error on MacOS (diff) | |
download | AltCraft-28cda3a34c85a35be2e1e4fa35b10fae5d0956d7.tar AltCraft-28cda3a34c85a35be2e1e4fa35b10fae5d0956d7.tar.gz AltCraft-28cda3a34c85a35be2e1e4fa35b10fae5d0956d7.tar.bz2 AltCraft-28cda3a34c85a35be2e1e4fa35b10fae5d0956d7.tar.lz AltCraft-28cda3a34c85a35be2e1e4fa35b10fae5d0956d7.tar.xz AltCraft-28cda3a34c85a35be2e1e4fa35b10fae5d0956d7.tar.zst AltCraft-28cda3a34c85a35be2e1e4fa35b10fae5d0956d7.zip |
-rw-r--r-- | cwd/assets/altcraft/scripts/init.lua | 11 | ||||
-rw-r--r-- | src/Plugin.cpp | 18 | ||||
-rw-r--r-- | src/Plugin.hpp | 2 | ||||
-rw-r--r-- | src/Render.cpp | 2 |
4 files changed, 32 insertions, 1 deletions
diff --git a/cwd/assets/altcraft/scripts/init.lua b/cwd/assets/altcraft/scripts/init.lua index b60a988..c938e94 100644 --- a/cwd/assets/altcraft/scripts/init.lua +++ b/cwd/assets/altcraft/scripts/init.lua @@ -7,6 +7,7 @@ local plugin = { onTick = nil, onRequestBlockInfo = nil, onChatMessage = nil, + onDisconnected = nil, } function plugin.onLoad () @@ -104,6 +105,16 @@ function plugin.onChatMessage(chat, pos) MoveChatToBottom = true end +function plugin.onDisconnected(reason) + local mmDoc = {} + for i,d in ipairs(rmlui.contexts["default"].documents) do + if d.title == "MainMenu" then + mmDoc = d + end + end + mmDoc:GetElementById('disclaimer').inner_rml = reason +end + AC.RegisterDimension(0, Dimension.new("overworld", true)) AC.RegisterDimension(-1, Dimension.new("the_nether", false)) AC.RegisterDimension(1, Dimension.new("the_end", false)) diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 98df8c3..3e06b0c 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -25,6 +25,7 @@ struct Plugin { const std::function<void(double)> onTick; const std::function<BlockInfo(Vector)> onRequestBlockInfo; const std::function<void(Chat, int)> onChatMessage; + const std::function<void(std::string)> onDisconnected; }; @@ -45,6 +46,7 @@ namespace PluginApi { plugin["onTick"].get_or(std::function<void(double)>()), plugin["onRequestBlockInfo"].get_or(std::function<BlockInfo(Vector)>()), plugin["onChatMessage"].get_or(std::function<void(Chat, int)>()), + plugin["onDisconnected"].get_or(std::function<void(std::string)>()), }; plugins.push_back(nativePlugin); LOG(INFO)<<"Loading plugin " << (!nativePlugin.displayName.empty() ? nativePlugin.displayName : nativePlugin.name); @@ -371,7 +373,7 @@ BlockInfo PluginSystem::RequestBlockInfo(Vector blockPos) { void PluginSystem::CallOnChatMessage(const Chat& chat, int position) { OPTICK_EVENT(); for (Plugin& plugin : plugins) { - if (plugin.onRequestBlockInfo && plugin.errors < 10) + if (plugin.errors < 10) try { plugin.onChatMessage(chat, position); } @@ -381,3 +383,17 @@ void PluginSystem::CallOnChatMessage(const Chat& chat, int position) { } } } + +void PluginSystem::CallOnDisconnected(const std::string &reason) { + OPTICK_EVENT(); + for (Plugin& plugin : plugins) { + if (plugin.errors < 10) + try { + plugin.onDisconnected(reason); + } + catch (sol::error& e) { + LOG(ERROR) << e.what(); + plugin.errors++; + } + } +} diff --git a/src/Plugin.hpp b/src/Plugin.hpp index 13b126e..e108c4f 100644 --- a/src/Plugin.hpp +++ b/src/Plugin.hpp @@ -22,4 +22,6 @@ namespace PluginSystem { BlockInfo RequestBlockInfo(Vector blockPos); void CallOnChatMessage(const Chat& chat, int position); + + void CallOnDisconnected(const std::string &reason); }
\ No newline at end of file diff --git a/src/Render.cpp b/src/Render.cpp index 896a05f..b9b7ab0 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -465,6 +465,7 @@ void Render::InitEvents() { world.reset(); SetState(State::MainMenu); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + PluginSystem::CallOnDisconnected("Connection failed: " + eventData.get <std::string>()); }); listener.RegisterHandler("Disconnected", [this](const Event& eventData) { @@ -473,6 +474,7 @@ void Render::InitEvents() { world.reset(); SetState(State::MainMenu); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + PluginSystem::CallOnDisconnected("Disconnected: " + eventData.get<std::string>()); }); listener.RegisterHandler("Connecting", [this](const Event&) { |