Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to toggle sound effects #568

Merged
merged 2 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin/src/App/Notifications.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ local bindingUtil = require(script.Parent.bindingUtil)

local Theme = require(Plugin.App.Theme)
local Assets = require(Plugin.Assets)
local playSound = require(Plugin.playSound)

local BorderedContainer = require(Plugin.App.Components.BorderedContainer)

Expand Down Expand Up @@ -53,7 +52,7 @@ function Notification:didMount()
})
)

playSound(Assets.Sounds.Notification)
self.props.soundPlayer:play(Assets.Sounds.Notification)

self.timeout = task.spawn(function()
local clock = os.clock()
Expand Down Expand Up @@ -182,6 +181,7 @@ function Notifications:render()

for index, notif in ipairs(self.props.notifications) do
notifs[notif] = e(Notification, {
soundPlayer = self.props.soundPlayer,
text = notif.text,
timestamp = notif.timestamp,
timeout = notif.timeout,
Expand Down
1 change: 1 addition & 0 deletions plugin/src/App/PluginSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local defaultSettings = {
openScriptsExternally = false,
twoWaySync = false,
showNotifications = true,
playSounds = true,
}

local Settings = {}
Expand Down
10 changes: 9 additions & 1 deletion plugin/src/App/StatusPages/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,20 @@ function SettingsPage:render()
layoutOrder = 2,
}),

PlaySounds = e(Setting, {
id = "playSounds",
name = "Play Sounds",
description = "Toggle sound effects",
transparency = self.props.transparency,
layoutOrder = 3,
}),

TwoWaySync = e(Setting, {
id = "twoWaySync",
name = "Two-Way Sync",
description = "EXPERIMENTAL! Editing files in Studio will sync them into the filesystem",
transparency = self.props.transparency,
layoutOrder = 3,
layoutOrder = 4,
}),

Layout = e("UIListLayout", {
Expand Down
7 changes: 5 additions & 2 deletions plugin/src/App/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local Dictionary = require(Plugin.Dictionary)
local ServeSession = require(Plugin.ServeSession)
local ApiContext = require(Plugin.ApiContext)
local preloadAssets = require(Plugin.preloadAssets)
local soundPlayer = require(Plugin.soundPlayer)
local Theme = require(script.Theme)
local PluginSettings = require(script.PluginSettings)

Expand Down Expand Up @@ -272,6 +273,7 @@ function App:render()
Padding = UDim.new(0, 5),
}),
notifs = e(Notifications, {
soundPlayer = self.props.soundPlayer,
notifications = self.state.notifications,
onClose = function(index)
self:closeNotification(index)
Expand Down Expand Up @@ -347,10 +349,11 @@ return function(props)
plugin = props.plugin,
}, {
App = PluginSettings.with(function(settings)
local settingsProps = Dictionary.merge(props, {
local mergedProps = Dictionary.merge(props, {
settings = settings,
soundPlayer = soundPlayer.new(settings),
})
return e(App, settingsProps)
return e(App, mergedProps)
end),
})
end
17 changes: 15 additions & 2 deletions plugin/src/playSound.lua → plugin/src/soundPlayer.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Roblox decided that sounds only play in Edit mode when parented to a plugin widget, for some reason
-- Sounds only play in Edit mode when parented to a plugin widget, for some reason
local plugin = plugin or script:FindFirstAncestorWhichIsA("Plugin")
local widget = plugin:CreateDockWidgetPluginGui("Rojo_soundPlayer", DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float,
Expand All @@ -9,7 +9,18 @@ local widget = plugin:CreateDockWidgetPluginGui("Rojo_soundPlayer", DockWidgetPl
widget.Name = "Rojo_soundPlayer"
widget.Title = "Rojo Sound Player"

return function(soundId)
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
Expand All @@ -20,3 +31,5 @@ return function(soundId)

sound:Play()
end

return SoundPlayer