From e1dea58e809bb2440b81a1771c6df916e50dda1a Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:44:46 +1100 Subject: [PATCH] questPortrait callback --- source/game/StarQuestManager.cpp | 5 +--- .../game/scripting/StarPlayerLuaBindings.cpp | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/source/game/StarQuestManager.cpp b/source/game/StarQuestManager.cpp index ee2c82b..df8a19a 100644 --- a/source/game/StarQuestManager.cpp +++ b/source/game/StarQuestManager.cpp @@ -144,10 +144,7 @@ StringMap QuestManager::serverQuests() const { } QuestPtr QuestManager::getQuest(String const& questId) const { - if (auto quest = m_quests.ptr(questId)) - return *quest; - - return {}; + return m_quests.get(questId); } bool QuestManager::hasQuest(String const& questId) const { diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index 4d3b316..5af86d0 100644 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -478,24 +478,28 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { }); callbacks.registerCallback("quest", [player](String const& questId) -> Json { - if (auto quest = player->questManager()->getQuest(questId)) - return quest->diskStore(); - - return {}; + if (!player->questManager()->hasQuest(questId)) + return {}; + return player->questManager()->getQuest(questId)->diskStore(); }); - callbacks.registerCallback("questState", [player](String const& questId) -> Maybe { - if (auto quest = player->questManager()->getQuest(questId)) - return QuestStateNames.getRight(quest->state()); + callbacks.registerCallback("questPortrait", [player](String const& questId, String const& portraitName) -> Maybe> { + if (!player->questManager()->hasQuest(questId)) + return {}; + return player->questManager()->getQuest(questId)->portrait(portraitName); + }); - return {}; + + callbacks.registerCallback("questState", [player](String const& questId) -> Maybe { + if (!player->questManager()->hasQuest(questId)) + return {}; + return QuestStateNames.getRight(player->questManager()->getQuest(questId)->state()); }); callbacks.registerCallback("callQuest", [player](String const& questId, String const& func, LuaVariadic const& args) -> Maybe { - if (auto quest = player->questManager()->getQuest(questId)) - return quest->callScript(func, args); - - return {}; + if (!player->questManager()->hasQuest(questId)) + return {}; + return player->questManager()->getQuest(questId)->callScript(func, args); }); callbacks.registerCallback("hasQuest", [player](String const& questId) {