From 41a2c82f9310d3c90511a4d21d4345d7ccf72303 Mon Sep 17 00:00:00 2001 From: Tobias Tribble Date: Wed, 7 Jun 2023 19:23:36 -0500 Subject: [PATCH 1/2] Added scale property and setScale function --- apps/openmw/mwlua/objectbindings.cpp | 5 +++++ files/lua_api/openmw/core.lua | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index 01ef08ffdb..ab7f967af7 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -157,6 +157,8 @@ namespace MWLua }); objectT["position"] = sol::readonly_property( [](const ObjectT& o) -> osg::Vec3f { return o.ptr().getRefData().getPosition().asVec3(); }); + objectT["scale"] + = sol::readonly_property([](const ObjectT& o) -> float { return o.ptr().getCellRef().getScale(); }); objectT["rotation"] = sol::readonly_property( [](const ObjectT& o) -> osg::Vec3f { return o.ptr().getRefData().getPosition().asRotationVec3(); }); objectT["startingPosition"] = sol::readonly_property( @@ -278,6 +280,9 @@ namespace MWLua if constexpr (std::is_same_v) { // Only for global scripts + objectT["setScale"] = [](const GObject& object, float scale) { + MWBase::Environment::get().getWorld()->scaleObject(object.ptr(), scale); + }; objectT["addScript"] = [context](const GObject& object, std::string_view path, sol::object initData) { const LuaUtil::ScriptsConfiguration& cfg = context.mLua->getConfiguration(); std::optional scriptId = cfg.findId(path); diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index fa56a1c80e..1de97394f2 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -110,6 +110,7 @@ -- @field #string id A unique id of this object (not record id), can be used as a key in a table. -- @field #boolean enabled Whether the object is enabled or disabled. Global scripts can set the value. Items in containers or inventories can't be disabled. -- @field openmw.util#Vector3 position Object position. +-- @field #number scale Object scale. -- @field openmw.util#Vector3 rotation Object rotation (ZXY order). -- @field openmw.util#Vector3 startingPosition The object original position -- @field openmw.util#Vector3 startingRotation The object original rotation @@ -168,6 +169,13 @@ -- @param self -- @param #string scriptPath Path to the script in OpenMW virtual filesystem. +--- +-- Sets the object's scale. +-- Can be called only from a global script. +-- @function [parent=#GameObject] setScale +-- @param self +-- @param #number scale Scale desired in game. + --- -- Moves object to given cell and position. -- Can be called only from a global script. From 0e6155c529b1cc710025b2cc8a138516eb987068 Mon Sep 17 00:00:00 2001 From: Tobias Tribble Date: Thu, 8 Jun 2023 23:50:54 -0500 Subject: [PATCH 2/2] Added delayed action --- apps/openmw/mwlua/objectbindings.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index ab7f967af7..abe78219b9 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -280,8 +280,9 @@ namespace MWLua if constexpr (std::is_same_v) { // Only for global scripts - objectT["setScale"] = [](const GObject& object, float scale) { - MWBase::Environment::get().getWorld()->scaleObject(object.ptr(), scale); + objectT["setScale"] = [context](const GObject& object, float scale) { + context.mLuaManager->addAction( + [object, scale] { MWBase::Environment::get().getWorld()->scaleObject(object.ptr(), scale); }); }; objectT["addScript"] = [context](const GObject& object, std::string_view path, sol::object initData) { const LuaUtil::ScriptsConfiguration& cfg = context.mLua->getConfiguration();