1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-16 20:46:34 +00:00

Don't hardcode weather ids

This commit is contained in:
SkyHasACat 2025-08-03 12:46:50 -07:00 committed by Evil Eye
parent fe48e2c9ae
commit 1b5450557e
2 changed files with 7 additions and 7 deletions

View file

@ -6,6 +6,8 @@
#include <components/lua/luastate.hpp>
#include <components/misc/color.hpp>
#include "../mwworld/weather.hpp"
namespace sol
{
template <>
@ -47,14 +49,12 @@ namespace MWLua
= sol::readonly_property([](const ESM::Region& rec) { return LuaUtil::serializeRefId(rec.mSleepList); });
regionT["weatherProbabilities"] = sol::readonly_property([lua = lua.lua_state()](const ESM::Region& rec) {
constexpr std::array<const char*, 10> WeatherNames
= { "clear", "cloudy", "foggy", "overcast", "rain", "thunder", "ash", "blight", "snow", "blizzard" };
sol::table res(lua, sol::create);
for (size_t i = 0; i < rec.mData.mProbabilities.size(); ++i)
{
res[LuaUtil::toLuaIndex(i)] = rec.mData.mProbabilities[i];
res[WeatherNames[i]] = rec.mData.mProbabilities[i];
const MWWorld::Weather* weather = MWBase::Environment::get().getWorld()->getWeather(i);
res[weather->mId.serializeText()] = rec.mData.mProbabilities[i];
}
return res;
});

View file

@ -1176,11 +1176,11 @@
-- @field #string sleepList A leveled creature list used when sleeping outdoors in this region
-- @field #list<#RegionSoundRef> sounds A read-only list of ambient sound references for this region.
-- Each reference includes a chance and a resolved link to the full sound record.
-- @field #table weatherProbabilities A table mapping weather types to their probability (0100), should sum to 100.
-- Supports both numeric indices (110) and string keys:
-- @field #table weatherProbabilities A table mapping weather ids to their probability (0100), should sum to 100.
-- Supports both numeric indices (110) and ids, for example:
-- `"clear"`, `"cloudy"`, `"foggy"`, `"overcast"`, `"rain"`, `"thunder"`, `"ash"`, `"blight"`, `"snow"`, `"blizzard"`
-- @usage print(region.weatherProbabilities[1]) -- access by index
-- @usage print(region.weatherProbabilities["rain"]) -- access by name
-- @usage print(region.weatherProbabilities["rain"]) -- access by id
---
-- Region sound reference