paramus

Computer OS

Aug 18th, 2025 (edited)
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.13 KB | Gaming | 0 0
  1. local nft = require "cc.image.nft"
  2. local Ventana, LSApps
  3. local LSBotones = {}
  4. local MaxX,MaxY = term.getSize()
  5. local heldButton, hasDragged = 0, false
  6. local focusWindow, baseTerminal = nil, term.current()
  7. local queueProgram = nil
  8.  
  9. function SystemData()
  10.     --File system
  11.     if (fs.exists("Apps") == false) then
  12.         fs.makeDir("Apps")
  13.     end
  14.     if (fs.exists("SysData") == false) then
  15.         fs.makeDir("SysData")
  16.         if(fs.exists("SysData/os.json")) then
  17.             fs.delete("SysData/os.json")
  18.         end
  19.         if(fs.exists("SysData/Background.nfp") == false) then
  20.             local file = fs.open("SysData/Background.nfp", "w")
  21.             file.close()
  22.         end
  23.     end
  24.     local file = fs.open("SysData/os.json", "w")
  25.     file.writeLine("1.0") --os Version
  26.     file.close()
  27.    
  28.     --Auto install
  29.     if (fs.exists("startup.lua") == false) then
  30.         shell.execute("pastebin", "get", "FHjcaBvz", "startup.lua")
  31.     end
  32.    
  33.     --Options
  34.     if (fs.exists("SysData/options.txt") == false) then
  35.         file = fs.open("SysData/options.txt", "w")
  36.         file.writeLine(colors.blue) --Bar color
  37.         file.writeLine(colors.yellow) --App color
  38.         file.writeLine(colors.black) --Text color
  39.         file.close()
  40.     end
  41.     file = fs.open("SysData/options.txt", "r")
  42.     barColor = tonumber(file.readLine()) --Bar color
  43.     appColor = tonumber(file.readLine()) --App color
  44.     textColor = tonumber(file.readLine()) --Text color
  45.     file.close()
  46.    
  47.     --Obligatory apps
  48.     local LSApps ={
  49.         {"Market", "rnCyVUc8"},
  50.         {"Birb", "PEu7TMTy"},
  51.         {"Files", "46VKqBfY"},
  52.         {"Msgr", "gv8X2eVS"},
  53.         {"Optns", "mn5XYW9f"}
  54.     }
  55.    
  56.     for a=1,#LSApps,1 do
  57.         if (fs.exists("Apps/" .. LSApps[a][1]) == false) then
  58.             fs.delete("Apps/" .. LSApps[a][1])
  59.             shell.execute("pastebin", "get", LSApps[a][2], "Apps/" .. LSApps[a][1] .. "/" .. LSApps[a][1] .. ".lua")
  60.             local fUID = fs.open("Apps/" .. LSApps[a][1] .. "/UID.txt", "w")
  61.             fUID.write(LSApps[a][2])
  62.             fUID.close()
  63.         end
  64.     end
  65. end
  66.  
  67. function LoadApps()
  68.     LSBotones = {}
  69.     LSApps = fs.list("Apps")
  70.     local nApps = table.getn(LSApps)
  71.     local x, y = 2, 2
  72.     for i=1,nApps do
  73.         local name = LSApps[i]
  74.         local path = "Apps/" .. LSApps[i] .. "/" .. LSApps[i] .. ".lua"
  75.        
  76.         if (fs.exists("Apps/" .. LSApps[i] .. "/LOCATION.txt")) then
  77.             local isX = true
  78.             for line in io.lines("Apps/" .. LSApps[i] .. "/LOCATION.txt") do
  79.                 if (isX) then
  80.                     isX = false
  81.                     x = tonumber(line)
  82.                 else
  83.                     y = tonumber(line)
  84.                 end
  85.             end
  86.         elseif (y > 16) then
  87.             y = 2
  88.             x = x+5
  89.            
  90.             local file = fs.open("Apps/" .. LSApps[a][1] .. "/LOCATION.txt", "w")
  91.             file.write(x .. "\n" .. y)
  92.             file.close()
  93.         end
  94.        
  95.         local i = table.getn(LSBotones) + 1
  96.         LSBotones[i] = {x, y, x+1, y+1, name, path}
  97.        
  98.         y = y+3
  99.     end
  100. end
  101.  
  102. function PaintIcons()
  103.    
  104.     for i,b in ipairs(LSBotones) do
  105.         local x,y = LSBotones[i][1], LSBotones[i][2]
  106.         local name = LSBotones[i][5]
  107.        
  108.         paintutils.drawBox(x,y, x+1,y+1, appColor)
  109.         term.setBackgroundColor(colors.white)
  110.         term.setTextColor(textColor)
  111.         term.setCursorPos(x-1,y+2)
  112.         term.write(name)
  113.     end
  114.    
  115. end
  116.  
  117. function OpenProgram(x, y)
  118.     for o = 1,#LSBotones,1 do
  119.         if (o > 6) then
  120.             break
  121.         end
  122.        
  123.         if (x >= LSBotones[o][1] and y >= LSBotones[o][2] and x <= LSBotones[o][3] and y <= LSBotones[o][4]) then
  124.             local w,h = term.getSize()
  125.             local window = window.create(term.native(), 1, 2, w, h-2)
  126.             focusWindow = window
  127.             queueProgram = LSBotones[o][6]
  128.         end
  129.        
  130.     end
  131. end
  132.  
  133. function PaintScreen()
  134.     if (focusWindow ~= nil) then
  135.         term.redirect(baseTerminal)
  136.         local w,h = term.getSize()
  137.        
  138.         -- app top bar
  139.         paintutils.drawLine(1, 1, w, 1, colors.orange)
  140.         paintutils.drawPixel(w,1, colors.yellow)
  141.         term.setTextColor(textColor)
  142.         term.setCursorPos(w,1)
  143.         term.write("x")
  144.  
  145.         -- task bar
  146.         paintutils.drawLine(1, h, w, h, barColor)
  147.         term.setTextColor(textColor)
  148.         term.setCursorPos(3,h)
  149.         term.write("DoorOS")
  150.  
  151.         -- time
  152.         term.setCursorPos(w-7,h)
  153.         term.write(textutils.formatTime(os.time(), false))
  154.  
  155.         -- menu button
  156.         paintutils.drawLine(1, h, 2, h, colors.cyan)
  157.        
  158.         term.redirect(focusWindow)
  159.     else
  160.         local w,h = term.getSize()
  161.         term.setBackgroundColor(colors.white)
  162.         term.clear()
  163.  
  164.         if(fs.exists("SysData/Background.nfp")) then
  165.             local image = paintutils.loadImage("SysData/Background.nfp")
  166.             paintutils.drawImage(image, 1,1)
  167.         end
  168.  
  169.         -- task bar
  170.         paintutils.drawLine(1, h, w, h, barColor)
  171.         term.setTextColor(textColor)
  172.         term.setCursorPos(3,h)
  173.         term.write("DoorOS")
  174.  
  175.         -- time
  176.         term.setCursorPos(w-7,h)
  177.         term.write(textutils.formatTime(os.time(), false))
  178.  
  179.         -- menu button
  180.         paintutils.drawLine(1, h, 2, h, colors.cyan)
  181.  
  182.         PaintIcons()
  183.     end
  184. end
  185.  
  186. function WakeUpEffect()
  187.     local delay = 0.3
  188.    
  189.     term.clear()
  190.     term.setCursorPos(1,3)
  191.     print("     #-#-#-#")sleep(delay)
  192.     print("     #     #   #")sleep(delay)
  193.     print("     #     #   #")sleep(delay)
  194.     print("     #     #   #")sleep(delay)
  195.     print("     #-#-#-#   #")sleep(delay)
  196.     print("     #         #")sleep(delay)
  197.     print("     #         #")sleep(delay)
  198.     print("     #         #")sleep(delay5)
  199.     print("               #-#-#-#")sleep(delay)
  200.     print("")
  201.     print("Industries.")
  202.     sleep(2)
  203. end
  204.  
  205. function ScreenSaver()
  206.     term.setBackgroundColour(colors.black)
  207.     term.setTextColour(colors.white)
  208.    
  209.     local txt = "Screensaver"
  210.     local X,Y, vX,vY = 1,1, 1,1
  211.     while (true) do
  212.         parallel.waitForAny(function()
  213.             term.clear()
  214.             if (X<1) then
  215.                 X=2
  216.                 vX=vX*-1
  217.             elseif (X > (MaxX - string.len(txt) + 1)) then
  218.                 X= (MaxX - string.len(txt))
  219.                 vX=vX*-1
  220.             end
  221.            
  222.             if (Y<1) then
  223.                 Y=2
  224.                 vY=vY*-1
  225.             elseif (Y > MaxY) then
  226.                 Y= MaxY-1
  227.                 vY=vY*-1
  228.             end
  229.            
  230.             term.setCursorPos(X,Y)
  231.             term.write(txt)
  232.             X=X+vX
  233.             Y=Y+vY
  234.             sleep(0.2)
  235.         end,
  236.         function()
  237.             local event, button, x, y = os.pullEvent("mouse_click")
  238.             return
  239.         end)
  240.     end
  241. end
  242.  
  243. --WakeUpEffect()
  244. SystemData()
  245. LoadApps()
  246.  
  247. --main
  248. parallel.waitForAny(
  249.     function()
  250.         while (true) do
  251.             PaintScreen()
  252.             sleep(0.05)
  253.         end
  254.     end,
  255.     function()
  256.         while (true) do
  257.            
  258.             local event, button, x, y = os.pullEvent("mouse_click")
  259.             for i,b in ipairs(LSBotones) do
  260.                 if (b[1]==x and b[2]==y) then
  261.                     heldButton = i
  262.                     break
  263.                 end
  264.             end
  265.            
  266.         end
  267.     end,
  268.     function()
  269.         while (true) do
  270.             local event, button, x, y = os.pullEvent("mouse_drag")
  271.             if (heldButton > 0) then
  272.                 hasDragged = true
  273.                 LSBotones[heldButton][1] = x
  274.                 LSBotones[heldButton][2] = y
  275.                 LSBotones[heldButton][3] = x+1
  276.                 LSBotones[heldButton][4] = y+1
  277.                 PaintScreen()
  278.             end
  279.         end
  280.     end,
  281.     function()
  282.         while (true) do
  283.             local event, button, x, y = os.pullEvent("mouse_up")
  284.            
  285.             if (focusWindow == nil) then
  286.                 if (hasDragged == false) then
  287.                     OpenProgram(x, y)
  288.                 else
  289.                     local file = fs.open("Apps/" .. LSBotones[heldButton][5] .. "/LOCATION.txt", "w")
  290.                     file.write(x .. "\n" .. y)
  291.                     file.close()
  292.                 end
  293.             else
  294.                 local w,h = term.getSize()
  295.                 if (x == w and y == 1) then -- close window
  296.                     focusWindow.reposition(100, 100)
  297.                     --error("Terminate")
  298.                     term.redirect(baseTerminal)
  299.                     focusWindow = nil
  300.                 end
  301.             end
  302.            
  303.             heldButton = 0
  304.             hasDragged = false
  305.         end
  306.     end,
  307.     function()
  308.         while (true) do            
  309.             if (queueProgram ~= nil) then
  310.                 shell.execute(queueProgram)
  311.                 queueProgram = nil
  312.                
  313.                 if (focusWindow ~= nil) then
  314.                     term.redirect(focusWindow)
  315.                 end
  316.                
  317.             end
  318.            
  319.             sleep(0.2)
  320.         end
  321.     end
  322. )
Advertisement
Add Comment
Please, Sign In to add comment