diff --git a/CHANGELOG.md b/CHANGELOG.md index 8656f792df..8ee20d33d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +0.50.0 +------ + + Feature #8320: Add access mwscript source text to lua api + 0.49.0 ------ diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 37de0abeab..2de32a09a5 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -60,7 +60,7 @@ add_openmw_dir (mwscript add_openmw_dir (mwlua luamanagerimp object objectlists userdataserializer luaevents engineevents objectvariant - context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings + context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings coremwscriptbindings mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings dialoguebindings postprocessingbindings stats recordstore debugbindings corebindings worldbindings worker magicbindings factionbindings classbindings itemdata inputprocessor animationbindings birthsignbindings racebindings markupbindings diff --git a/apps/openmw/mwlua/corebindings.cpp b/apps/openmw/mwlua/corebindings.cpp index 9df435c00d..c4fec99458 100644 --- a/apps/openmw/mwlua/corebindings.cpp +++ b/apps/openmw/mwlua/corebindings.cpp @@ -19,6 +19,7 @@ #include "../mwworld/datetimemanager.hpp" #include "../mwworld/esmstore.hpp" +#include "coremwscriptbindings.hpp" #include "dialoguebindings.hpp" #include "factionbindings.hpp" #include "luaevents.hpp" @@ -97,6 +98,9 @@ namespace MWLua api["stats"] = context.cachePackage("openmw_core_stats", [context]() { return initCoreStatsBindings(context); }); + api["mwscripts"] + = context.cachePackage("openmw_core_mwscripts", [context]() { return initCoreMwScriptBindings(context); }); + api["factions"] = context.cachePackage("openmw_core_factions", [context]() { return initCoreFactionBindings(context); }); api["dialogue"] diff --git a/apps/openmw/mwlua/coremwscriptbindings.cpp b/apps/openmw/mwlua/coremwscriptbindings.cpp new file mode 100644 index 0000000000..6bf01a4b3d --- /dev/null +++ b/apps/openmw/mwlua/coremwscriptbindings.cpp @@ -0,0 +1,28 @@ +#include "coremwscriptbindings.hpp" + +#include + +#include "../mwworld/esmstore.hpp" + +#include "context.hpp" +#include "recordstore.hpp" + +namespace MWLua +{ + sol::table initCoreMwScriptBindings(const Context& context) + { + sol::state_view lua = context.sol(); + sol::table api(lua, sol::create); + + auto recordBindingsClass = lua.new_usertype("ESM3_Script"); + recordBindingsClass[sol::meta_function::to_string] + = [](const ESM::Script& rec) { return "ESM3_Script[" + rec.mId.toDebugString() + "]"; }; + recordBindingsClass["id"] + = sol::readonly_property([](const ESM::Script& rec) { return rec.mId.serializeText(); }); + recordBindingsClass["text"] = sol::readonly_property([](const ESM::Script& rec) { return rec.mScriptText; }); + + addRecordFunctionBinding(api, context); + + return LuaUtil::makeReadOnly(api); + } +} diff --git a/apps/openmw/mwlua/coremwscriptbindings.hpp b/apps/openmw/mwlua/coremwscriptbindings.hpp new file mode 100644 index 0000000000..0f69b7dcb7 --- /dev/null +++ b/apps/openmw/mwlua/coremwscriptbindings.hpp @@ -0,0 +1,13 @@ +#ifndef MWLUA_COREMWSCRIPTBINDINGS_H +#define MWLUA_COREMWSCRIPTBINDINGS_H + +#include + +namespace MWLua +{ + struct Context; + + sol::table initCoreMwScriptBindings(const Context& context); +} + +#endif // MWLUA_COREMWSCRIPTBINDINGS_H diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 8a78a52441..dc689e71c3 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -1143,4 +1143,19 @@ -- @field #number favouredSkillValue Secondary skill value required to get this rank. -- @field #number factionReaction Reaction of faction members if player is in this faction. +--- @{#MWScripts}: MWScripts +-- @field [parent=#core] #MWScript mwscripts + +--- +-- A read-only list of all @{#MWScriptRecord}s in the world database. +-- @field [parent=#MWScripts] #list<#MWScriptRecord> records +-- @usage local record = core.mwscripts.records['example_recordid'] +-- @usage local record = core.mwscripts.records[1] + +--- +-- MWScript data record +-- @type MWScriptRecord +-- @field #string id MWScript id +-- @field #string text MWScript content + return nil