Advertisement
Xslymaster

tAPI

May 28th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1. --[[
  2.  
  3.     Author: Zachary Knoblauch
  4.     Version: 1.8
  5.     Type: API
  6.    
  7.     An api for the the long winded functions with huge names that I'm too lazy to type
  8.     out all the way.
  9.    
  10.     Custom Functions
  11.    
  12.         download(url, fileName)
  13.         cl()
  14.         createLabel(name)
  15.         Labels:drawLabel(x, y, height, bCol, tCol)
  16.  
  17. --]]
  18.  
  19.  
  20.  
  21. function version()
  22.     version = 1.8
  23.     return version
  24. end
  25.  
  26. function download(url, fileName)
  27.   if type(url) ~= "string" then  
  28.     error("Incorrect argument received for type URL. Expected string, received : "..type(url), 2)
  29.   elseif type(fileName) ~= "string" then
  30.     error("Incorrect argument received for type fileName. Expected string, received : "..type(fileName), 2)
  31.   else
  32.       local download = http.get(url)
  33.       if download then
  34.         local handle = download.readAll()
  35.         download.close()
  36.         local file = fs.open(fileName, "w")
  37.         file.write(handle)
  38.         file.close()
  39.         print("File: "..fileName.." downloaded")
  40.       else
  41.         print("Unable to download file: "..fileName)
  42.         print("Located at URL: "..url)  
  43.       end
  44.     end
  45. end
  46.  
  47. function cPos(x, y)
  48.     term.setCursorPos(x, y)
  49. end
  50.  
  51. function bgCol(col)
  52.     term.setBackgroundColor(col)
  53. end
  54.  
  55. function txtCol(col)
  56.     term.setTextColor(col)
  57. end
  58.  
  59. function drawLine(x1, y1, x2, y2, col)
  60.     paintutils.drawLine(x1, y1, x2, y2, col)
  61. end
  62.  
  63. function cl()
  64.   term.clear()
  65.   term.setCursorPos(1, 1)
  66. end
  67.  
  68. function clearLine(col)
  69.     term.setBackgroundColor(col)
  70.     term.clearLine()
  71. end
  72.  
  73. function drawBox(x1, y1, x2, y2, col, fill)
  74.     if fill == nil then
  75.         paintutils.drawBox(x1, y1, x2, y2, col)
  76.     elseif fill == false then
  77.         paintutils.drawBox(x1, y1, x2, y2, col)
  78.     elseif fill == true then
  79.         paintutils.drawFilledBox(x1, y1, x2, y2, col)
  80.     end
  81. end
  82.  
  83. function cPrint(text, y)
  84.   local x = term.getSize()
  85.   local centerXPos = (x - string.len(text)) / 2
  86.   term.setCursorPos(centerXPos, y)
  87.   write(text)
  88. end
  89.  
  90. labelList = {}
  91. Labels = {}
  92. Labels.__index = Labels
  93.  
  94. function createLabel(name)
  95.     label = {}
  96.     setmetatable(label, Labels)
  97.     label.name = name
  98.     return label
  99. end
  100.  
  101. function Labels:drawLabel(x, y, height, bCol, tCol)
  102.     table.insert(labelList, {self.name, x, y, height, self.action})
  103.    
  104.     self.x = x
  105.     self.y = y
  106.     if self.tCol == nil then
  107.         self.bCol = bCol
  108.     end
  109.    
  110.     self.tCol = tCol
  111.     for i = 1, height do
  112.         drawLine(x, y + i, x + #self.name + 1, y + i, bCol)
  113.     end
  114.    
  115.     cPos(x, y + math.ceil(height/2))
  116.     txtCol(tonumber(tCol))
  117.     bgCol(tonumber(bCol))
  118.     term.write(" "..self.name.." ")
  119. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement