Advertisement
goldfiction

edge

Jan 26th, 2024
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.95 KB | Gaming | 0 0
  1. alias="At least it works!"
  2. version = "Edge v3.27"
  3. noLog = false
  4. imageDir = "Axiom/images/"
  5. defc = colors.white
  6. local ccversion = os.version()
  7. local easterEgg_allcaps = false
  8. local use_legacy_drawing = true
  9. local replicate_to_screen = true
  10. local logcat_to_screen = false
  11. debugOverlay = false
  12. local debugOverlayMsg = {}
  13. local screen = nil
  14. local screen_scale = 1
  15. local selected_scale = 3
  16. function printwarn(text)
  17.   screen.setTextColor(colors.gray)
  18.   screen.write("[")
  19.   screen.setTextColor(colors.orange)
  20.   screen.write("WARNING")
  21.   screen.setTextColor(colors.gray)
  22.   screen.write("]")
  23.   screen.setTextColor(colors.white)
  24.   term.redirect(screen)
  25.   print(" "..text)
  26.   term.redirect(term.native())
  27.   sleep(0.1)
  28. end
  29. function printerr(text)
  30.   screen.setTextColor(colors.gray)
  31.   write("[")
  32.   screen.setTextColor(colors.red)
  33.   write("ERROR")
  34.   screen.setTextColor(colors.gray)
  35.   write("]")
  36.   screen.setTextColor(colors.white)
  37.   term.redirect(screen)
  38.   print(" "..text)
  39.   term.redirect(term.native())
  40.   sleep(0.1)
  41. end
  42. function printout(text)
  43.   screen.setTextColor(colors.gray)
  44.   screen.write("[")
  45.   screen.setTextColor(colors.green)
  46.   screen.write("INFO")
  47.   screen.setTextColor(colors.gray)
  48.   screen.write("]")
  49.   screen.setTextColor(colors.white)
  50.   term.redirect(screen)
  51.   print(" "..text)
  52.   term.redirect(term.native())
  53.   sleep(0.1)
  54. end
  55. function screentest()
  56.  
  57.   screen.clear()
  58.   screen.setCursorPos(1,1)
  59.   screen.write("Screen OK!")
  60. end
  61. function setScale(scale)
  62.   screen_scale = scale
  63. end
  64. function getScaleIndex()
  65.   return selected_scale
  66. end
  67. function setScaleIndex(index)
  68.   selected_scale = index
  69. end
  70. function getScreen()
  71.   return screen or nil
  72. end
  73. function setScreen(newscreen)
  74.   if newscreen == nil then
  75.     screen.setCursorPos(1,1)
  76.     screen.setBackgroundColor(colors.black)
  77.     screen.setTextColor(colors.white)
  78.     screen.clear()
  79.     screen = nil
  80.     return true
  81.   else
  82.     screen = newscreen
  83.     screen.setTextScale(screen_scale)
  84.     local ok, error = pcall(screentest)
  85.     if not ok then
  86.  
  87.       return false, error
  88.     else
  89.       return true
  90.     end
  91.   end
  92.  
  93. end
  94. function hasScreen()
  95.   if screen then return true else return false end
  96. end
  97. function log(string)
  98.  
  99.   if fs.getFreeSpace("/") < 1500 then
  100.     noLog = true
  101.   else
  102.     noLog = false
  103.   end
  104.   if noLog == false then
  105.     local time = os.clock()
  106.     if fs.exists("Axiom/logging/system.log") then
  107.       if fs.getSize("Axiom/logging/system.log") >= 12000 then
  108.         fs.delete("Axiom/logging/system.log")
  109.         log(version.." | "..alias)
  110.       end
  111.     end
  112.     if not fs.exists("Axiom/logging/system.log") then
  113.       logfile = fs.open("Axiom/logging/system.log","w")
  114.       logfile.close()
  115.     end
  116.     logfile = fs.open("Axiom/logging/system.log","a")
  117.     logfile.writeLine("["..time.." / "..c().."]: "..string.."\n")
  118.     logfile.flush()
  119.     logfile.close()
  120.     if logcat_to_screen and screen then
  121.       term.redirect(screen)
  122.       print("["..time.." / "..c().."]: "..string.."")
  123.       term.redirect(term.native())
  124.     end
  125.     if not string.find(string,"rendered") then
  126.       debugOverlayMsg[#debugOverlayMsg+1] = "["..time.." / "..c().."]: "..string
  127.     end
  128.   end
  129. end
  130. function llog(string)
  131.   if noLog == false then
  132.     local time = os.clock()
  133.     if fs.exists("Axiom/logging/edge.log") then
  134.       if fs.getSize("Axiom/logging/edge.log") >= 12000 then
  135.         fs.delete("Axiom/logging/edge.log")
  136.       end
  137.     end
  138.     if not fs.exists("Axiom/logging/edge.log") then
  139.       logfile = fs.open("Axiom/logging/edge.log","w")
  140.       logfile.close()
  141.     end
  142.     logfile = fs.open("Axiom/logging/edge.log","a")
  143.     logfile.writeLine("["..time.." / "..c().."]: "..string.."\n")
  144.     logfile.close()
  145.  
  146.     if not string.find(string,"rendered") then
  147.       --debugOverlayMsg[#debugOverlayMsg+1] = "["..time.." / "..c().."]: "..string
  148.     end
  149.   end
  150. end
  151. function debugSay(text)
  152.   local time = os.clock()
  153.   debugOverlayMsg[#debugOverlayMsg+1] = "["..time.." / "..c().."]: "..text
  154. end
  155. function toggleOverlay()
  156.   debugOverlay = not debugOverlay
  157.   return debugOverlay
  158. end
  159. function getOverlay()
  160.   return debugOverlay
  161. end
  162. function cprint( text, y )
  163.   local x = term.getSize()
  164.   local centerXPos = ( x - string.len(text) ) / 2
  165.   term.setCursorPos( centerXPos, y )
  166.   write( text )
  167. end
  168. function c()
  169.   local returnTime = textutils.formatTime(os.time(),false)
  170.   return returnTime
  171. end
  172. function ico(x,y,imgPath,defaultcolor)
  173.   llog("[draw] drew image @ "..x.." "..y..": img: "..imgPath)
  174.   if fs.exists(imageDir..imgPath) then
  175.     local img = paintutils.loadImage(imageDir..imgPath)
  176.     if img == nil then
  177.       error("nil image data")
  178.     end
  179.     paintutils.drawImage(img, x, y)
  180.     term.setBackgroundColor(defaultcolor)
  181.   else
  182.     log("[error] No such image: "..imageDir..imgPath)
  183.   end
  184. end
  185. function image(x,y,imgPath,defaultcolor)
  186.   if screen and replicate_to_screen then
  187.     local mx, my = screen.getSize()
  188.     for _y=1, my, 1 do
  189.       for _x=1, mx, 1 do
  190.         screen.setCursorPos(_x,_y)
  191.         screen.setBackgroundColor(colors.lightBlue)
  192.         screen.write(" ")
  193.       end
  194.     end
  195.   end
  196.   if not defaultcolor then defaultcolor = colors.white end
  197.   llog("[draw] drew image @ "..x.." "..y..": img: "..imgPath)
  198.   if fs.exists(imageDir..imgPath) then
  199.     local img = paintutils.loadImage(imageDir..imgPath)
  200.     if img == nil then
  201.       error("nil image data")
  202.     end
  203.     paintutils.drawImage(img, x, y)
  204.     term.setBackgroundColor(defaultcolor)
  205.   else
  206.     log("[error] No such image: "..imageDir..imgPath)
  207.   end
  208. end
  209. function aprint(string , color)
  210.   if not color then color = 128 end
  211.   if screen and replicate_to_screen then
  212.     if screen.isColor() then
  213.       screen.setTextColor(color)
  214.     else
  215.       screen.setTextColor(colors.white)
  216.     end
  217.     screen.write(string)
  218.   end
  219.   if not term.isColor() then
  220.     term.setTextColor(colors.white)
  221.   else
  222.      term.setTextColor(color)
  223.   end
  224.   if easterEgg_allcaps then
  225.        write(string.upper(string))
  226.   elseif easterEgg_allcaps == "lower" then
  227.      write(string.lower(string))
  228.   else
  229.     write(string)
  230.   end
  231.     term.setTextColor(colors.white)
  232. end
  233. function setbgColor(color)
  234.     term.setBackgroundColor(color)
  235. end
  236. function textColor(color)
  237.     term.setTextColor(color)
  238. end
  239. function render(x,y,sx,sy,color,defaultcolor,t,tc,shadow)
  240.  
  241.   if sx == x then
  242.     if string.len(t) > 1 then
  243.       sx = x + string.len(t)
  244.     end
  245.   end
  246.   if screen and replicate_to_screen then
  247.     screen.setTextScale(screen_scale)
  248.     if shadow == true then
  249.       for _y=y, sy, 1 do
  250.         for _x=x, sx, 1 do
  251.           screen.setCursorPos(_x+1,_y+1)
  252.           screen.setBackgroundColor(colors.gray)
  253.           screen.write(" ")
  254.         end
  255.       end
  256.     end
  257.     for _y=y, sy, 1 do
  258.       for _x=x, sx, 1 do
  259.         screen.setCursorPos(_x,_y)
  260.         screen.setBackgroundColor(color)
  261.         screen.write(" ")
  262.       end
  263.     end
  264.   end
  265.   if shadow == true then
  266.     for _y=y, sy, 1 do
  267.       for _x=x, sx, 1 do
  268.         term.setCursorPos(_x+1,_y+1)
  269.         setbgColor(colors.gray)
  270.         write(" ")
  271.       end
  272.     end
  273.   end
  274.   for _y=y, sy, 1 do
  275.     for _x=x, sx, 1 do
  276.       term.setCursorPos(_x,_y)
  277.       setbgColor(color)
  278.       write(" ")
  279.     end
  280.   end
  281.  
  282.   xprint(t,x,y,tc)
  283.   term.setBackgroundColor(defaultcolor)
  284.   if screen and replicate_to_screen then
  285.     screen.setBackgroundColor(defaultcolor)
  286.   end
  287. end
  288. function box(x,y,sx,sy,color,defcolor,shadow)
  289.   if fs.getFreeSpace("/") >= 500 then
  290.     llog("[render] rendered @ "..x.." "..y.." "..sx.." "..sy..": shaded: "..tostring(shadow))
  291.   end
  292.   if not color then
  293.     color = colors.white
  294.   end
  295.   if shadow == true then
  296.     paintutils.drawFilledBox(x + 1,y + 1,sx + 1,sy + 1,colors.gray)
  297.   end
  298.   paintutils.drawFilledBox(x,y,sx,sy,color)
  299.   setbgColor(defaultcolor)
  300.   defc = defcolor
  301. end
  302. function xprint(str,x,y,color)
  303.   if screen and replicate_to_screen then
  304.     screen.setCursorPos(x,y)
  305.   end
  306.     term.setCursorPos(x,y)
  307.     aprint(str,color)
  308.     --term.setCursorPos(1,1)
  309. end
  310. function window(posx, posy, sizex, sizey, title, windowColor,content)
  311.   if not windowColor then
  312.     windowColor = colors.white
  313.   end
  314.   if not title then
  315.     render(posx,posy,posx+sizex,posy,colors.lightGray,colors.cyan," Untitled",colors.black,false)
  316.   else
  317.     render(posx,posy,posx+sizex,posy,colors.lightGray,colors.cyan," "..title,colors.black,false)
  318.   end
  319.   render(posx+sizex,posy,posx+sizex,posy,colors.lightGray,colors.cyan,"x",colors.red,false)
  320.   render(posx,posy+1,posx+sizex,posy+sizey+1,windowColor,colors.cyan,"",colors.black,false)
  321.   render(posx+sizex-1,posy+sizey+1,posx+sizex,posy+sizey,windowColor,colors.cyan,".:",colors.black,false)
  322.   if content then
  323.     local contentFunction = assert(content)
  324.     contentFunction()
  325.   end
  326. end
  327. function center(optionalText)
  328.   if optionalText then
  329.     local w, h = term.getSize()
  330.     centerPoint = w / 2 - (string.len(optionalText) / 2)
  331.     return centerPoint, h / 2
  332.   else
  333.     local w, h = term.getSize()
  334.     return w / 2, h / 2
  335.   end
  336. end
  337. function dl(url, file)
  338.       fdl = http.get(url)
  339.       f = fs.open(file,"w")
  340.       f.write(fdl.readAll())
  341.       f.close()
  342. end
  343. local function wPrintv2(wx,wy,width,string,color)
  344.  
  345.  
  346. end
  347. local function wPrint(wx,wy,width, string, color)
  348.   if not color then
  349.     color = colors.gray
  350.   end
  351.   local stringChars = {}
  352.   local count = 0
  353.   local finalString = ""
  354.   local increment = 0
  355.   log(tostring(wx.."&"..wy.."width"..width))
  356.   for i = 1, string.len(string) do
  357.     local c = string:sub(i,i)
  358.  
  359.     table.insert(stringChars, c)
  360.     if count >= width then
  361.       table.insert(stringChars,"\n")
  362.       count = 1
  363.     end
  364.     count = count + 1
  365.     -- do something with c
  366.   end
  367.   local x = wx
  368.   local y = wy
  369.   for k,v in ipairs(stringChars) do
  370.     if v == "\n" then
  371.       y = y + 1
  372.       x = wx
  373.       increment = increment + 1
  374.     end
  375.     if x > wx+width then
  376.       y = y + 1
  377.       x = wx
  378.       increment = increment + 1
  379.     end
  380.     if v ~= "\n" then
  381.       term.setCursorPos(x,y)
  382.       term.setTextColor(color)
  383.       write(v)
  384.       x = x + 1
  385.  
  386.     end
  387.  
  388.   end
  389.   return increment
  390. end
  391. function printWithinBounds(wx,wy,width, string, optCol)
  392.   if not optCol then optCol = colors.white end
  393.   return wPrint(wx, wy, width, string, optCol)
  394.  
  395. end
  396.  
  397. function windowAlert(width, height, alertString, useOKorYN, wcol)
  398.   local noButton = false
  399.   if useOKorYN == "noButton" then
  400.     noButton = true
  401.   end
  402.   -- If useOKorYN = false then use YN, else use OK.
  403.   --local a, incr = printWithinBounds(wx+1, wy, width-1, alertString)
  404.   if term.isColor == false then
  405.     return false
  406.   end
  407.   local exitcol = colors.red
  408.   if wcol == exitcol then
  409.     exitcol = colors.black
  410.   end
  411.   if not wcol then
  412.     wcol = colors.green
  413.   end
  414.   if height < 5 then
  415.     height = 5
  416.   end
  417.   if width < 22 then
  418.     width = 22
  419.   end
  420.   local mx, my = term.getSize()
  421.   local wx = math.floor((mx/2)-(width/2))
  422.  
  423.   local wy = math.floor((my/2)-(height/2))
  424.   log(wy..":"..height)
  425.   render(wx,wy, wx+width, wy+height, colors.white, colors.white, "", colors.lightGray, true)
  426.   render(wx, wy, wx+width, wy, wcol, colors.white, "", colors.red)
  427.   render(wx+width, wy, wx+width, wy, wcol, colors.white, "o", exitcol)
  428.  
  429.   --local tempStr, increment = printWithinBounds(wx+1, wy,width-1, alertString)
  430.   wPrint(wx+1, wy+2, width-2, alertString, colors.black)
  431.   --render(wx+1, wy+1,wx+width-1,wy+height,colors.white, colors.cyan,tempStr, colors.black)
  432.   if noButton == false then
  433.     if useOKorYN == true then
  434.       render(wx+(width/2)-4, wy+height-1, wx+(width/2)+4, wy+height-1, colors.lightGray, colors.white, "   OK   ", colors.gray)
  435.     else
  436.       render(wx+(width/2)-9, wy+height-1, wx+(width/2)-2, wy+height-1, colors.lightGray, colors.white, "  Yes ", colors.gray)
  437.       render(wx+(width/2)+2, wy+height-1, wx+(width/2)+9, wy+height-1, colors.lightGray, colors.white, "   No  ", colors.gray)
  438.     end
  439.   end
  440.  
  441.   while(true) do
  442.     if noButton then break end
  443.     local e, b, x, y = os.pullEvent() -- Get event of type click
  444.     -- If using OK, return nothing.
  445.     -- Else we return true or false
  446.     if e == "terminate" then
  447.       return false
  448.     end
  449.     --render(wx,wy,wy+width, wx+height, colors.white, colors.white, e, colors.lightGray)
  450.     if e == "mouse_click" then
  451.       if noButton == false then
  452.         if useOKorYN then
  453.           if x >= wx+(width/2)-4 and x <= wx+(width/2)+4  and y == wy+height-1 then
  454.             render(wx+(width/2)-4, wy+height-1, wx+(width/2)+4, wy+height-1, colors.gray, colors.white, "   OK   ", colors.lightGray)
  455.           end
  456.         else
  457.           if x >= wx+(width/2)-10 and x <= wx+(width/2)-2 and y == wy+height-1 then
  458.             render(wx+(width/2)-9, wy+height-1, wx+(width/2)-2, wy+height-1, colors.gray, colors.white, "  Yes ", colors.lightGray)
  459.           end
  460.           if x >= wx+(width/2)+2 and x <= wx+(width/2)+9 and y == wy+height-1 then
  461.             render(wx+(width/2)+2, wy+height-1, wx+(width/2)+9, wy+height-1, colors.gray, colors.white, "   No  ", colors.lightGray)
  462.           end
  463.         end
  464.       end
  465.  
  466.       if x == wx+width and y == wy then
  467.         return false
  468.       end
  469.     elseif e == "mouse_up" then
  470.       if noButton == false then
  471.         if useOKorYN then
  472.           if x >= wx+(width/2)-4 and x <= wx+(width/2)+4  and y == wy+height-1 then
  473.             return true
  474.           end
  475.         else
  476.           if   x >= wx+(width/2)-10 and x <= wx+(width/2)-2 and y == wy+height-1 then
  477.             return true
  478.           end
  479.           if x >= wx+(width/2)+2 and x <= wx+(width/2)+9 and y == wy+height-1 then
  480.             return false
  481.           end
  482.         end
  483.       end
  484.  
  485.       if x == wx+width and y == wy then
  486.         return false
  487.       end
  488.     end
  489.   end
  490. end
  491. function readLine(censor)
  492.  
  493. end
  494. function notify(msg,content)
  495.   windowAlert(20,10,msg, true)
  496.  
  497.   --window(3,5,25,3,"System Notification",colors.white,content)
  498.  
  499. end
  500. function aabb(x,y,vx,vy,ex,ey)
  501.   if x >= vx and x <= ex and y >= vy and y <= ey then
  502.     return true
  503.   else
  504.     return false
  505.   end
  506. end
  507. log(version.." | "..alias)
  508.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement