mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Add sounds module (#1413)
This commit is contained in:
parent
850c48bd39
commit
da4e31284c
54
utils/sounds.lua
Normal file
54
utils/sounds.lua
Normal file
@ -0,0 +1,54 @@
|
||||
local default_sound_path = 'utility/console_message'
|
||||
|
||||
local Sounds = {}
|
||||
|
||||
local function play(players, sound_path)
|
||||
local sound = sound_path or default_sound_path
|
||||
if not game.is_valid_sound_path(sound) then
|
||||
error('Invalid sound path ' .. sound_path)
|
||||
return
|
||||
end
|
||||
for _, player in pairs(players) do
|
||||
if player and player.valid then
|
||||
player.play_sound{ path = sound, volume_modifier = 1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param player LuaPlayer
|
||||
---@param sound_path string
|
||||
Sounds.notify_player = function(player, sound_path)
|
||||
play({player}, sound_path)
|
||||
end
|
||||
|
||||
---@param player LuaForce
|
||||
---@param sound_path string
|
||||
Sounds.notify_force = function(force, sound_path)
|
||||
play(force.connected_players, sound_path)
|
||||
end
|
||||
|
||||
---@param sound_path string
|
||||
Sounds.notify_admins = function(sound_path)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.admin then
|
||||
play({player}, sound_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param player LuaForce
|
||||
---@param sound_path string
|
||||
Sounds.notify_allies = function(force, sound_path)
|
||||
for _, f in pairs(game.forces) do
|
||||
if (f.index == force.index) or f.is_friend(force) then
|
||||
play(f.connected_players, sound_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param sound_path string
|
||||
Sounds.notify_all = function(sound_path)
|
||||
play(game.connected_players, sound_path)
|
||||
end
|
||||
|
||||
return Sounds
|
Loading…
Reference in New Issue
Block a user