diff --git a/apps/openmw/mwlua/regionbindings.cpp b/apps/openmw/mwlua/regionbindings.cpp index be93e17168..b117d09570 100644 --- a/apps/openmw/mwlua/regionbindings.cpp +++ b/apps/openmw/mwlua/regionbindings.cpp @@ -2,6 +2,7 @@ #include "recordstore.hpp" #include +#include #include #include @@ -27,6 +28,10 @@ namespace sol { }; template <> + struct is_automagical : std::false_type + { + }; + template <> struct is_automagical> : std::false_type { }; @@ -39,6 +44,18 @@ namespace MWLua sol::state_view lua = context.sol(); sol::table regions(lua, sol::create); addRecordFunctionBinding(regions, context); + auto soundRefT = lua.new_usertype("ESM3_RegionSoundRef"); + + soundRefT[sol::meta_function::to_string] = [](const ESM::Region::SoundRef& ref) -> std::string { + return "ESM3_RegionSoundRef[" + ref.mSound.toDebugString() + "]"; + }; + soundRefT["soundId"] + = sol::readonly_property([](const ESM::Region::SoundRef& ref) { return ref.mSound.serializeText(); }); + + soundRefT["chance"] = sol::readonly_property([](const ESM::Region::SoundRef& ref) { return ref.mChance; }); + soundRefT["sound"] = sol::readonly_property([](const ESM::Region::SoundRef& ref) -> const ESM::Sound* { + return MWBase::Environment::get().getESMStore()->get().find(ref.mSound); + }); // Region record auto regionT = lua.new_usertype("ESM3_Region"); @@ -63,22 +80,12 @@ namespace MWLua } return res; }); - regionT["sounds"] = sol::readonly_property([lua = lua.lua_state()](const ESM::Region& rec) { sol::table res(lua, sol::create); for (const auto& soundRef : rec.mSoundList) - res.add(RegionSoundRef(soundRef)); + res.add(soundRef); return res; }); - - auto soundRefT = lua.new_usertype("ESM3_RegionSoundRef"); - soundRefT[sol::meta_function::to_string] = [](const RegionSoundRef& ref) -> std::string { - return "ESM3_RegionSoundRef[" + ref.mSoundId.toDebugString() + "]"; - }; - soundRefT["soundId"] - = sol::readonly_property([](const RegionSoundRef& ref) { return ref.mSoundId.serializeText(); }); - soundRefT["chance"] = sol::readonly_property([](const RegionSoundRef& ref) { return ref.mChance; }); - return LuaUtil::makeReadOnly(regions); } } diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 688a1d92ba..020eab6b86 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -1167,16 +1167,16 @@ -- @field [parent=#Regions] #list<#RegionRecord> records -- @usage local record = core.regions.records['bitter coast region'] -- @usage local record = core.regions.records[1] - --- -- Region data record -- @type RegionRecord -- @field #string id Region ID -- @field #string name Region display name -- @field openmw.util#Color mapColor Map color for this region. --- @field #string sleepList A list of leveled creature list used when sleeping outdoors in this region --- @field #list<#RegionSoundRef> sounds A read-only list of ambient sounds played randomly in this region --- @field #table weatherProbabilities A table mapping weather types to their probability (0–100), should sum to 100. +-- @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 (0–100), should sum to 100. -- Supports both numeric indices (1–10) and string keys: -- `"clear"`, `"cloudy"`, `"foggy"`, `"overcast"`, `"rain"`, `"thunder"`, `"ash"`, `"blight"`, `"snow"`, `"blizzard"` -- @usage print(region.weatherProbabilities[1]) -- access by index @@ -1186,7 +1186,8 @@ -- Region sound reference -- @type RegionSoundRef -- @field #string soundId Sound record ID --- @field #number chance Probability that this sound plays periodically in the region +-- @field #number chance Probability (0–100) that this sound plays periodically in the region +-- @field #Sound sound The full sound record referenced by `soundId`, or `nil` if not found --- @{#Factions}: Factions -- @field [parent=#core] #Factions factions