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

summaryrefslogtreecommitdiff
path: root/source/frontend/StarInterfaceLuaBindings.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-04-22 06:07:59 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2024-04-22 06:07:59 +1000
commitca1426eabc873f781eb0dd389d45634b7d183250 (patch)
tree15ea83658ca3824232f14fe4b32ec714e0aa05c6 /source/frontend/StarInterfaceLuaBindings.cpp
parentd5f5fb5ddf0d4a9f0b0e6ac012121926d2fcd949 (diff)
Lua chat callbacks + better font styling
golly gee whiz!! i hope i didn't fuck something up
Diffstat (limited to 'source/frontend/StarInterfaceLuaBindings.cpp')
-rw-r--r--source/frontend/StarInterfaceLuaBindings.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/source/frontend/StarInterfaceLuaBindings.cpp b/source/frontend/StarInterfaceLuaBindings.cpp
index a023a71..9e0bb2e 100644
--- a/source/frontend/StarInterfaceLuaBindings.cpp
+++ b/source/frontend/StarInterfaceLuaBindings.cpp
@@ -4,6 +4,9 @@
#include "StarLuaGameConverters.hpp"
#include "StarMainInterface.hpp"
#include "StarGuiContext.hpp"
+#include "StarChat.hpp"
+#include "StarUniverseClient.hpp"
+#include "StarClientCommandProcessor.hpp"
namespace Star {
@@ -42,4 +45,49 @@ LuaCallbacks LuaBindings::makeInterfaceCallbacks(MainInterface* mainInterface) {
return callbacks;
}
+LuaCallbacks LuaBindings::makeChatCallbacks(MainInterface* mainInterface, UniverseClient* client) {
+ LuaCallbacks callbacks;
+
+ auto chat = as<Chat>(mainInterface->paneManager()->registeredPane(MainInterfacePanes::Chat).get());
+
+ callbacks.registerCallback("send", [chat, client](String const& message, Maybe<String> modeName, Maybe<bool> speak) {
+ auto sendMode = modeName ? ChatSendModeNames.getLeft(*modeName) : ChatSendMode::Broadcast;
+ client->sendChat(message, sendMode, speak);
+ });
+
+ // just for SE compat - this shoulda been a utility callback :moyai:
+ callbacks.registerCallback("parseArguments", [](String const& args) {
+ return Json::parseSequence(args);
+ });
+
+ callbacks.registerCallback("command", [mainInterface](String const& command) -> StringList {
+ return mainInterface->commandProcessor()->handleCommand(command);
+ });
+
+ callbacks.registerCallback("addMessage", [client, chat](String const& text, Maybe<Json> config) {
+ ChatReceivedMessage message({MessageContext::Mode::CommandResult, ""}, client->clientContext()->connectionId(), "", text);
+ if (config) {
+ if (auto mode = config->optString("mode"))
+ message.context.mode = MessageContextModeNames.getLeft(*mode);
+ if (auto channelName = config->optString("channelName"))
+ message.context.channelName = std::move(*channelName);
+ if (auto portrait = config->optString("portrait"))
+ message.portrait = std::move(*portrait);
+ if (auto fromNick = config->optString("fromNick"))
+ message.fromNick = std::move(*fromNick);
+ }
+ chat->addMessages({std::move(message)}, config ? config->getBool("showPane", true) : true);
+ });
+
+ callbacks.registerCallback("input", [chat]() -> String {
+ return chat->currentChat();
+ });
+
+ callbacks.registerCallback("setInput", [chat](String const& text, Maybe<bool> moveCursor) -> bool {
+ return chat->setCurrentChat(text, moveCursor.value(false));
+ });
+
+ return callbacks;
+}
+
}