Advertisement
Guest User

hologram.lua

a guest
Jul 26th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.84 KB | None | 0 0
  1. local shell = require("shell")
  2. local component = require("component")
  3.  
  4. local function printErr(err)
  5.  io.stderr:write(err.."\n")
  6. end
  7.  
  8. local holo
  9.  
  10. addresses = {}
  11. for address in component.list("hologram") do
  12.   table.insert(addresses, address)
  13.   print(#addresses .. ": " .. address)
  14. end
  15. if #addresses > 1 then
  16.   io.write("Choose projector: ")
  17.   local index
  18.   repeat
  19.     local input = string.gsub(require("term").read(), "\n", "")
  20.     index = tonumber(input)
  21.     if not (index and addresses[index]) then
  22.       io.write("\nInvalid index!\nChoose projector: ")
  23.     end
  24.   until index and addresses[index]
  25.   holo = component.proxy(addresses[index])
  26. end
  27.  
  28. local args = shell.parse(...)
  29.  
  30. if #args < 1 then
  31.  printErr("Usage: hologram FILE")
  32.  return
  33. end
  34.  
  35. local file, reason = io.open(args[1], "r")
  36. if not file then
  37.   printErr("Failed to open file: "..reason)
  38.   return
  39. end
  40.  
  41. local rawdata = file:read("*all")
  42. file:close()
  43. local data, reason = load("return "..rawdata)
  44. if not data then
  45.  printErr("Failed loading model: "..reason)
  46.  return
  47. end
  48. data = data()
  49.  
  50. holo.clear()
  51.  
  52. if data.scale then
  53.  holo.setScale(data.scale)
  54. end
  55. if data.color1 then
  56.  holo.setPaletteColor(1, data.color1)
  57. end
  58. if data.color2 then
  59.  holo.setPaletteColor(2, data.color2)
  60. end
  61. if data.color3 then
  62.  holo.setPaletteColor(3, data.color3)
  63. end
  64. if data.rotation then
  65.  local d = data.rotation
  66.  holo.setRotation(d[1], d[2], d[3], d[4])
  67. end
  68. if data.rotationSpeed then
  69.  local d = data.rotationSpeed
  70.  holo.setRotationSpeed(d[1], d[2], d[3], d[4])
  71. end
  72. if data.translation then
  73.  local t = data.translation
  74.  holo.setTranslation(t[1], t[2], t[3])
  75. end
  76.  
  77. if not data.shapes then
  78.  printErr("No shapes!")
  79.  return
  80. end
  81.  
  82. local function fill(minX,maxX, minZ,maxZ, minY,maxY, color)
  83.  for w = minX,maxX do
  84.   for d = minZ,maxZ do
  85.    holo.fill(w,d,minY,maxY, color)
  86.   end
  87.  end
  88. end
  89.  
  90. for k,v in pairs(data.shapes) do
  91.  fill(v[1], v[2], v[3], v[4], v[5], v[6], v[7])
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement