Lua bindings for sound functions

Just add Lua wrappers for existing MWScript API.

Note that MWSE-Lua has a similar API, but it also has events (addSound/addTempSound/soundObjectPlay) to detect when sounds are about to be played.

API usage examples:

local core = require('openmw.core');
local ambient = require('openmw.ambient');

-- Play a 3D sound with given parameters
local params = {
    timeOffset=0.1
    volume=0.3, 
    loop=false, 
    pitch=1.0
};
core.sound.playSound3d("shock bolt", target, params)
-- Play a 2D sound with given parameters
local params = {
    timeOffset=0.1
    volume=0.3, 
    scale=false, 
    pitch=1.0
};
ambient.playSound("shock bolt", params)
-- Check if given sound is playing
local isPlaying = core.sound.isSoundPlaying("shock bolt", target);
-- Stop sound
core.sound.stopSound("shock bolt", target);
-- Make target to say a voiced line. Lips movement will be used if available.
core.sound.say(target, "Sound\\Vo\\Misc\\tr_almgreet1.mp3", "Many Blessings upon you, my loyal servant.")
-- Make target to say a voiced line. Lips movement will be used if available. Also print a message box even if subtitles are disabled
core.sound.say(target, "Sound\\Vo\\Misc\\tr_almgreet1.mp3", "Many Blessings upon you, my loyal servant.", true)
-- The same, but without speaker
core.sound.say("Sound\\Vo\\Misc\\tr_almgreet1.mp3", "Many Blessings upon you, my loyal servant.", true)
-- Check if given objects says something
local active = core.sound.isSayActive(target);
-- Make target to shut up
core.sound.stopSay(target)
-- Play a 3D sound with given parameters
local params = {
    timeOffset=0.1, 
    volume=0.3, 
    loop=false, 
    pitch=1.0
};
core.sound.playSoundFile3d("Sound\\Vo\\Misc\\tr_almgreet1.mp3", target, params)
-- Play a 2D sound file with given parameters
local params = {
    timeOffset=0.1
    volume=0.3, 
    scale=false, 
    pitch=1.0
};
ambient.playSoundFile("Sound\\Vo\\Misc\\tr_almgreet1.mp3", params)
-- Check if given sound is playing
local isPlaying = core.sound.isSoundFilePlaying("Sound\\Vo\\Misc\\tr_almgreet1.mp3", target);
-- Stop sound
core.sound.stopFileSound("Sound\\Vo\\Misc\\tr_almgreet1.mp3", target);

New functions do not seem to require delayed actions - sound system uses queues, and animation update based on "say" state happens in the main thread when we run animations.

Any suggestions are welcome.

Edited by Andrei Kortunov

Merge request reports

Loading