mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-21 18:40:01 +00:00
ESM::Dialogue Lua bindings 1
This commit is contained in:
parent
819aace891
commit
c622cfc245
@ -62,7 +62,7 @@ add_openmw_dir (mwscript
|
|||||||
add_openmw_dir (mwlua
|
add_openmw_dir (mwlua
|
||||||
luamanagerimp object objectlists userdataserializer luaevents engineevents objectvariant
|
luamanagerimp object objectlists userdataserializer luaevents engineevents objectvariant
|
||||||
context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings
|
context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings
|
||||||
mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings
|
mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings dialoguebindings
|
||||||
postprocessingbindings stats recordstore debugbindings corebindings worldbindings worker magicbindings factionbindings
|
postprocessingbindings stats recordstore debugbindings corebindings worldbindings worker magicbindings factionbindings
|
||||||
classbindings itemdata inputprocessor animationbindings birthsignbindings racebindings markupbindings
|
classbindings itemdata inputprocessor animationbindings birthsignbindings racebindings markupbindings
|
||||||
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc
|
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "luaevents.hpp"
|
#include "luaevents.hpp"
|
||||||
#include "magicbindings.hpp"
|
#include "magicbindings.hpp"
|
||||||
#include "soundbindings.hpp"
|
#include "soundbindings.hpp"
|
||||||
|
#include "dialoguebindings.hpp"
|
||||||
#include "stats.hpp"
|
#include "stats.hpp"
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
@ -98,7 +99,7 @@ namespace MWLua
|
|||||||
api["stats"] = initCoreStatsBindings(context);
|
api["stats"] = initCoreStatsBindings(context);
|
||||||
|
|
||||||
api["factions"] = initCoreFactionBindings(context);
|
api["factions"] = initCoreFactionBindings(context);
|
||||||
|
api["dialogue"] = initCoreDialogueBindings(context);
|
||||||
api["l10n"] = LuaUtil::initL10nLoader(lua->sol(), MWBase::Environment::get().getL10nManager());
|
api["l10n"] = LuaUtil::initL10nLoader(lua->sol(), MWBase::Environment::get().getL10nManager());
|
||||||
const MWWorld::Store<ESM::GameSetting>* gmstStore
|
const MWWorld::Store<ESM::GameSetting>* gmstStore
|
||||||
= &MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>();
|
= &MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>();
|
||||||
|
133
apps/openmw/mwlua/dialoguebindings.cpp
Normal file
133
apps/openmw/mwlua/dialoguebindings.cpp
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
#include "dialoguebindings.hpp"
|
||||||
|
#include "context.hpp"
|
||||||
|
#include "recordstore.hpp"
|
||||||
|
#include "apps/openmw/mwworld/store.hpp"
|
||||||
|
#include <components/esm3/loaddial.hpp>
|
||||||
|
#include <components/lua/luastate.hpp>
|
||||||
|
#include <components/misc/resourcehelpers.hpp>
|
||||||
|
#include <components/vfs/pathutil.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
sol::table prepareJournalRecord(sol::state_view& lua, const ESM::Dialogue& mwDialogue)
|
||||||
|
{
|
||||||
|
const auto dialogueRecordId = mwDialogue.mId.serializeText();
|
||||||
|
sol::table result(lua, sol::create);
|
||||||
|
result["text"] = mwDialogue.mStringId;
|
||||||
|
|
||||||
|
sol::table preparedInfos(lua, sol::create);
|
||||||
|
unsigned index = 1;
|
||||||
|
for (const auto& mwDialogueInfo : mwDialogue.mInfo)
|
||||||
|
{
|
||||||
|
if (mwDialogueInfo.mQuestStatus == ESM::DialInfo::QuestStatus::QS_Name)
|
||||||
|
{
|
||||||
|
result["questName"] = mwDialogueInfo.mResponse;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sol::table infoElement(lua, sol::create);
|
||||||
|
infoElement["id"] = (dialogueRecordId + '#' + mwDialogueInfo.mId.serializeText());
|
||||||
|
infoElement["text"] = mwDialogueInfo.mResponse;
|
||||||
|
infoElement["questStage"] = mwDialogueInfo.mData.mJournalIndex;
|
||||||
|
infoElement["questFinished"] = (mwDialogueInfo.mQuestStatus == ESM::DialInfo::QuestStatus::QS_Finished);
|
||||||
|
infoElement["questRestart"] = (mwDialogueInfo.mQuestStatus == ESM::DialInfo::QuestStatus::QS_Restart);
|
||||||
|
preparedInfos[index++] = infoElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
result["infos"] = LuaUtil::makeStrictReadOnly(preparedInfos);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
sol::table prepareNonJournalRecord(sol::state_view& lua, const ESM::Dialogue& mwDialogue)
|
||||||
|
{
|
||||||
|
const auto dialogueRecordId = mwDialogue.mId.serializeText();
|
||||||
|
sol::table result(lua, sol::create);
|
||||||
|
result["text"] = mwDialogue.mStringId;
|
||||||
|
|
||||||
|
sol::table preparedInfos(lua, sol::create);
|
||||||
|
unsigned index = 1;
|
||||||
|
for (const auto& mwDialogueInfo : mwDialogue.mInfo)
|
||||||
|
{
|
||||||
|
sol::table infoElement(lua, sol::create);
|
||||||
|
infoElement["id"] = (dialogueRecordId + '#' + mwDialogueInfo.mId.serializeText());
|
||||||
|
infoElement["text"] = mwDialogueInfo.mResponse;
|
||||||
|
infoElement["actorId"] = mwDialogueInfo.mActor.serializeText();
|
||||||
|
infoElement["actorRace"] = mwDialogueInfo.mRace.serializeText();
|
||||||
|
infoElement["actorClass"] = mwDialogueInfo.mClass.serializeText();
|
||||||
|
infoElement["actorFaction"] = mwDialogueInfo.mFaction.serializeText();
|
||||||
|
if (mwDialogueInfo.mData.mRank != -1)
|
||||||
|
{
|
||||||
|
infoElement["actorFactionRank"] = mwDialogueInfo.mData.mRank;
|
||||||
|
}
|
||||||
|
infoElement["actorCell"] = mwDialogueInfo.mClass.serializeText();
|
||||||
|
infoElement["actorDisposition"] = mwDialogueInfo.mData.mDisposition;
|
||||||
|
if (mwDialogueInfo.mData.mGender != ESM::DialInfo::Gender::NA)
|
||||||
|
{
|
||||||
|
infoElement["actorGender"] = mwDialogueInfo.mData.mGender;
|
||||||
|
}
|
||||||
|
infoElement["playerFaction"] = mwDialogueInfo.mPcFaction.serializeText();
|
||||||
|
if (mwDialogueInfo.mData.mPCrank != -1)
|
||||||
|
{
|
||||||
|
infoElement["playerFactionRank"] = mwDialogueInfo.mData.mPCrank;
|
||||||
|
}
|
||||||
|
if (not mwDialogueInfo.mSound.empty())
|
||||||
|
{
|
||||||
|
infoElement["sound"] = Misc::ResourceHelpers::correctSoundPath(VFS::Path::Normalized(mwDialogueInfo.mSound)).value();
|
||||||
|
}
|
||||||
|
//mResultScript TODO
|
||||||
|
//mSelects TODO
|
||||||
|
preparedInfos[index++] = infoElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
result["infos"] = LuaUtil::makeStrictReadOnly(preparedInfos);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
|
||||||
|
sol::table initCoreDialogueBindings(const Context& context)
|
||||||
|
{
|
||||||
|
sol::state_view& lua = context.mLua->sol();
|
||||||
|
sol::table api(lua, sol::create);
|
||||||
|
|
||||||
|
const MWWorld::Store<ESM::Dialogue>& mwDialogueStore = MWBase::Environment::get().getESMStore()->get<ESM::Dialogue>();
|
||||||
|
|
||||||
|
sol::table journalRecordsByQuestId(lua, sol::create);
|
||||||
|
sol::table topicRecordsByTopicId(lua, sol::create);
|
||||||
|
sol::table voiceRecordsById(lua, sol::create);
|
||||||
|
sol::table greetingRecordsById(lua, sol::create);
|
||||||
|
sol::table persuasionRecordsById(lua, sol::create);
|
||||||
|
for (const auto& mwDialogue : mwDialogueStore)
|
||||||
|
{
|
||||||
|
const auto dialogueRecordId = mwDialogue.mId.serializeText();
|
||||||
|
if (mwDialogue.mType == ESM::Dialogue::Type::Journal)
|
||||||
|
{
|
||||||
|
journalRecordsByQuestId[dialogueRecordId] = prepareJournalRecord(lua, mwDialogue);
|
||||||
|
}
|
||||||
|
else if (mwDialogue.mType == ESM::Dialogue::Type::Topic)
|
||||||
|
{
|
||||||
|
topicRecordsByTopicId[dialogueRecordId] = prepareNonJournalRecord(lua, mwDialogue);
|
||||||
|
}
|
||||||
|
else if (mwDialogue.mType == ESM::Dialogue::Type::Voice)
|
||||||
|
{
|
||||||
|
voiceRecordsById[dialogueRecordId] = prepareNonJournalRecord(lua, mwDialogue);
|
||||||
|
}
|
||||||
|
else if (mwDialogue.mType == ESM::Dialogue::Type::Greeting)
|
||||||
|
{
|
||||||
|
greetingRecordsById[dialogueRecordId] = prepareNonJournalRecord(lua, mwDialogue);
|
||||||
|
}
|
||||||
|
else if (mwDialogue.mType == ESM::Dialogue::Type::Persuasion)
|
||||||
|
{
|
||||||
|
persuasionRecordsById[dialogueRecordId] = prepareNonJournalRecord(lua, mwDialogue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
api["journalRecords"] = LuaUtil::makeStrictReadOnly(journalRecordsByQuestId);
|
||||||
|
api["topicRecords"] = LuaUtil::makeStrictReadOnly(topicRecordsByTopicId);
|
||||||
|
api["voiceRecords"] = LuaUtil::makeStrictReadOnly(voiceRecordsById);
|
||||||
|
api["greetingRecords"] = LuaUtil::makeStrictReadOnly(greetingRecordsById);
|
||||||
|
api["persuasionRecords"] = LuaUtil::makeStrictReadOnly(persuasionRecordsById);
|
||||||
|
|
||||||
|
return LuaUtil::makeReadOnly(api);
|
||||||
|
}
|
||||||
|
}
|
12
apps/openmw/mwlua/dialoguebindings.hpp
Normal file
12
apps/openmw/mwlua/dialoguebindings.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef MWLUA_DIALOGUEBINDINGS_H
|
||||||
|
#define MWLUA_DIALOGUEBINDINGS_H
|
||||||
|
|
||||||
|
#include <sol/forward.hpp>
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
struct Context;
|
||||||
|
sol::table initCoreDialogueBindings(const Context&);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MWLUA_DIALOGUEBINDINGS_H
|
Loading…
x
Reference in New Issue
Block a user