Advertisement
Guest User

1

a guest
Jul 23rd, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.16 KB | None | 0 0
  1. -- Where to find aspect files
  2. local aspectDir = "/thaumhelper/recipes"
  3. local descDir = "/thaumhelper/descriptions"
  4.  
  5. -- Optional monitor
  6. local monitor = nil
  7. local monitorDir = "top"
  8. if peripheral.isPresent(monitorDir) then
  9.  if peripheral.getType(monitorDir) == "monitor" then
  10.   monitor = peripheral.wrap(monitorDir)
  11.  end
  12. end
  13.  
  14. -- Theme colours
  15. local colText = colors.white
  16. local colHigh = colors.yellow
  17. local colBord = colors.gray
  18. local colBack = colors.black
  19. local colCycle = {}
  20. colCycle[1] = colors.black
  21. colCycle[2] = colors.red
  22. colCycle[3] = colors.blue
  23. colCycle[4] = colors.lime
  24.  
  25. local alpha = {} -- Alphabetical Dictionary List
  26. local listCol = {} -- Colour values
  27. local aspectCol = {} -- Aspect specific colours
  28. local dict = {} -- Dictionary table with components
  29. local desc = {} -- Description of that aspect
  30.  
  31. -- Chart of colour codes for essence descriptions
  32. local colTrans = {}
  33. colTrans["white"] = 1
  34. colTrans["orange"] = 2
  35. colTrans["magenta"] = 4
  36. colTrans["lightBlue"] = 8
  37. colTrans["yellow"] = 16
  38. colTrans["lime"] = 32
  39. colTrans["pink"] = 64
  40. colTrans["gray"] = 128
  41. colTrans["lightGray"] = 256
  42. colTrans["cyan"] = 512
  43. colTrans["purple"] = 1024
  44. colTrans["blue"] = 2048
  45. colTrans["brown"] = 4096
  46. colTrans["green"] = 8192
  47. colTrans["red"] = 16384
  48. colTrans["black"] = 32768
  49.  
  50. local termX, termY = term.getSize()
  51.  
  52. -- Draw top border
  53. local function drawBorder()
  54.  term.setBackgroundColor(colBack)
  55.  term.clear()
  56.  term.setCursorPos(1,1)
  57.  term.setTextColor(colText)
  58.  term.setBackgroundColor(colBord)
  59.  term.clearLine()
  60.  term.write("Thaumcraft Research Helper")
  61.  term.setCursorPos(termX-4,1)
  62.  term.write("exit")
  63. end
  64.  
  65. -- Load aspects + components into table
  66. local function loadDictionary()
  67.  local tList = fs.list(aspectDir)
  68.  table.sort(tList)
  69.  local i = 0
  70.  for k, v in pairs(tList) do
  71.   i = i + 1
  72.   local tFile = fs.open(aspectDir.."/"..v,"r")
  73.   alpha[k] = v
  74.   listCol[k] = 1
  75.   dict[v] = {}
  76.   local i = 1
  77.   while true do
  78.    local line = tFile.readLine()
  79.    if line == nil then
  80.     break
  81.    else
  82.     dict[v][i] = line
  83.    end
  84.    i = i + 1
  85.   end
  86.   tFile.close()
  87.   if fs.exists(descDir.."/"..v) then
  88.    tFile = fs.open(descDir.."/"..v,"r")
  89.    local line = tFile.readLine()
  90.    if line ~= nil then
  91.     if colTrans[line] ~= nil then
  92.      aspectCol[v] = colTrans[line]
  93.     end
  94.     line = tFile.readLine()
  95.     if line ~= nil then
  96.      desc[v] = line
  97.     end
  98.    end
  99.   end
  100.  end
  101.  return i
  102. end
  103.  
  104. -- Draw aspect with colour
  105. local function drawAspect(aspect)
  106.  if aspectCol[aspect] ~= nil then
  107.   term.setTextColor(aspectCol[aspect])
  108.  else
  109.   term.setTextColor(colors.white)
  110.  end
  111.  term.write(aspect)
  112. end
  113.  
  114. -- List components
  115. local function drawComponents(aspect)
  116.  local initX, initY = term.getCursorPos()
  117.  term.setTextColor(colors.white)
  118.  term.setBackgroundColor(colBord)
  119.  term.write(" ")
  120.  drawAspect(aspect)
  121.  term.write(" ")
  122.  term.setCursorPos(initX,initY+1)
  123.  term.write(" ")
  124.  if dict[aspect] ~= nil then
  125.   for k,v in pairs(dict[aspect]) do
  126.    local curX, curY = term.getCursorPos()
  127.    term.setCursorPos(initX,initY+k+1)
  128.    term.setBackgroundColor(colBord)
  129.    term.write(" ")
  130.    term.setBackgroundColor(colBack)
  131.    term.write(" ")
  132.    drawAspect(v)
  133.   end
  134.  end
  135. end
  136.  
  137. -- List of all aspects
  138. local function drawList(offset)
  139.  local initX = 1
  140.  local initY = 2
  141.  local maxHeight = termY - 1
  142.  local i = 0
  143.  local height = 0
  144.  for k,v in pairs(alpha) do
  145.   if i >= offset then
  146.    term.setBackgroundColor( colBack )
  147.    term.setTextColor( colCycle[listCol[i+1]] )
  148.    term.setCursorPos(initX,initY+height)
  149.    term.write(">")
  150.    term.write("             ")
  151.    term.setCursorPos(initX+1,initY+height)
  152.    drawAspect(v)
  153.    height = height+1
  154.    if height > maxHeight then
  155.     break
  156.    end
  157.   end
  158.   i = i + 1
  159.  end
  160. end
  161.  
  162.  
  163. -- Load in all aspects to dictionary
  164. local listLength = loadDictionary()
  165. local listOffset = 0
  166.  
  167. -- Draw initial list
  168. drawBorder()
  169. drawList(0)
  170.  
  171. -- Welcome message
  172. term.setTextColor(colors.white)
  173. term.setCursorPos(19,3)
  174. term.write("Select aspect to inspect it")
  175. term.setCursorPos(19,4)
  176. term.write("Scroll using the mouse wheel")
  177. term.setCursorPos(19,5)
  178. term.write("Right click to flag an aspect")
  179.  
  180. -- Monitor Welcome
  181. if monitor ~= nil then
  182.  term.redirect(monitor)
  183.  term.setBackgroundColor(colors.black)
  184.  term.setTextColor(colors.white)
  185.  term.clear()
  186.  term.setCursorPos(5,2)
  187.  term.write("Thaumcraft")
  188.  term.setCursorPos(6,3)
  189.  term.write("Research")
  190.  term.setCursorPos(7,4)
  191.  term.write("Helper")
  192.  term.restore()
  193. end
  194.  
  195. -- Main loop
  196. while true do
  197.  local event, p1, p2, p3 = os.pullEvent()
  198.  if event == "mouse_scroll" then -- Mouse list scroll
  199.   listOffset = listOffset+p1
  200.   if listOffset < 0 then
  201.    listOffset = 0
  202.   elseif listOffset > listLength-termY+1 then
  203.    listOffset = listLength-termY+1
  204.   end
  205.   drawList(listOffset)
  206.  elseif event == "mouse_click" then
  207.   if p2 >= termX-4 and p3 == 1 then
  208.    term.setCursorPos(1,1)
  209.    term.setBackgroundColor(colors.black)
  210.    term.setTextColor(colors.white)
  211.    term.clear()
  212.    break
  213.   elseif p2 <= 12 and p3 >= 2 then
  214.    local pos = p3 + listOffset - 1
  215.    if p1 == 2 then
  216.     listCol[pos] = listCol[pos] + 1
  217.     if listCol[pos] > #colCycle then
  218.      listCol[pos] = 1
  219.     end
  220.     drawList(listOffset)
  221.    else
  222.     drawBorder()
  223.     drawList(listOffset)
  224.     term.setTextColor(colText)
  225.     term.setCursorPos(17,4)
  226.     term.write(alpha[pos])
  227.     term.setCursorPos(17,5)
  228.     term.write(desc[alpha[pos]])
  229.     term.setCursorPos(17,7)
  230.     drawComponents(alpha[pos])
  231.     local part1 = dict[alpha[pos]][1]
  232.     local part2 = dict[alpha[pos]][2]
  233.     if part1 ~= nil and part2 ~= nil then
  234.      term.setCursorPos(17,13)
  235.      drawComponents(part1)
  236.      term.setCursorPos(32,13)
  237.      drawComponents(part2)
  238.     end
  239.     if monitor ~= nil then
  240.      term.redirect(monitor)
  241.      term.setBackgroundColor(colBack)
  242.      term.clear()
  243.      term.setCursorPos(1,1)
  244.      term.setTextColor(colText)
  245.      term.setBackgroundColor(colBord)
  246.      term.clearLine()
  247.      local i = 0
  248.      while i < 5 do
  249.       i = i + 1
  250.       term.setCursorPos(1,i)
  251.       term.write(" ")
  252.      end
  253.      term.setCursorPos(1,1)
  254.      drawComponents(alpha[pos])
  255.      term.restore()
  256.     end
  257.    end
  258.   end
  259.  end
  260. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement