Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local file = "abc.nft"
- local frames = {}
- local function getColourOf(hex)
- local value = tonumber(hex, 16)
- if not value then return nil end
- value = math.pow(2, value)
- return value
- end
- local function loadNFT(path)
- sFrame = 1
- frames[sFrame] = { }
- frames[sFrame].text = { }
- frames[sFrame].textcol = { }
- if fs.exists(path) then
- local file = io.open(path, "r")
- local sLine = file:read()
- local num = 1
- while sLine do
- table.insert(frames[sFrame], num, {})
- table.insert(frames[sFrame].text, num, {})
- table.insert(frames[sFrame].textcol, num, {})
- --As we're no longer 1-1, we keep track of what index to write to
- local writeIndex = 1
- --Tells us if we've hit a 30 or 31 (BG and FG respectively)- next char specifies the curr colour
- local bgNext, fgNext = false, false
- --The current background and foreground colours
- local currBG, currFG = nil,nil
- term.setCursorPos(1,1)
- for i=1,#sLine do
- local nextChar = string.sub(sLine, i, i)
- if nextChar:byte() == 30 then
- bgNext = true
- elseif nextChar:byte() == 31 then
- fgNext = true
- elseif bgNext then
- currBG = getColourOf(nextChar)
- bgNext = false
- elseif fgNext then
- currFG = getColourOf(nextChar)
- fgNext = false
- else
- if nextChar ~= " " and currFG == nil then
- currFG = colours.white
- end
- frames[sFrame][num][writeIndex] = currBG
- frames[sFrame].textcol[num][writeIndex] = currFG
- frames[sFrame].text[num][writeIndex] = nextChar
- writeIndex = writeIndex + 1
- end
- end
- num = num+1
- sLine = file:read()
- end
- file:close()
- end
- end
- loadNFT(file)
- term.clear()
- term.setCursorPos(1,1)
- for k, v in pairs(frames[1]) do
- if tonumber(k) then
- local n = 1
- repeat
- term.setBackgroundColor(frames[1][k][n])
- term.setTextColor(frames[1]["textcol"][k][n])
- write(frames[1]["text"][k][n])
- n = n+1
- until not frames[1][k][n+1]
- end
- write("\n")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement