darmod

Untitled

Aug 3rd, 2025 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.07 KB | None | 0 0
  1. -- Movie Theater Controller (Basalt2, monitor-safe, no Unicode)
  2. -- Behavior:
  3. --   Play  -> rs.setOutput("right", false)  -- lights OFF, video plays
  4. --   Pause -> rs.setOutput("right", true)   -- lights ON, video pauses
  5.  
  6. local basalt = require("basalt")
  7.  
  8. -- ===== Monitor setup =========================================================
  9. local monitor = peripheral.find("monitor")
  10. if not monitor then error("No monitor found. Attach one and try again.") end
  11.  
  12. -- Use a scale that most monitors can handle; 1.0 is readable and predictable.
  13. monitor.setTextScale(1.0)
  14.  
  15. -- Create a UI frame bound to the monitor (Basaltic pattern).
  16. local ui = basalt.createFrame():setTerm(monitor)
  17.  
  18. -- Read size AFTER setting text scale; Basalt positions/sizes use these coords.
  19. local W, H = monitor.getSize()
  20.  
  21. -- ===== Theme (ComputerCraft 16-color palette) ================================
  22. local COL_BG    = colors.black
  23. local COL_PANEL = colors.gray
  24. local COL_TEXT  = colors.white
  25. local COL_OK    = colors.lime
  26. local COL_ERR   = colors.red
  27. local COL_DIM   = colors.lightGray
  28.  
  29. -- Full-screen background
  30. ui:setBackground(COL_BG):setForeground(COL_TEXT):setSize(W, H)
  31.  
  32. -- ===== Title bar (keep it simple and tall enough) ============================
  33. local topBar = ui:addFrame()
  34.   :setPosition(1, 1)
  35.   :setSize(W, 4)                  -- Big enough to avoid clipping
  36.   :setBackground(COL_PANEL)
  37.   :setForeground(COL_TEXT)
  38.  
  39. topBar:addLabel()
  40.   :setPosition(2, 2)
  41.   :setText("THEATER 1")
  42.  
  43. topBar:addLabel()
  44.   :setPosition(2, 3)
  45.   :setText("Now Playing: Blue Harvest")
  46.  
  47. -- Divider line under the bar
  48. ui:addLabel()
  49.   :setPosition(1, 5)
  50.   :setText(string.rep("~", W))
  51.   :setForeground(COL_DIM)
  52.  
  53. -- ===== Status area ===========================================================
  54. local statusFrame = ui:addFrame()
  55.   :setPosition(2, 6)
  56.   :setSize(W - 2, 4)
  57.   :setBackground(COL_BG)
  58.   :setForeground(COL_TEXT)
  59.  
  60. statusFrame:addLabel()
  61.   :setPosition(1, 1)
  62.   :setText("Status:")
  63.   :setForeground(COL_DIM)
  64.  
  65. local statusText = statusFrame:addLabel()
  66.   :setPosition(10, 1)
  67.   :setText("Paused (lights ON)")
  68.   :setForeground(COL_ERR)
  69.  
  70. -- “LED” indicator (two-space label with background color)
  71. local led = statusFrame:addLabel()
  72.   :setPosition(1, 2)
  73.   :setText("  ")
  74.   :setBackground(COL_ERR)
  75.   :setForeground(COL_ERR)
  76.  
  77. statusFrame:addLabel()
  78.   :setPosition(4, 2)
  79.   :setText("Lights")
  80.   :setForeground(COL_DIM)
  81.  
  82. -- ===== Behavior helper =======================================================
  83. --- Apply UI + redstone for play/pause.
  84. --- @param isPlaying boolean
  85. local function applyState(isPlaying)
  86.   rs.setOutput("right", not isPlaying)  -- hardware truth table
  87.  
  88.   if isPlaying then
  89.     statusText:setText("Playing (lights OFF)"):setForeground(COL_OK)
  90.     led:setBackground(COL_OK):setForeground(COL_OK)
  91.   else
  92.     statusText:setText("Paused (lights ON)"):setForeground(COL_ERR)
  93.     led:setBackground(COL_ERR):setForeground(COL_ERR)
  94.   end
  95. end
  96.  
  97. -- ===== Controls ==============================================================
  98. local btns = ui:addFrame()
  99.   :setPosition(2, 11)
  100.   :setSize(W - 4, 5)
  101.   :setBackground(COL_BG)
  102.   :setForeground(COL_TEXT)
  103.  
  104. -- Compute half-widths once (leave 1 col gap between buttons)
  105. local half = math.floor((btns:getSize() - 1) / 2)
  106.  
  107. -- PLAY button (ASCII-only text)
  108. local playBtn = btns:addButton()
  109.   :setPosition(1, 1)
  110.   :setSize(half, 3)
  111.   :setBackground(COL_OK)
  112.   :setForeground(COL_BG)
  113.   :setText("[>]  Play")
  114.   :onClick(function() applyState(true) end)
  115.  
  116. -- PAUSE button (no Unicode)
  117. btns:addButton()
  118.   :setPosition(half + 2, 1)      -- +1 gap, +1 for 1-based coords
  119.   :setSize(half, 3)
  120.   :setBackground(COL_ERR)
  121.   :setForeground(COL_BG)
  122.   :setText("[||] Pause")
  123.   :onClick(function() applyState(false) end)
  124.  
  125. -- Footer hint (constrain width so it doesn't trail off-screen)
  126. ui:addLabel()
  127.   :setPosition(2, H)
  128.   :setSize(W - 2, 1)
  129.   :setForeground(COL_DIM)
  130.   :setText("Tip: Add a projector peripheral later; these buttons only drive redstone.")
  131.  
  132. -- Initialize to a known safe state
  133. applyState(false)
  134.  
  135. -- Start Basalt event loop
  136. basalt.run()
  137.  
Advertisement
Add Comment
Please, Sign In to add comment