mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Merge branch 'moveinto' into 'master'
[Lua] Accept GameObject as destination in obj:moveInto. See merge request OpenMW/openmw!3318
This commit is contained in:
commit
861b9b215c
@ -409,11 +409,18 @@ namespace MWLua
|
||||
|
||||
return GObject(splitted);
|
||||
};
|
||||
objectT["moveInto"] = [removeFn, context](const GObject& object, const Inventory<GObject>& inventory) {
|
||||
objectT["moveInto"] = [removeFn, context](const GObject& object, const sol::object& dest) {
|
||||
const MWWorld::Ptr& ptr = object.ptr();
|
||||
int count = ptr.getRefData().getCount();
|
||||
MWWorld::Ptr destPtr;
|
||||
if (dest.is<GObject>())
|
||||
destPtr = dest.as<GObject>().ptr();
|
||||
else
|
||||
destPtr = LuaUtil::cast<Inventory<GObject>>(dest).mObj.ptr();
|
||||
destPtr.getContainerStore(); // raises an error if there is no container store
|
||||
|
||||
std::optional<DelayedRemovalFn> delayedRemovalFn = removeFn(ptr, count);
|
||||
context.mLuaManager->addAction([item = object, count, cont = inventory.mObj, delayedRemovalFn] {
|
||||
context.mLuaManager->addAction([item = object, count, cont = GObject(destPtr), delayedRemovalFn] {
|
||||
const MWWorld::Ptr& oldPtr = item.ptr();
|
||||
auto& refData = oldPtr.getRefData();
|
||||
refData.setCount(count); // temporarily undo removal to run ContainerStore::add
|
||||
|
@ -241,8 +241,10 @@
|
||||
-- Can be called only from a global script.
|
||||
-- @function [parent=#GameObject] moveInto
|
||||
-- @param self
|
||||
-- @param #Inventory dest
|
||||
-- @param #any dest @{#Inventory} or @{#GameObject}
|
||||
-- @usage item:moveInto(types.Actor.inventory(actor))
|
||||
-- @usage item:moveInto(types.Container.content(container))
|
||||
-- @usage item:moveInto(container)
|
||||
|
||||
---
|
||||
-- Removes an object or reduces a stack of objects.
|
||||
|
Loading…
x
Reference in New Issue
Block a user