diff --git a/apps/openmw/mwlua/weatherbindings.cpp b/apps/openmw/mwlua/weatherbindings.cpp index 975b650d79..1d813a2b92 100644 --- a/apps/openmw/mwlua/weatherbindings.cpp +++ b/apps/openmw/mwlua/weatherbindings.cpp @@ -42,25 +42,25 @@ namespace } template - bool hasWeather(const Cell& cell) + bool hasWeather(const Cell& cell, bool requireExterior) { - if (!cell.mStore->isQuasiExterior() && !cell.mStore->isExterior()) + if (requireExterior && !cell.mStore->isQuasiExterior() && !cell.mStore->isExterior()) return false; return MWBase::Environment::get().getWorldScene()->isCellActive(*cell.mStore); } template - auto overloadForActiveCell(const Getter&& getter) + auto overloadForActiveCell(Getter&& getter, bool requireExterior = true) { using Result = std::invoke_result_t; return sol::overload( [=](const MWLua::GCell& cell) -> Result { - if (!hasWeather(cell)) + if (!hasWeather(cell, requireExterior)) return Result{}; return getter(); }, [=](const MWLua::LCell& cell) -> Result { - if (!hasWeather(cell)) + if (!hasWeather(cell, requireExterior)) return Result{}; return getter(); }); @@ -210,14 +210,16 @@ namespace MWLua api["getNext"] = overloadForActiveCell( []() -> const MWWorld::Weather* { return MWBase::Environment::get().getWorld()->getNextWeather(); }); api["getTransition"] = overloadWeatherGetter(&MWBase::World::getWeatherTransition); - api["getCurrentSunLightDirection"] = overloadForActiveCell([]() -> std::optional { - osg::Vec4f sunPos = MWBase::Environment::get().getWorld()->getSunLightPosition(); - // normalize to get the direction towards the sun - sunPos.normalize(); + api["getCurrentSunLightDirection"] = overloadForActiveCell( + []() -> std::optional { + osg::Vec4f sunPos = MWBase::Environment::get().getWorld()->getSunLightPosition(); + // normalize to get the direction towards the sun + sunPos.normalize(); - // and invert it to get the direction of the sun light - return -sunPos; - }); + // and invert it to get the direction of the sun light + return -sunPos; + }, + false); api["getCurrentSunVisibility"] = overloadWeatherGetter(&MWBase::World::getSunVisibility); api["getCurrentSunPercentage"] = overloadWeatherGetter(&MWBase::World::getSunPercentage); api["getCurrentWindSpeed"] = overloadWeatherGetter(&MWBase::World::getWindSpeed); diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 4457c7c0e8..25db0e57b5 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -1275,7 +1275,7 @@ -- Get the current direction of the light of the sun. -- @function [parent=#Weather] getCurrentSunLightDirection -- @param #Cell The cell to get the sun direction for --- @return openmw.util#Vector4 or nil if the cell is inactive or has no weather +-- @return openmw.util#Vector4 or nil if the cell is inactive --- -- Get the current sun visibility taking weather transition into account.