Guest User

HLTIView

a guest
Oct 23rd, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. --This is the very basic libHLTI API. 2 functions, but they work!
  2. --Since HLTI is actually just many Lua tables, we can use it like this:
  3. local libHLTI = {}
  4. libHLTI.GetValues = function(file)
  5.     if not fs.exists(file) then
  6.         error("HLTI file doesn't exist.")
  7.     end
  8.  
  9.     local file = fs.open(file,'r')
  10.     local values = textutils.unserialize(file.readAll())
  11.     if not values then
  12.         error("HLTI image is misconfigured/corrupted.")
  13.     end
  14.    
  15.     file.close()
  16.     return values
  17. end
  18.  
  19. libHLTI.SetValue = function(file, key, value)
  20.     if not fs.exists(file) then
  21.         error("HLTI file doesn't exist.")
  22.     end
  23.  
  24.     local currentValues = libHLTI.GetValues(file)
  25.     currentValues[key] = value
  26.    
  27.     local file = fs.open(file, 'w')
  28.     file.write(textutils.serialize(currentValues))
  29.     file.close()
  30. end
  31.  
  32. --Actual program
  33. local function HLTI_Render(file)
  34.     local hlti = libHLTI.GetValues(file)
  35.     local hltiver = hlti["HLTIVer"]
  36.     local width = hlti["Width"]
  37.     local height = hlti["Height"]
  38.    
  39.     term.setBackgroundColor(colors.black)
  40.     term.setTextColor(colors.white)
  41.     term.clear()
  42.     term.setCursorPos(1,1)
  43.    
  44.     write("HLTI Version: " .. hltiver .. " | ")
  45.     print(width .. "x" .. height)
  46.    
  47.     local yOffset = 2
  48.    
  49.     local sectionCount = 0
  50.    
  51.     --Really bad rendering method. Sorry! :D
  52.     while sectionCount < hlti["Sections"] do
  53.         local v = hlti["Section" .. sectionCount]
  54.         if v.Type == "Color" then
  55.             if not v.BackgroundColor then v.BackgroundColor = colors.black end
  56.             term.setCursorPos(v.X, v.Y + yOffset)
  57.             term.setBackgroundColor(v.BackgroundColor)
  58.             write(" ")
  59.         end
  60.        
  61.         term.setCursorPos(1,2)
  62.         term.setBackgroundColor(colors.black)
  63.         write("Sector "..sectionCount .. "/" .. hlti["Sections"] .. " | X" .. v.X .. " Y" .. v.Y .. "  ") --spaces because of ghosting
  64.         sectionCount = sectionCount + 1
  65.         sleep(0)
  66.     end
  67.     return;
  68. end
  69.  
  70. local tArgs = {...}
  71. local ok, err = pcall(function()
  72. HLTI_Render(tArgs[1]) --Kinda wanted to do this, I'll come up with something better soon.
  73. end)
  74. if not ok then
  75.     printError("Something happened: " .. err)
  76. end
Advertisement
Add Comment
Please, Sign In to add comment