April_The_Sergal

test basalt code for ccTweaked

Jan 9th, 2025 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by cdbab.
  4. --- DateTime: 1/9/2025 7:11 AM
  5. ---
  6. ---
  7. print("running node")
  8. local basalt = require("basalt")
  9. local subnetStatusText = ""
  10. local sunbnetStatusColor = colors.red
  11. peripheral.find("modem", rednet.open)
  12. local delay = 120
  13. local authCode = 1111
  14. local subnetStatus = false
  15. local commAttempts = 0
  16. local maxCommAttempts = 5
  17. local cmdType = {AUTH = "authCode", CMD = "command", VAR = "var", ARG = "args"}
  18.  
  19. local root = basalt.createFrame():setTheme({ButtonBG=colors.cyan, ButtonText=colors.white, FrameBG = colors.lightGray, FrameFG = colors.black})
  20. local timer = root:addTimer()
  21. local delayPanel = root:addFrame():setPosition(2,2):setSize("parent.w - 3", "parent.h / 2 - 3"):setBorder(colors.black)
  22. local debugPanel = root:addFrame():setPosition(2,"parent.h / 2 + 1"):setSize("parent.w - 3", "parent.h / 2 - 3"):setBorder(colors.black)
  23. local delayControl = delayPanel:addFrame():setPosition(2,2):setSize("parent.w - 2",5):setForeground(colors.black):setBorder(colors.white)
  24. local delaySetButton = delayControl:addButton():setText("Set Delay"):setVerticalAlign("center"):setHorizontalAlign("center"):setSize(11,1):setPosition("parent.w / 2 - 5", "parent.h - 1")
  25. local timeInput = delayControl:addInput():setInputType("number"):setDefaultText(tostring(delay)):setInputLimit(3):setSize(11,1):setPosition("parent.w / 2 - 5",2)
  26. local subnetControl = debugPanel:addFrame():setPosition(2,2):setSize("parent.w - 2",5):setForeground(colors.black):setBorder(colors.white)
  27. if subnetStatus then
  28.     subnetStatusText = "Online"
  29.     sunbnetStatusColor = colors.gray
  30. else
  31.     subnetStatusText = "Offline"
  32.     sunbnetStatusColor = colors.green
  33. end
  34.  
  35. local subnetStatusTitleLabel = subnetControl:addLabel():setText("Subnet Status: "):setSize(15, 1):setPosition("parent.w / 2 - 6",2)
  36. local subnetStatusLabel = subnetControl:addLabel():setText(subnetStatusText):setSize(#subnetStatusText, 1):setPosition("parent.w / 2 - 3",3)
  37. local subnetToggleButton = subnetControl:addButton():setText("Start Subnet"):setSize(14,1):setBackground(sunbnetStatusColor):setPosition("parent.w / 2 - 6",4)
  38.  
  39.  
  40. local function fetchMsg()
  41.     print("receiving message")
  42.     local id, message = rednet.receive(nil, 5)
  43.     if message == nil then
  44.         error("Message received but was empty.",0)
  45.     end
  46.     if message[cmdType.AUTH] == authCode and  message[cmdType.CMD] == "var" then
  47.         return message[cmdType.ARG][1]
  48.     else
  49.         return false
  50.     end
  51. end
  52.  
  53. local function sendMsg(cmd, ...)
  54.     local arg={...}
  55.     commAttempts = commAttempts + 1
  56.     if comAttempts == maxCommAttempts then
  57.         error("Cannot communicate with controller. Controller might not be online")
  58.         return
  59.     end
  60.     print("sending message")
  61.     local response
  62.     local msg = {}
  63.     msg["authCode"] = authCode
  64.     msg["command"] = cmd
  65.     if #arg > 0 then
  66.         msg["args"] = arg
  67.     end
  68.     rednet.broadcast(msg)
  69.     response = fetchMsg()
  70.     if response == false then
  71.         sendMsg(cmd, ...)
  72.     end
  73.     return response
  74. end
  75.  
  76. local function fetchInfo()
  77.     -- add your logic here
  78.     basalt.debug("Requesting Status!")
  79.     subnetStatus = sendMsg("getSubnetStatus")
  80.     delay = sendMsg("getDelay")
  81.     timeInput:setDefaultText(tostring(delay))
  82. end
  83.  
  84. timer:onCall(fetchInfo())
  85.      :setTime(1, -1)
  86.      :start()
  87.  
  88. delaySetButton:onClick(function(self,event,button,x,y)
  89.     --TODO set timer delay
  90.     if(event=="mouse_click")and(button==1)then
  91.  
  92.         basalt.debug("Left mousebutton got clicked!")
  93.     end
  94. end)
  95.  
  96. subnetToggleButton:onClick(function(self,event,button,x,y)
  97.     --TODO sub 10 seconds from timer delay
  98.     if(event=="mouse_click")and(button==1)then
  99.         basalt.debug("Left mousebutton got clicked!")
  100.     end
  101. end)
  102.  
  103.  
  104.  
  105. basalt.autoUpdate()
Advertisement
Add Comment
Please, Sign In to add comment