Nathan1852

NatAPI_Area_v.1

Dec 30th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. local function findArg(args, sa)
  2. for i,v in pairs(args) do
  3. if sa == "m=" and tostring(type(v)) == "table" then
  4. return v
  5. end
  6. local x,y = string.find(tostring(v),tostring(sa))
  7. if x and y then
  8. return string.sub(tostring(v),y+1)
  9. end
  10. end
  11. return nil
  12. end
  13.  
  14. New = function(self,...) -- Creates and returns a new instance of "area"
  15. local new = {}
  16. setmetatable(new, {__index = self})
  17. new.string = findArg(arg, "s=") or " "
  18. new.x = tonumber(findArg(arg, "x=")) or 1
  19. new.y = tonumber(findArg(arg, "y=")) or 1
  20. new.width = tonumber(findArg(arg, "w=")) or 20
  21. new.height = tonumber(findArg(arg, "h=")) or 20
  22. new.color_BG = tonumber(findArg(arg, "cbg=")) or colors.cyan
  23. new.color_TXT = tonumber(findArg(arg, "ctx=")) or colors.ligthGray
  24. new.enabled = findArg(arg, "e=") or true
  25. new.mon = findArg(arg, "m=") or term
  26.  
  27. return new
  28. end
  29.  
  30. setColor = function(self,type,color) -- Sets the color, type must be either BG or TXT
  31. if tostring(type) == "BG" then
  32. self.color_BG = color
  33. elseif tostring(type) == "TXT" then
  34. self.color_TXT = color
  35. end
  36. end
  37.  
  38. getColor = function(self,type) -- Returns the color specified by type
  39. if tostring(type) == "BG" then
  40. return self.color_BG
  41. elseif tostring(type) == "TXT" then
  42. return self.color_TXT
  43. else
  44. return false
  45. end
  46. end
  47.  
  48. setX = function(self,x) -- Sets x
  49. self.x = tonumber(x)
  50. end
  51.  
  52. getX = function(self) -- Returns x
  53. return self.x
  54. end
  55.  
  56. setY = function(self,y) -- Sets y
  57. self.y = tonumber(y)
  58. end
  59.  
  60. getY = function(self) -- Returns y
  61. return self.y
  62. end
  63.  
  64. setPos = function(self,x,y) -- Sets x and y to new position
  65. self.x = tonumber(x)
  66. self.y = tonumber(y)
  67. end
  68.  
  69. getPos = function(self) -- Returns x and y
  70. return self.x, self.y
  71. end
  72.  
  73. setWidth = function(self,width) -- Sets the width
  74. self.width = tonumber(width)
  75. end
  76.  
  77. getWidth = function(self) -- Returns the width
  78. return self.width
  79. end
  80.  
  81. setHeigth = function(self,height) -- Sets the height
  82. self.heigth = tonumber(heigth)
  83. end
  84.  
  85. getHeigth = function(self) -- Returns the height
  86. return self.height
  87. end
  88.  
  89. showArea = function(self, mon) -- Writes the area out
  90. if not mon then mon = self.mon else self.mon = mon end
  91. if self.enabled then
  92. mon.setTextColor(self.color_TXT)
  93. mon.setBackgroundColor(self.color_BG)
  94. end
  95. mon.setCursorPos(self.x,self.y)
  96. for i=1,self.height do
  97. for j=1,self.width do
  98. mon.write(self.string)
  99. end
  100. mon.setCursorPos(self.x,self.y + i)
  101. end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment