1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 12:39:55 +00:00

Merge branch 'set_scale' into 'master'

Allow Lua to set and get GameObject's in game scale

See merge request OpenMW/openmw!3114
This commit is contained in:
psi29a 2023-06-10 08:48:14 +00:00
commit 3fcf9dc1d2
2 changed files with 14 additions and 0 deletions

View File

@ -164,6 +164,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(
@ -285,6 +287,10 @@ namespace MWLua
if constexpr (std::is_same_v<ObjectT, GObject>)
{ // Only for global scripts
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();
std::optional<int> scriptId = cfg.findId(path);

View File

@ -151,6 +151,7 @@
-- @field #string contentFile Lower cased file name of the content file that defines this object; nil for dynamically created objects.
-- @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
@ -209,6 +210,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.