mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 08:15:34 +00:00
Merge branch 'soul_set_lua' into 'master'
Allow Soul values on Misc Items to be set by Lua See merge request OpenMW/openmw!2927
This commit is contained in:
commit
91c85294d7
2 changed files with 32 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
|
|
||||||
|
#include <components/esm3/loadcrea.hpp>
|
||||||
#include <components/esm3/loadmisc.hpp>
|
#include <components/esm3/loadmisc.hpp>
|
||||||
#include <components/lua/luastate.hpp>
|
#include <components/lua/luastate.hpp>
|
||||||
#include <components/misc/resourcehelpers.hpp>
|
#include <components/misc/resourcehelpers.hpp>
|
||||||
|
@ -25,6 +26,25 @@ namespace MWLua
|
||||||
|
|
||||||
addRecordFunctionBinding<ESM::Miscellaneous>(miscellaneous, context);
|
addRecordFunctionBinding<ESM::Miscellaneous>(miscellaneous, context);
|
||||||
|
|
||||||
|
miscellaneous["setSoul"] = [](const GObject& object, std::string_view soulId) {
|
||||||
|
ESM::RefId creature = ESM::RefId::deserializeText(soulId);
|
||||||
|
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
|
||||||
|
if (!store.get<ESM::Creature>().search(creature))
|
||||||
|
{
|
||||||
|
// TODO: Add Support for NPC Souls
|
||||||
|
throw std::runtime_error("Cannot use non-existent creature as a soul: " + std::string(soulId));
|
||||||
|
}
|
||||||
|
|
||||||
|
object.ptr().getCellRef().setSoul(creature);
|
||||||
|
};
|
||||||
|
miscellaneous["soul"] = [](const Object& object) -> sol::optional<std::string> {
|
||||||
|
ESM::RefId soul = object.ptr().getCellRef().getSoul();
|
||||||
|
if (soul.empty())
|
||||||
|
return sol::nullopt;
|
||||||
|
else
|
||||||
|
return soul.serializeText();
|
||||||
|
};
|
||||||
sol::usertype<ESM::Miscellaneous> record
|
sol::usertype<ESM::Miscellaneous> record
|
||||||
= context.mLua->sol().new_usertype<ESM::Miscellaneous>("ESM3_Miscellaneous");
|
= context.mLua->sol().new_usertype<ESM::Miscellaneous>("ESM3_Miscellaneous");
|
||||||
record[sol::meta_function::to_string]
|
record[sol::meta_function::to_string]
|
||||||
|
|
|
@ -802,6 +802,18 @@
|
||||||
-- @param #any objectOrRecordId
|
-- @param #any objectOrRecordId
|
||||||
-- @return #MiscellaneousRecord
|
-- @return #MiscellaneousRecord
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Returns the read-only soul of a miscellaneous item
|
||||||
|
-- @function [parent=#Miscellaneous] soul
|
||||||
|
-- @param openmw.core#GameObject object
|
||||||
|
-- @return #string
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Sets the soul of a miscellaneous item, intended for soul gem objects; Must be used in a global script.
|
||||||
|
-- @function [parent=#Miscellaneous] setSoul
|
||||||
|
-- @param openmw.core#GameObject object
|
||||||
|
-- @param #string soulId Record ID for the soul of the creature to use
|
||||||
|
|
||||||
---
|
---
|
||||||
-- @type MiscellaneousRecord
|
-- @type MiscellaneousRecord
|
||||||
-- @field #string id The record ID of the miscellaneous item
|
-- @field #string id The record ID of the miscellaneous item
|
||||||
|
|
Loading…
Reference in a new issue