diff --git a/apps/openmw/mwbase/soundmanager.hpp b/apps/openmw/mwbase/soundmanager.hpp index 85062ace8d..1f0337869b 100644 --- a/apps/openmw/mwbase/soundmanager.hpp +++ b/apps/openmw/mwbase/soundmanager.hpp @@ -109,6 +109,9 @@ namespace MWBase virtual void processChangedSettings(const std::set>& settings) = 0; + virtual bool isEnabled() const = 0; + ///< Returns true if sound system is enabled + virtual void stopMusic() = 0; ///< Stops music if it's playing diff --git a/apps/openmw/mwlua/soundbindings.cpp b/apps/openmw/mwlua/soundbindings.cpp index 102f88ce61..dc45a672b4 100644 --- a/apps/openmw/mwlua/soundbindings.cpp +++ b/apps/openmw/mwlua/soundbindings.cpp @@ -112,6 +112,8 @@ namespace MWLua sol::state_view& lua = context.mLua->sol(); sol::table api(lua, sol::create); + api["isEnabled"] = []() { return MWBase::Environment::get().getSoundManager()->isEnabled(); }; + api["playSound3d"] = [](std::string_view soundId, const Object& object, const sol::optional& options) { auto args = getPlaySoundArgs(options); diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 87fb109791..94d407c11b 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -173,6 +173,9 @@ namespace MWSound void processChangedSettings(const Settings::CategorySettingVector& settings) override; + bool isEnabled() const override { return mOutput->isInitialized(); } + ///< Returns true if sound system is enabled + void stopMusic() override; ///< Stops music if it's playing diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index af09274981..a6e9cb361c 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -749,6 +749,13 @@ --- @{#Sound}: Sounds and Speech -- @field [parent=#core] #Sound sound +--- +-- Checks if sound system is enabled (any functions to play sounds are no-ops when it is disabled). +-- It can not be enabled or disabled during runtime. +-- @function [parent=#Sound] isEnabled +-- @return #boolean +-- @usage local enabled = core.sound.isEnabled(); + --- -- Play a 3D sound, attached to object -- @function [parent=#Sound] playSound3d