Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Movie Theater Controller (Basalt2, monitor-safe, no Unicode)
- -- Behavior:
- -- Play -> rs.setOutput("right", false) -- lights OFF, video plays
- -- Pause -> rs.setOutput("right", true) -- lights ON, video pauses
- local basalt = require("basalt")
- -- ===== Monitor setup =========================================================
- local monitor = peripheral.find("monitor")
- if not monitor then error("No monitor found. Attach one and try again.") end
- -- Use a scale that most monitors can handle; 1.0 is readable and predictable.
- monitor.setTextScale(1.0)
- -- Create a UI frame bound to the monitor (Basaltic pattern).
- local ui = basalt.createFrame():setTerm(monitor)
- -- Read size AFTER setting text scale; Basalt positions/sizes use these coords.
- local W, H = monitor.getSize()
- -- ===== Theme (ComputerCraft 16-color palette) ================================
- local COL_BG = colors.black
- local COL_PANEL = colors.gray
- local COL_TEXT = colors.white
- local COL_OK = colors.lime
- local COL_ERR = colors.red
- local COL_DIM = colors.lightGray
- -- Full-screen background
- ui:setBackground(COL_BG):setForeground(COL_TEXT):setSize(W, H)
- -- ===== Title bar (keep it simple and tall enough) ============================
- local topBar = ui:addFrame()
- :setPosition(1, 1)
- :setSize(W, 4) -- Big enough to avoid clipping
- :setBackground(COL_PANEL)
- :setForeground(COL_TEXT)
- topBar:addLabel()
- :setPosition(2, 2)
- :setText("THEATER 1")
- topBar:addLabel()
- :setPosition(2, 3)
- :setText("Now Playing: Blue Harvest")
- -- Divider line under the bar
- ui:addLabel()
- :setPosition(1, 5)
- :setText(string.rep("~", W))
- :setForeground(COL_DIM)
- -- ===== Status area ===========================================================
- local statusFrame = ui:addFrame()
- :setPosition(2, 6)
- :setSize(W - 2, 4)
- :setBackground(COL_BG)
- :setForeground(COL_TEXT)
- statusFrame:addLabel()
- :setPosition(1, 1)
- :setText("Status:")
- :setForeground(COL_DIM)
- local statusText = statusFrame:addLabel()
- :setPosition(10, 1)
- :setText("Paused (lights ON)")
- :setForeground(COL_ERR)
- -- “LED” indicator (two-space label with background color)
- local led = statusFrame:addLabel()
- :setPosition(1, 2)
- :setText(" ")
- :setBackground(COL_ERR)
- :setForeground(COL_ERR)
- statusFrame:addLabel()
- :setPosition(4, 2)
- :setText("Lights")
- :setForeground(COL_DIM)
- -- ===== Behavior helper =======================================================
- --- Apply UI + redstone for play/pause.
- --- @param isPlaying boolean
- local function applyState(isPlaying)
- rs.setOutput("right", not isPlaying) -- hardware truth table
- if isPlaying then
- statusText:setText("Playing (lights OFF)"):setForeground(COL_OK)
- led:setBackground(COL_OK):setForeground(COL_OK)
- else
- statusText:setText("Paused (lights ON)"):setForeground(COL_ERR)
- led:setBackground(COL_ERR):setForeground(COL_ERR)
- end
- end
- -- ===== Controls ==============================================================
- local btns = ui:addFrame()
- :setPosition(2, 11)
- :setSize(W - 4, 5)
- :setBackground(COL_BG)
- :setForeground(COL_TEXT)
- -- Compute half-widths once (leave 1 col gap between buttons)
- local half = math.floor((btns:getSize() - 1) / 2)
- -- PLAY button (ASCII-only text)
- local playBtn = btns:addButton()
- :setPosition(1, 1)
- :setSize(half, 3)
- :setBackground(COL_OK)
- :setForeground(COL_BG)
- :setText("[>] Play")
- :onClick(function() applyState(true) end)
- -- PAUSE button (no Unicode)
- btns:addButton()
- :setPosition(half + 2, 1) -- +1 gap, +1 for 1-based coords
- :setSize(half, 3)
- :setBackground(COL_ERR)
- :setForeground(COL_BG)
- :setText("[||] Pause")
- :onClick(function() applyState(false) end)
- -- Footer hint (constrain width so it doesn't trail off-screen)
- ui:addLabel()
- :setPosition(2, H)
- :setSize(W - 2, 1)
- :setForeground(COL_DIM)
- :setText("Tip: Add a projector peripheral later; these buttons only drive redstone.")
- -- Initialize to a known safe state
- applyState(false)
- -- Start Basalt event loop
- basalt.run()
Advertisement
Add Comment
Please, Sign In to add comment