mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 13:53:53 +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
2 changed files with 12 additions and 3 deletions
|
@ -409,11 +409,18 @@ namespace MWLua
|
||||||
|
|
||||||
return GObject(splitted);
|
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();
|
const MWWorld::Ptr& ptr = object.ptr();
|
||||||
int count = ptr.getRefData().getCount();
|
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);
|
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();
|
const MWWorld::Ptr& oldPtr = item.ptr();
|
||||||
auto& refData = oldPtr.getRefData();
|
auto& refData = oldPtr.getRefData();
|
||||||
refData.setCount(count); // temporarily undo removal to run ContainerStore::add
|
refData.setCount(count); // temporarily undo removal to run ContainerStore::add
|
||||||
|
|
|
@ -241,8 +241,10 @@
|
||||||
-- Can be called only from a global script.
|
-- Can be called only from a global script.
|
||||||
-- @function [parent=#GameObject] moveInto
|
-- @function [parent=#GameObject] moveInto
|
||||||
-- @param self
|
-- @param self
|
||||||
-- @param #Inventory dest
|
-- @param #any dest @{#Inventory} or @{#GameObject}
|
||||||
-- @usage item:moveInto(types.Actor.inventory(actor))
|
-- @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.
|
-- Removes an object or reduces a stack of objects.
|
||||||
|
|
Loading…
Reference in a new issue