mirror of
https://github.com/OpenMW/openmw.git
synced 2025-10-17 07:46:40 +00:00
Don't hardcode weather ids
This commit is contained in:
parent
fe48e2c9ae
commit
1b5450557e
2 changed files with 7 additions and 7 deletions
|
@ -6,6 +6,8 @@
|
||||||
#include <components/lua/luastate.hpp>
|
#include <components/lua/luastate.hpp>
|
||||||
#include <components/misc/color.hpp>
|
#include <components/misc/color.hpp>
|
||||||
|
|
||||||
|
#include "../mwworld/weather.hpp"
|
||||||
|
|
||||||
namespace sol
|
namespace sol
|
||||||
{
|
{
|
||||||
template <>
|
template <>
|
||||||
|
@ -47,14 +49,12 @@ namespace MWLua
|
||||||
= sol::readonly_property([](const ESM::Region& rec) { return LuaUtil::serializeRefId(rec.mSleepList); });
|
= 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) {
|
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);
|
sol::table res(lua, sol::create);
|
||||||
for (size_t i = 0; i < rec.mData.mProbabilities.size(); ++i)
|
for (size_t i = 0; i < rec.mData.mProbabilities.size(); ++i)
|
||||||
{
|
{
|
||||||
res[LuaUtil::toLuaIndex(i)] = rec.mData.mProbabilities[i];
|
const MWWorld::Weather* weather = MWBase::Environment::get().getWorld()->getWeather(i);
|
||||||
res[WeatherNames[i]] = rec.mData.mProbabilities[i];
|
res[weather->mId.serializeText()] = rec.mData.mProbabilities[i];
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1176,11 +1176,11 @@
|
||||||
-- @field #string sleepList A leveled creature list used when sleeping outdoors in this region
|
-- @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.
|
-- @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.
|
-- 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 (0–100), should sum to 100.
|
-- @field #table weatherProbabilities A table mapping weather ids to their probability (0–100), should sum to 100.
|
||||||
-- Supports both numeric indices (1–10) and string keys:
|
-- Supports both numeric indices (1–10) and ids, for example:
|
||||||
-- `"clear"`, `"cloudy"`, `"foggy"`, `"overcast"`, `"rain"`, `"thunder"`, `"ash"`, `"blight"`, `"snow"`, `"blizzard"`
|
-- `"clear"`, `"cloudy"`, `"foggy"`, `"overcast"`, `"rain"`, `"thunder"`, `"ash"`, `"blight"`, `"snow"`, `"blizzard"`
|
||||||
-- @usage print(region.weatherProbabilities[1]) -- access by index
|
-- @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
|
-- Region sound reference
|
||||||
|
|
Loading…
Reference in a new issue