2023-07-04 09:27:16 +00:00
|
|
|
#include "StarInterfaceLuaBindings.hpp"
|
|
|
|
#include "StarWidgetLuaBindings.hpp"
|
|
|
|
#include "StarJsonExtra.hpp"
|
|
|
|
#include "StarLuaGameConverters.hpp"
|
|
|
|
#include "StarMainInterface.hpp"
|
2023-07-04 12:36:27 +00:00
|
|
|
#include "StarGuiContext.hpp"
|
2024-04-21 20:07:59 +00:00
|
|
|
#include "StarChat.hpp"
|
|
|
|
#include "StarUniverseClient.hpp"
|
|
|
|
#include "StarClientCommandProcessor.hpp"
|
2023-07-04 09:27:16 +00:00
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
|
|
|
LuaCallbacks LuaBindings::makeInterfaceCallbacks(MainInterface* mainInterface) {
|
|
|
|
LuaCallbacks callbacks;
|
|
|
|
|
2023-07-05 08:25:16 +00:00
|
|
|
callbacks.registerCallback("bindCanvas", [mainInterface](String const& canvasName, Maybe<bool> ignoreInterfaceScale) -> Maybe<CanvasWidgetPtr> {
|
|
|
|
if (auto canvas = mainInterface->fetchCanvas(canvasName, ignoreInterfaceScale.value(false)))
|
2023-07-04 09:27:16 +00:00
|
|
|
return canvas;
|
|
|
|
return {};
|
|
|
|
});
|
|
|
|
|
2023-07-04 12:36:27 +00:00
|
|
|
|
|
|
|
callbacks.registerCallback("bindRegisteredPane", [mainInterface](String const& registeredPaneName) -> Maybe<LuaCallbacks> {
|
|
|
|
if (auto pane = mainInterface->paneManager()->maybeRegisteredPane(MainInterfacePanesNames.getLeft(registeredPaneName)))
|
|
|
|
return pane->makePaneCallbacks();
|
|
|
|
return {};
|
|
|
|
});
|
2023-10-31 04:31:53 +00:00
|
|
|
|
|
|
|
callbacks.registerCallback("displayRegisteredPane", [mainInterface](String const& registeredPaneName) {
|
|
|
|
auto pane = MainInterfacePanesNames.getLeft(registeredPaneName);
|
|
|
|
auto paneManager = mainInterface->paneManager();
|
|
|
|
if (paneManager->maybeRegisteredPane(pane))
|
|
|
|
paneManager->displayRegisteredPane(pane);
|
|
|
|
});
|
2023-07-04 12:36:27 +00:00
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
callbacks.registerCallback("scale", []() -> int {
|
2023-07-04 12:36:27 +00:00
|
|
|
return GuiContext::singleton().interfaceScale();
|
|
|
|
});
|
|
|
|
|
2023-07-17 12:20:39 +00:00
|
|
|
callbacks.registerCallback("queueMessage", [mainInterface](String const& message, Maybe<float> cooldown, Maybe<float> springState) {
|
|
|
|
mainInterface->queueMessage(message, cooldown, springState.value(0));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2023-07-04 09:27:16 +00:00
|
|
|
return callbacks;
|
|
|
|
}
|
|
|
|
|
2024-04-21 20:07:59 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-07-04 09:27:16 +00:00
|
|
|
}
|