pesde goatsoft / lucy

Getting started

Lucy is a UI and app framework for Roblox, built on Universal Styling. It gives you themeable components, scenes and one app state, and works with mouse, keyboard, gamepad and touch on desktop, console, tablet and phone.

Install

Components are copied into your project as source you own. You need Lune and a checkout of Lucy.

git clone https://github.com/goatsoft/lucy ~/Projects/Lucy
cd your-game
lune run ~/Projects/Lucy/scripts/add -- button dialog --from ~/Projects/Lucy --out src/shared/Lucy
  • Core is always copied; dependencies come along (Dialog brings Button).
  • Files you have edited are kept unless you pass --overwrite.
  • --list shows every component, --all installs them all, --specs copies the tests too.

pesde

pesde add goatsoft/lucy
pesde install

Forest

forest install goatsoft/lucy

Create the App

Create one App on the client. It owns the state, theme, input, scenes and toasts.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lucy = require(ReplicatedStorage.Shared.Lucy) -- or ReplicatedStorage.Packages.Lucy

local app = Lucy.App.new({
    theme = "dark",
    baseColor = "zinc",
    primary = "violet",
    state = { player = { coins = 0 } },
})

Every option, and everything an App holds, is listed in The app.

Make it once, in one client script. Components you create use this App without being told, and other scripts reach it with Lucy.App.current():

local app = Lucy.App.current() -- the App, or nil if UI.client hasn't made it yet

Lucy.App.current() is nil until that script has run, so a script that may start first should wait for it, or get the App from a ModuleScript that makes it and returns it.

For typed code, Lucy exports its types: Lucy.App, Lucy.Scene, Lucy.Handle (any component), Lucy.Ref<T> and more. A scene and a handle both take your own fields, such as scene.play.

Build a scene

Each scene owns one ScreenGui. Only one screen shows at a time; modals and overlays sit above it. This title screen has a "Hit the floor" button that switches to the game screen:

Getting started exampleGetting started example
app.scenes:register("Title", {
    build = function(scene)
        scene.play = Lucy.Button.new({
            text = "Hit the floor",
            size = "lg",
            onClick = function()
                app.scenes:goTo("Game")
            end,
        })
        Lucy.Stack.new({
            size = UDim2.fromScale(1, 1),
            align = "center",
            justify = "center",
            gap = "Space4",
            children = {
                Lucy.Text.new({ text = "Club Lucy", variant = "h1", align = "center" }),
                scene.play,
            },
            Parent = scene.gui,
        })
    end,
    -- What keyboard and gamepad players start on.
    defaultFocus = function(scene)
        return scene.play
    end,
})

local coins = app.state:ref("player.coins")

app.scenes:register("Game", {
    build = function(scene)
        Lucy.Text.new({
            text = function()
                return `Coins: {coins()}`
            end,
            Parent = scene.gui,
        })
    end,
})

app.scenes:goTo("Title")

The coins text reads app state, so it changes by itself when the game sets player.coins. For more, see Build screens with scenes, and the Recipes for whole screens to copy: a settings menu that saves, a pause menu, a HUD and a shop.

Drive anything from app state

app.state:set("ui.leave.open", true)          -- any component, by id
app.state:set("theme", "light")               -- switch theme
app.state:set("scenes.current", "Game")       -- navigate
app.state:subscribe("input.device", print)    -- "desktop" | "console" | "tablet" | "mobile"

Dialogs and toasts

Getting started exampleGetting started example
local leave = Lucy.Dialog.new({
    id = "leave",
    title = "Leave the club?",
    description = "Your combo will reset.",
    actions = {
        { text = "Keep dancing", variant = "outline" },
        { text = "Leave", variant = "destructive", onClick = leaveClub },
    },
})
leave:open() -- or app.state:set("ui.leave.open", true)

app.toast.success("Dance-off won", { description = "+250 coins" })

Next

The basics, in order:

  1. Build screens with scenes: screens, a HUD, menus on top, and back
  2. Work with app state: your game's data, read, written and shown
  3. Hotkeys and modal input: keys and buttons for every device, and menus that pause gameplay keys

Then build out your game:

When you need more, Go further covers your own components and composables, stories and agents, and the Reference lists everything on Lucy.