Daniel_Kerman

LokiAPI

Dec 13th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. function checkNumber(var)
  2.     assert(type(var) == "number", "Error: Expected type number. Got different type instead.");
  3. end
  4.  
  5. function clc(clr,bOrW)
  6. bOrW = bOrW or 0
  7.     if term.isColor then
  8.         return clr;
  9.     else
  10.         if bOrW == true or bOrW == 1 then
  11.             return colors.white
  12.         else
  13.             return colors.black
  14.         end
  15.     end
  16. end
  17.  
  18. function GOE(inNumber,compNumber,debugNr) -- greater or equal
  19.     debugNr = debugNr or "";
  20.     inNumber = tonumber(inNumber);
  21.     compNumber = tonumber(compNumber);
  22.     assert(compNumber <= inNumber, "Error: Expected number greater or equal. "..debugNr);
  23. end
  24.  
  25. function getCenter(coordinate,subtraction)
  26.     subtraction = subtraction or 0;
  27.     checkNumber(subtraction);
  28.     coordinate = coordinate or "x";
  29.     x, y = term.getSize();
  30.     assert(math.floor(x/2-subtraction)>=1,"Error: Subraction too high.");
  31.     --assert(math.floor(y/2-subtraction)>=1,"Error: Subraction too high.");
  32.     if coordinate == "x" then return math.floor(x/2 - subtraction) elseif coordinate == "y" then
  33.     return math.floor(y/2 - subtraction) else
  34.     return 1; end
  35. end
  36.  
  37. function drawRectangle(xCoor,yCoor,width,height,color,fillType)
  38.     xCoor = xCoor or 1; yCoor = yCoor or 1; width = width or 2; height = height or 2; color = color or colors.red; fillType = fillType or "fill";
  39.     checkNumber(xCoor); checkNumber(yCoor); checkNumber(width); checkNumber(height); checkNumber(color);
  40.     GOE(xCoor,1,"1"); GOE(yCoor,1,"2"); GOE(width,1,"3"); GOE(height,1,"4");
  41.     if (fillType == "fill") then
  42.         paintutils.drawFilledBox(xCoor,yCoor,xCoor+width-1,yCoor+height-1,color);
  43.     else
  44.         paintutils.drawBox(xCoor,yCoor,xCoor+width-1,yCoor+height-1,color);
  45.     end
  46. end
  47.  
  48. function clean(cursorPosX,cursorPosY,bgColor,textColor)
  49.     cursorPosX = cursorPosX or 1; cursorPosY = cursorPosY or 1; bgColor = bgColor or colors.white; textColor = textColor or colors.black;
  50.     checkNumber(cursorPosX); checkNumber(cursorPosY); checkNumber(bgColor); checkNumber(textColor);
  51.     GOE(cursorPosX,1); GOE(cursorPosY,1);
  52.     term.setCursorPos(cursorPosX,cursorPosY);
  53.     term.setBackgroundColor(bgColor); term.setTextColor(textColor);
  54.     term.clear();
  55. end
  56.  
  57. function color(bgColor,textColor)
  58.     bgColor = bgColor or colors.white; textColor = textColor or colors.black;
  59.     term.setBackgroundColor(bgColor); term.setTextColor(textColor);
  60. end
  61.  
  62. function save(table,name)
  63. local file = fs.open(name,"w")
  64. file.write(textutils.serialize(table))
  65. file.close()
  66. end
  67.  
  68. function load(name)
  69. local file = fs.open(name,"r")
  70. if file == nil then
  71. return 0;
  72. else
  73. local data = file.readAll()
  74. file.close()
  75. return textutils.unserialize(data)
  76. end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment