Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Where to find aspect files
- local aspectDir = "/thaumhelper/recipes"
- local descDir = "/thaumhelper/descriptions"
- -- Optional monitor
- local monitor = nil
- local monitorDir = "top"
- if peripheral.isPresent(monitorDir) then
- if peripheral.getType(monitorDir) == "monitor" then
- monitor = peripheral.wrap(monitorDir)
- end
- end
- -- Theme colours
- local colText = colors.white
- local colHigh = colors.yellow
- local colBord = colors.gray
- local colBack = colors.black
- local colCycle = {}
- colCycle[1] = colors.black
- colCycle[2] = colors.red
- colCycle[3] = colors.blue
- colCycle[4] = colors.lime
- local alpha = {} -- Alphabetical Dictionary List
- local listCol = {} -- Colour values
- local aspectCol = {} -- Aspect specific colours
- local dict = {} -- Dictionary table with components
- local desc = {} -- Description of that aspect
- -- Chart of colour codes for essence descriptions
- local colTrans = {}
- colTrans["white"] = 1
- colTrans["orange"] = 2
- colTrans["magenta"] = 4
- colTrans["lightBlue"] = 8
- colTrans["yellow"] = 16
- colTrans["lime"] = 32
- colTrans["pink"] = 64
- colTrans["gray"] = 128
- colTrans["lightGray"] = 256
- colTrans["cyan"] = 512
- colTrans["purple"] = 1024
- colTrans["blue"] = 2048
- colTrans["brown"] = 4096
- colTrans["green"] = 8192
- colTrans["red"] = 16384
- colTrans["black"] = 32768
- local termX, termY = term.getSize()
- -- Draw top border
- local function drawBorder()
- term.setBackgroundColor(colBack)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colText)
- term.setBackgroundColor(colBord)
- term.clearLine()
- term.write("Thaumcraft Research Helper")
- term.setCursorPos(termX-4,1)
- term.write("exit")
- end
- -- Load aspects + components into table
- local function loadDictionary()
- local tList = fs.list(aspectDir)
- table.sort(tList)
- local i = 0
- for k, v in pairs(tList) do
- i = i + 1
- local tFile = fs.open(aspectDir.."/"..v,"r")
- alpha[k] = v
- listCol[k] = 1
- dict[v] = {}
- local i = 1
- while true do
- local line = tFile.readLine()
- if line == nil then
- break
- else
- dict[v][i] = line
- end
- i = i + 1
- end
- tFile.close()
- if fs.exists(descDir.."/"..v) then
- tFile = fs.open(descDir.."/"..v,"r")
- local line = tFile.readLine()
- if line ~= nil then
- if colTrans[line] ~= nil then
- aspectCol[v] = colTrans[line]
- end
- line = tFile.readLine()
- if line ~= nil then
- desc[v] = line
- end
- end
- end
- end
- return i
- end
- -- Draw aspect with colour
- local function drawAspect(aspect)
- if aspectCol[aspect] ~= nil then
- term.setTextColor(aspectCol[aspect])
- else
- term.setTextColor(colors.white)
- end
- term.write(aspect)
- end
- -- List components
- local function drawComponents(aspect)
- local initX, initY = term.getCursorPos()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colBord)
- term.write(" ")
- drawAspect(aspect)
- term.write(" ")
- term.setCursorPos(initX,initY+1)
- term.write(" ")
- if dict[aspect] ~= nil then
- for k,v in pairs(dict[aspect]) do
- local curX, curY = term.getCursorPos()
- term.setCursorPos(initX,initY+k+1)
- term.setBackgroundColor(colBord)
- term.write(" ")
- term.setBackgroundColor(colBack)
- term.write(" ")
- drawAspect(v)
- end
- end
- end
- -- List of all aspects
- local function drawList(offset)
- local initX = 1
- local initY = 2
- local maxHeight = termY - 1
- local i = 0
- local height = 0
- for k,v in pairs(alpha) do
- if i >= offset then
- term.setBackgroundColor( colBack )
- term.setTextColor( colCycle[listCol[i+1]] )
- term.setCursorPos(initX,initY+height)
- term.write(">")
- term.write(" ")
- term.setCursorPos(initX+1,initY+height)
- drawAspect(v)
- height = height+1
- if height > maxHeight then
- break
- end
- end
- i = i + 1
- end
- end
- -- Load in all aspects to dictionary
- local listLength = loadDictionary()
- local listOffset = 0
- -- Draw initial list
- drawBorder()
- drawList(0)
- -- Welcome message
- term.setTextColor(colors.white)
- term.setCursorPos(19,3)
- term.write("Select aspect to inspect it")
- term.setCursorPos(19,4)
- term.write("Scroll using the mouse wheel")
- term.setCursorPos(19,5)
- term.write("Right click to flag an aspect")
- -- Monitor Welcome
- if monitor ~= nil then
- term.redirect(monitor)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(5,2)
- term.write("Thaumcraft")
- term.setCursorPos(6,3)
- term.write("Research")
- term.setCursorPos(7,4)
- term.write("Helper")
- term.restore()
- end
- -- Main loop
- while true do
- local event, p1, p2, p3 = os.pullEvent()
- if event == "mouse_scroll" then -- Mouse list scroll
- listOffset = listOffset+p1
- if listOffset < 0 then
- listOffset = 0
- elseif listOffset > listLength-termY+1 then
- listOffset = listLength-termY+1
- end
- drawList(listOffset)
- elseif event == "mouse_click" then
- if p2 >= termX-4 and p3 == 1 then
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- break
- elseif p2 <= 12 and p3 >= 2 then
- local pos = p3 + listOffset - 1
- if p1 == 2 then
- listCol[pos] = listCol[pos] + 1
- if listCol[pos] > #colCycle then
- listCol[pos] = 1
- end
- drawList(listOffset)
- else
- drawBorder()
- drawList(listOffset)
- term.setTextColor(colText)
- term.setCursorPos(17,4)
- term.write(alpha[pos])
- term.setCursorPos(17,5)
- term.write(desc[alpha[pos]])
- term.setCursorPos(17,7)
- drawComponents(alpha[pos])
- local part1 = dict[alpha[pos]][1]
- local part2 = dict[alpha[pos]][2]
- if part1 ~= nil and part2 ~= nil then
- term.setCursorPos(17,13)
- drawComponents(part1)
- term.setCursorPos(32,13)
- drawComponents(part2)
- end
- if monitor ~= nil then
- term.redirect(monitor)
- term.setBackgroundColor(colBack)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colText)
- term.setBackgroundColor(colBord)
- term.clearLine()
- local i = 0
- while i < 5 do
- i = i + 1
- term.setCursorPos(1,i)
- term.write(" ")
- end
- term.setCursorPos(1,1)
- drawComponents(alpha[pos])
- term.restore()
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement