mirror of
https://github.com/OpenMW/openmw.git
synced 2026-01-02 16:33:30 +00:00
Add region sound binding
This commit is contained in:
parent
40f26a9495
commit
548fb5fecb
2 changed files with 24 additions and 16 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#include "recordstore.hpp"
|
||||
|
||||
#include <components/esm3/loadregn.hpp>
|
||||
#include <components/esm3/loadsoun.hpp>
|
||||
#include <components/lua/luastate.hpp>
|
||||
#include <components/misc/color.hpp>
|
||||
|
||||
|
|
@ -27,6 +28,10 @@ namespace sol
|
|||
{
|
||||
};
|
||||
template <>
|
||||
struct is_automagical<ESM::Region::SoundRef> : std::false_type
|
||||
{
|
||||
};
|
||||
template <>
|
||||
struct is_automagical<MWWorld::Store<RegionSoundRef>> : std::false_type
|
||||
{
|
||||
};
|
||||
|
|
@ -39,6 +44,18 @@ namespace MWLua
|
|||
sol::state_view lua = context.sol();
|
||||
sol::table regions(lua, sol::create);
|
||||
addRecordFunctionBinding<ESM::Region>(regions, context);
|
||||
auto soundRefT = lua.new_usertype<ESM::Region::SoundRef>("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<ESM::Sound>().find(ref.mSound);
|
||||
});
|
||||
|
||||
// Region record
|
||||
auto regionT = lua.new_usertype<ESM::Region>("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<RegionSoundRef>("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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue