pesde goatsoft / lucy

useUiSound

Lucy plays no audio of its own. Components report events when the player interacts with them (activate, toggle, open, close, select), and Lucy.useUiSound hooks those events to your game's sounds.

Usage

Lucy.useUiSound(app?, soundMap)
ArgumentTypeDefaultWhat it is
appLucy.App?Lucy.App.current()The App routing UI events
soundMaptablerequiredMap of event names to functions (or false)

Supported events

EventWhen it firesValue passed
activateA Button or Pressable is clickedNone
toggleA Switch or Checkbox changesboolean (new checked state)
openA Dialog or Sheet opensNone
closeA Dialog or Sheet closesNone
selectA choice is picked in RadioGroup, ToggleGroup, Select or TabsThe picked value

Scoping and silencing

  • Innermost scope wins: Lucy walks up from the component through its parent scopes and calls the first handler that names the event. Set default sounds on the scene, then override them inside a panel when needed.
  • false silences an event: { activate = false } stops button sounds during a busy rhythm minigame.
  • sound = false on a component: silences every event from that instance.
  • Errors stay contained: an error in a sound function warns in the output without breaking the click itself.

Example: audio feedback

Play sounds for clicks, switches, menus and selections:

Lucy.useUiSound(app, {
    activate = function(handle)
        sounds.clickThump:Play()
    end,
    toggle = function(handle, checked)
        if checked then
            sounds.switchOn:Play()
        else
            sounds.switchOff:Play()
        end
    end,
    open = function(handle)
        sounds.vinylScratch:Play()
    end,
    close = function(handle)
        sounds.vinylBackspin:Play()
    end,
    select = function(handle, trackValue)
        sounds.cueBeep:Play()
    end,
})