Merge branch 'talk-to-me-about-something-else' into 'master'
Some checks failed
Build and test / Ubuntu (push) Has been cancelled
Build and test / MacOS (push) Has been cancelled
Build and test / Read .env file and expose it as output (push) Has been cancelled
Build and test / Windows (2019) (push) Has been cancelled
Build and test / Windows (2022) (push) Has been cancelled

FEAT: AddTopic in Lua, close #8334

Closes #8334

See merge request OpenMW/openmw!4529
This commit is contained in:
Dave Corley 2025-04-24 00:31:58 +00:00
commit ca098205ff

View file

@ -1,7 +1,9 @@
#include "types.hpp"
#include <apps/openmw/mwbase/dialoguemanager.hpp>
#include <components/esm3/loadbsgn.hpp>
#include <components/esm3/loadfact.hpp>
#include <components/misc/strings/format.hpp>
#include "../birthsignbindings.hpp"
#include "../luamanagerimp.hpp"
@ -195,6 +197,22 @@ namespace MWLua
throw std::runtime_error("Only player and global scripts can toggle teleportation.");
MWBase::Environment::get().getWorld()->enableTeleporting(state);
};
player["addTopic"] = [](const Object& player, std::string_view topicId) {
verifyPlayer(player);
ESM::RefId topic = ESM::RefId::deserializeText(topicId);
const ESM::Dialogue* dialogueRecord
= MWBase::Environment::get().getESMStore()->get<ESM::Dialogue>().search(topic);
if (!dialogueRecord)
throw std::runtime_error(
Misc::StringUtils::format("Failed to add topic ", topicId, ": topic record not found"));
else if (dialogueRecord->mType != ESM::Dialogue::Topic)
throw std::runtime_error(
Misc::StringUtils::format("Failed to add topic ", topicId, ": record is not a topic"));
MWBase::Environment::get().getDialogueManager()->addTopic(topic);
};
player["sendMenuEvent"] = [context](const Object& player, std::string eventName, const sol::object& eventData) {
verifyPlayer(player);
context.mLuaEvents->addMenuEvent({ std::move(eventName), LuaUtil::serialize(eventData) });