Advertisement
SizableShrimp

help.lua

Jul 8th, 2020 (edited)
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. local component = require('component')
  2. local gpu = component.gpu
  3.  
  4. local width, height = gpu.getResolution()
  5. local maxSize = 0
  6. local maxAddress = ""
  7. for address,type in component.list("screen", true) do
  8.   local proxy = component.proxy(address)
  9.   local width, height = proxy.getAspectRatio()
  10.   local size = width*height
  11.   if proxy ~= nil and size > maxSize then
  12.     maxSize = size
  13.     maxAddress = address
  14.   end
  15. end
  16. gpu.bind(maxAddress)
  17.  
  18. local filesystem = require('filesystem')
  19. local confdir = "/raid"
  20. local success = false
  21. local error = ""
  22. if not filesystem.exists(confdir) then
  23.   for address,type in component.list("filesystem", true) do
  24.     local proxy = component.proxy(address)
  25.     if proxy ~= nil and proxy.exists("help.conf") then
  26.       --print(address, proxy)
  27.       success, error = filesystem.mount(proxy, confdir)
  28.       break
  29.     end
  30.   end
  31. end
  32. if success == nil then
  33.   print("An error occurred loading the filesystem: " .. error)
  34.   return
  35. end
  36.  
  37. local confpath = filesystem.concat(confdir, "help.conf")
  38.  
  39. if not success and not filesystem.exists(confpath) then
  40.   print("No filesystem was found with a help.conf in the main directory")
  41.   return
  42. end
  43.  
  44. local lastupdated = filesystem.lastModified(confpath)
  45.  
  46. --print(filesystem.exists("/home/raid/help.conf"))
  47.  
  48. function loadConf()
  49.   local conf = io.open(confpath)
  50.   --reads pairs of lines
  51.   --the starting coords and the file name to read from
  52.   x = conf:read("*n")
  53.   while (x) do
  54.     y = conf:read("*n")
  55.     filename = string.sub(conf:read(),2)
  56.     --print("raid/"..filename,x,y)
  57.  
  58.     display(filesystem.concat(confdir, filename),x,y)
  59.  
  60.     x = conf:read("*n")
  61.   end
  62.   conf:close()
  63.    
  64. end
  65.  
  66. --detects if the help.conf file has updated to change position of text on screen
  67. function hasUpdated()
  68.   time = filesystem.lastModified(confpath)
  69.   if time > lastupdated then
  70.     lastupdated = time
  71.     return true
  72.   end
  73.  
  74.   conf = io.open(confpath)
  75.   if conf == nil then
  76.     return false
  77.   end
  78.  
  79.   x = conf:read("*n")
  80.   while x do
  81.     conf:read("*n")
  82.     filename = string.sub(conf:read(),2)
  83.  
  84.     time = filesystem.lastModified(confdir..filename)
  85.     if time > lastupdated then
  86.       lastupdated = time
  87.       return true
  88.     end
  89.    
  90.  
  91.     x = conf:read("*n")
  92.   end
  93.  
  94.   conf:close()
  95.   return false
  96. end
  97.  
  98. function display(filename,x,y)
  99.   col1 = io.lines(filename)
  100.   displayText(col1,x,y)
  101. end
  102.  
  103. function displayText(strs, startX, startY)
  104.   k = startY
  105.   for v in strs do
  106.     gpu.set(startX,k,v)
  107.     k=k+1
  108.   end
  109. end
  110.  
  111. gpu.fill(1,1,width,height, " ")
  112. while 1 do
  113.   sleeptime = 5
  114.  
  115.   if hasUpdated() then
  116.     gpu.fill(1, 1, width, height, " ")
  117.     loadConf()
  118.     os.sleep(sleeptime)
  119.   else
  120.     loadConf()
  121.     os.sleep(sleeptime)
  122.   end
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement