From e4439806edda830c159c90e5079adfedaf76853e Mon Sep 17 00:00:00 2001 From: Sebastian Fieber Date: Wed, 25 Jun 2025 20:27:30 +0200 Subject: [PATCH] land bindings afterwork - fix include order + style - cellOrName -> cellOrId - bump lua api revision to 78 - cellOrId is not optional anymore for getHeightAt --- CMakeLists.txt | 2 +- apps/openmw/mwlua/landbindings.cpp | 33 ++++++++++++++++-------------- files/lua_api/openmw/core.lua | 4 ++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd2309158b..7301496172 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 50) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 77) +set(OPENMW_LUA_API_REVISION 78) set(OPENMW_POSTPROCESSING_API_REVISION 2) set(OPENMW_VERSION_COMMITHASH "") diff --git a/apps/openmw/mwlua/landbindings.cpp b/apps/openmw/mwlua/landbindings.cpp index a4ebc0a841..3f85e2b066 100644 --- a/apps/openmw/mwlua/landbindings.cpp +++ b/apps/openmw/mwlua/landbindings.cpp @@ -1,15 +1,15 @@ #include "landbindings.hpp" -#include -#include -#include - +#include #include #include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" +#include "../mwworld/cellstore.hpp" #include "../mwworld/esmstore.hpp" +#include "../mwworld/worldmodel.hpp" +#include "object.hpp" namespace { @@ -37,15 +37,18 @@ namespace return { tex, plugin }; } - const ESM::RefId worldspaceAt(sol::object cellOrName) + const ESM::RefId worldspaceAt(sol::object cellOrId) { const MWWorld::Cell* cell = nullptr; - if (cellOrName.is()) - cell = cellOrName.as().mStore->getCell(); - else if (cellOrName.is()) - cell = cellOrName.as().mStore->getCell(); - else if (cellOrName.is() && !cellOrName.as().empty()) - cell = MWBase::Environment::get().getWorldModel()->getCell(cellOrName.as()).getCell(); + if (cellOrId.is()) + cell = cellOrId.as().mStore->getCell(); + else if (cellOrId.is()) + cell = cellOrId.as().mStore->getCell(); + else if (cellOrId.is() && !cellOrId.as().empty()) + cell = MWBase::Environment::get() + .getWorldModel() + ->getCell(ESM::RefId::deserializeText(cellOrId.as())) + .getCell(); if (cell == nullptr) throw std::runtime_error("Invalid cell"); else if (!cell->isExterior()) @@ -62,16 +65,16 @@ namespace MWLua sol::state_view lua = context.sol(); sol::table landApi(lua, sol::create); - landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) { - ESM::RefId worldspace = worldspaceAt(cellOrName); + landApi["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrId) { + ESM::RefId worldspace = worldspaceAt(cellOrId); return MWBase::Environment::get().getWorld()->getTerrainHeightAt(pos, worldspace); }; - landApi["getTextureAt"] = [lua = lua](const osg::Vec3f& pos, sol::object cellOrName) { + landApi["getTextureAt"] = [lua = lua](const osg::Vec3f& pos, sol::object cellOrId) { sol::variadic_results values; const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore(); const MWWorld::Store& landStore = store.get(); - ESM::RefId worldspace = worldspaceAt(cellOrName); + ESM::RefId worldspace = worldspaceAt(cellOrId); if (worldspace != ESM::Cell::sDefaultWorldspaceId) return values; diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index be9868a6f5..a2552fcd21 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -457,7 +457,7 @@ -- Get the terrain height at a given location. -- @function [parent=#Land] getHeightAt -- @param openmw.util#Vector3 position --- @param #any cellOrName (optional) cell or cell name in their exterior world space to query +-- @param #any cellOrId cell or cell id in their exterior world space to query -- @return #number --- @@ -467,7 +467,7 @@ -- -- @function [parent=#Land] getTextureAt -- @param openmw.util#Vector3 position --- @param #any cellOrName cell or cell name in their exterior world space to query +-- @param #any cellOrId cell or cell id in their exterior world space to query -- @return #nil, #string Texture path or nil if one isn't defined -- @return #nil, #string Plugin name or nil if failed to retrieve the texture