Advertisement
LazerAio

CCS

Apr 16th, 2023 (edited)
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.98 KB | None | 0 0
  1. print("Booting...")
  2. Log = {}
  3. PreviusRenderData = {}
  4. function Clear()
  5.     if HasMonitor then
  6.         Monitor.setBackgroundColor(colors.black)
  7.         Monitor.clear()
  8.     end
  9.     term.setBackgroundColor(colors.black)
  10.     term.clear()
  11.     PreviusRenderData = {}
  12. end
  13. function Render(renderData,color) --renderData is packaged as a list of lines to print
  14.     if HasMonitor then
  15.         Monitor.clear()
  16.         Monitor.setTextColor(colors.gray)
  17.         for i=1,#PreviusRenderData do
  18.             local cx,cy = Monitor.getCursorPos()
  19.             Monitor.setCursorPos(cx,cy+1)
  20.             Monitor.write(PreviusRenderData[i])
  21.         end
  22.         Monitor.setCursorPos(1,1)
  23.         Monitor.setTextColor(color)
  24.         for i=1,#renderData do
  25.             local cx,cy = Monitor.getCursorPos()
  26.             Monitor.setCursorPos(cx,cy+1)
  27.             Monitor.write(renderData[i])
  28.         end
  29.     else
  30.         term.clear()
  31.         term.setTextColor(color.gray)
  32.         for i=1,#PreviusRenderData do
  33.             local cx,cy = term.getCursorPos()
  34.             term.setCursorPos(cx,cy+1)
  35.             term.write(PreviusRenderData[i])
  36.         end
  37.         term.setCursorPos(1,1)
  38.         term.setTextColor(color)
  39.         for i=1,#renderData do
  40.             local cx,cy = term.getCursorPos()
  41.             term.setCursorPos(cx,cy+1)
  42.             term.write(renderData[i])
  43.         end
  44.     end
  45. end
  46. function log(level,additional)
  47.     Log[#Log+1] = level
  48.     Log[#Log+1] = additional
  49. end
  50. HasMonitor = false
  51. HasSpeaker = false
  52. function DetectHardware()
  53.     Speaker = peripheral.find("speaker")
  54.     Monitor = peripheral.find("monitor")
  55.     if Speaker == nil then
  56.     else
  57.         HasSpeaker = true
  58.         log(1,"DetectHardware:Speaker_detected")
  59.     end
  60.     if Monitor == nil then
  61.     else
  62.         HasMonitor = true
  63.         log(1,"DetectHardware:Monitor_detected")
  64.     end
  65. end
  66. function ShowAlert(type,text,noText,yesText,noFunc,yesFunc)
  67.     if type == "warning" then
  68.         Render({"---",text},colors.yellow)
  69.     elseif type == "question" then
  70.         Render({"---",text,"Y>",yesText,"N>",noText,"?"},colors.blue)
  71.         local cx,cy = term.getCursorPos()
  72.         while true do
  73.             term.setCursorPos(cx,cy)
  74.             local inp = read()
  75.             if string.upper(inp) == "Y" then
  76.                 yesFunc()
  77.             elseif string.upper(inp) == "N" then
  78.                 noFunc()
  79.             end
  80.         end
  81.     elseif type == "input" then
  82.         Render({"---",text},colors.blue)
  83.         return read()
  84.     else
  85.         log(2,"ShowAlert:type_is_unknown")
  86.     end
  87. end
  88. function DrawImage(filePath,x,y,hasBorder,imageWidth,borderColor)
  89.     if hasBorder then
  90.         paintutils.drawBox(x-imageWidth,y-imageWidth,x+imageWidth,y+imageWidth,borderColor)
  91.     end
  92.     if fs.exists(filePath) then
  93.         paintutils.drawImage(paintutils.loadImage(filePath),x,y)
  94.     else
  95.         log(2,"DrawImage:file_does_not_exist")
  96.     end
  97. end
  98. function ShowLog(asWarnings,lowestLevel)
  99.     local display = true
  100.     if asWarnings then
  101.         for i=1,#Log do
  102.             if tonumber(Log[i]) == nil then
  103.                 if display then
  104.                     ShowAlert("warning",Log[i-1])
  105.                     ShowAlert("warning",Log[i])
  106.                 end
  107.             else
  108.                 if tonumber(Log[i]) < lowestLevel then
  109.                     display = false
  110.                 else
  111.                     display = true
  112.                 end
  113.             end
  114.         end
  115.     else
  116.         log(1,"ShowLog:textmode_enabled_will_dump_info_on_monitor")
  117.         for i=1,#Log do
  118.             if tonumber(Log[i]) == nil then
  119.                 if display then
  120.                     print(Log[i-1])
  121.                     print(Log[i])
  122.                     sleep(0.25)
  123.                 end
  124.             else
  125.                 if tonumber(Log[i]) < lowestLevel then
  126.                     display = false
  127.                 else
  128.                     display = true
  129.                 end
  130.             end
  131.         end
  132.     end
  133. end
  134. log(1,"All base functions loaded")
  135. ShowLog(false,1)
  136. Clear()
  137. DetectHardware()
  138. DrawImage("./bootImage",1,1,false)
  139. if fs.exists("./autoboot/") then
  140.     local i = fs.list("./autoboot/")
  141.     for j=1,#i do
  142.         shell.run("fg ./autoboot/"..i[j])
  143.         sleep(0.25)
  144.         multishell.setFocus(1)
  145.     end
  146. end
  147. if fs.exists("APM") then
  148.     shell.run("bg APM update")
  149. else
  150.     log(2,"APM is missing")
  151.     local function yes()
  152.         shell.run("bg wget https://raw.githubusercontent.com/TheAio/CC-APM/main/APM APM")
  153.         if fs.exists("APM") then
  154.             ShowAlert("warning","Install complete")
  155.         else
  156.             ShowAlert("warning","Install failed")
  157.         end
  158.     end
  159.     local function no()
  160.         log(0,"user refused install")
  161.     end
  162.     --ShowAlert("question","APM is missing, install it?","no","yes",no,yes)
  163.     Clear()
  164. end
  165. Render({"Starting!"},colors.pink)
  166. sleep(1)
  167. Render({"Aios CCS version",Version},colors.yellow)
  168. sleep(1)
  169. Render({"was made in 2023"},colors.blue)
  170. ShowLog(true,3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement