forked from rojo-rbx/rojo
Uses Stylua to format all existing Lua files, and adds a CI check in `lint` to pin this improvement. Excludes formatting dependencies, of course.
39 lines
877 B
Lua
39 lines
877 B
Lua
-- Sounds only play in Edit mode when parented to a plugin widget, for some reason
|
|
local plugin = plugin or script:FindFirstAncestorWhichIsA("Plugin")
|
|
local widget = nil
|
|
if plugin then
|
|
widget = plugin:CreateDockWidgetPluginGui(
|
|
"Rojo_soundPlayer",
|
|
DockWidgetPluginGuiInfo.new(Enum.InitialDockState.Float, false, true, 10, 10, 10, 10)
|
|
)
|
|
widget.Name = "Rojo_soundPlayer"
|
|
widget.Title = "Rojo Sound Player"
|
|
end
|
|
|
|
local SoundPlayer = {}
|
|
SoundPlayer.__index = SoundPlayer
|
|
|
|
function SoundPlayer.new(settings)
|
|
return setmetatable({
|
|
settings = settings,
|
|
}, SoundPlayer)
|
|
end
|
|
|
|
function SoundPlayer:play(soundId)
|
|
if self.settings and self.settings:get("playSounds") == false then
|
|
return
|
|
end
|
|
|
|
local sound = Instance.new("Sound")
|
|
sound.SoundId = soundId
|
|
sound.Parent = widget
|
|
|
|
sound.Ended:Connect(function()
|
|
sound:Destroy()
|
|
end)
|
|
|
|
sound:Play()
|
|
end
|
|
|
|
return SoundPlayer
|