Advertisement
Zantag

Thaum Computer Display

Jun 12th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. imgHeight = 16
  2. if fs.exists("imgs.txt") then
  3. imgs = paintutils.loadImage("imgs.txt")
  4. else
  5. shell.run("pastebin get dNXpareS imgs.txt")
  6. --Assumes you have http enabled
  7. imgs = paintutils.loadImage("imgs.txt")
  8. end
  9. if fs.exists("names") then
  10.  
  11. else
  12. shell.run("pastebin get 9d4JPVYB names")
  13. --Assumes you have http enabled
  14. end
  15.  
  16. local names = {}
  17. names = readLines("names")
  18.  
  19. local rangeLow = 1 --Change to be 1-8, 9-16, 17-24 etc.
  20. local rangeHigh = 8
  21. local function readLines(sPath)
  22. local file = fs.open(sPath, "r")
  23. if file then
  24. local tLines = {}
  25. local sLine = file.readLine()
  26. while sLine do
  27. table.insert(tLines, sLine)
  28. sLine = file.readLine()
  29. end
  30. file.close()
  31. return tLines
  32. end
  33. return nil
  34. end
  35.  
  36. function drawImg(index, x,y)
  37. index = index - 1
  38. curY = 0
  39. for yy = index*imgHeight+1, (index+1)*imgHeight do
  40. for xx = 1, 16 do
  41. paintutils.drawPixel(x+xx-1, y+curY, imgs[yy][xx])
  42. end
  43. curY = curY + 1
  44. end
  45. end
  46. function renderAspect(name, qty, x, y)
  47. local index = 0
  48. for i = 1, #names do
  49. if string.lower(name) == string.lower(names[i]) then
  50. index = i
  51. break
  52. end
  53. end
  54. if index ~= 0 then
  55. drawImg(index, x,y)
  56. utils.write(x+1, y + imgHeight, name .. ": " .. qty, colors.white, colors.black)
  57. return 1
  58. else
  59. return 0
  60. end
  61. end
  62. mon = peripheral.wrap("right")
  63. term.redirect(mon)
  64. term.clear()
  65. rednet.open("bottom")
  66.  
  67. local globalTbl = {}
  68.  
  69.  
  70. utils = {
  71. clear = function()
  72. mon.setBackgroundColor(colors.black)
  73. mon.clear()
  74. end,
  75. write = function(x, y, text, color, background)
  76. if color ~= nil then
  77. mon.setTextColor(color)
  78. else
  79. mon.setTextColor(colors.white)
  80. end
  81.  
  82. if background ~= nil then
  83. mon.setBackgroundColor(background)
  84. else
  85. mon.setBackgroundColor(colors.black)
  86. end
  87.  
  88. mon.setCursorPos(x, y)
  89. mon.write(text)
  90. end,
  91. writeCentered = function(y, text, color, background)
  92. utils.write(utils.centerString(text), y, text, color, background)
  93. end,
  94. getWidth = function()
  95. local width, height = mon.getSize()
  96. return width
  97. end,
  98. getHeight = function()
  99. local width, height = mon.getSize()
  100. return height
  101. end,
  102. centerString = function(msg)
  103. local length = string.len(msg)
  104. local width = utils.getWidth()
  105. return (width - length) / 2
  106. end
  107. }
  108.  
  109. function printAspects()
  110.  
  111. utils.clear()
  112. utils.writeCentered(1," Cauldron ", colors.white, colors.blue)
  113.  
  114. if globalTbl ~= nil then
  115. local t = {}
  116. for k, v in pairs(globalTbl) do
  117. if v ~= nil then
  118. for k2, v2 in pairs(v) do
  119. if t[k2] ~= nil then
  120. t[k2] = t[k2] + v2
  121. else
  122. t[k2] = v2
  123. end
  124. end
  125. end
  126. end
  127. line = 3
  128. local a = {}
  129. for n in pairs(t) do
  130. table.insert(a,n)
  131. end
  132. table.sort(a)
  133. xs = {1, 21, 42, 63, 1, 21,42,63}
  134. ys = {1, 1, 1, 1, 19, 19,19,19}
  135. line = 1
  136. local tempMax = rangeHigh
  137. if rangeHigh > #a then
  138. tempMax = #a
  139. end
  140. for i = rangeLow, tempMax do
  141. -- utils.write(1, line, v .. ": " .. t[v])
  142. v = a[i]
  143. renderAspect(v, t[v], xs[line], ys[line]+2)
  144. line = line + 1
  145. end
  146. end
  147. end
  148.  
  149. function main()
  150. while true do
  151. id, msg = rednet.receive()
  152. utils.clear()
  153. if not (msg == "none") then
  154. tbl = textutils.unserialize(msg)
  155. globalTbl[id] = tbl
  156. i = 0
  157. else
  158. globalTbl[id] = nil
  159. end
  160. printAspects()
  161. end
  162. end
  163.  
  164. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement