DabDaddy6223

cara_main

Aug 2nd, 2026 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. -- This is the primary Operating System for CARA (Computer-Aided Reliance Assistant)
  2.  
  3. require "cara_generic_api"
  4. require "cara_monitor_api"
  5.  
  6. local ui = require "cara_ui"
  7. local screenManager = require "cara_screen_manager"
  8.  
  9. function startupSequence()
  10.     local opening_text, err = readFileToTable("/cara_src/cara_opening_text.txt")
  11.     if not opening_text then
  12.         mon_ClearAndPrint(err, 1)
  13.         return
  14.     end
  15.  
  16.     mon_PrintScrollingTextFromBottom(opening_text, 0.01)
  17. end
  18.  
  19. local screens = {
  20.     require("screens.cara_primary_screen"),
  21.     require("screens.cara_power_screen")
  22. }
  23.  
  24. local network = {
  25.     interaction_agent = nil
  26. }
  27.  
  28. function main()
  29.     -- Init Network
  30.     rednet.open("top")
  31.     rednet.broadcast("acquire_clients", "cara_send")
  32.  
  33.     -- Init UI
  34.     ui.setTarget(MONITOR)
  35.     ui.setTextScale(1)
  36.  
  37.     startupSequence()
  38.     sleep(0.5)
  39.     MONITOR.clear()
  40.  
  41.     ui.resetStyle()
  42.     ui.setTextScale(1.5)
  43.  
  44.     for _, screen in ipairs(screens) do
  45.         screen["network"] = network
  46.         screenManager.append(screen)
  47.     end
  48.  
  49.     while true do
  50.         local current = screenManager.current()
  51.         if current == nil then
  52.             break
  53.         end
  54.        
  55.         if ui.isDirty() then
  56.             ui.clear()
  57.             current.draw(ui)
  58.             ui.validate()
  59.         end
  60.  
  61.         local event = { os.pullEvent() }
  62.  
  63.         if event[1] == "key" then
  64.             local action = current.key(event[2])
  65.  
  66.             if action then
  67.                 if action.type == "quit" then
  68.                     break
  69.                 elseif action.type == "close" then
  70.                     os.shutdown()
  71.                 elseif action.type == "switch" then
  72.                     if action.screen == "next" then
  73.                         screenManager.next()
  74.                     elseif action.screen == "prev" then
  75.                         screenManager.prev()
  76.                     elseif type(action.screen) == "number" then
  77.                         screenManager.switchTo(action.screen)
  78.                     end
  79.                 end
  80.             end
  81.         end
  82.     end
  83.  
  84.     term.setBackgroundColor(colors.black)
  85.     term.setTextColor(colors.white)
  86.     term.clear()
  87.     term.setCursorPos(1, 1)
  88. end
  89.  
  90. main()
Advertisement
Add Comment
Please, Sign In to add comment