Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local f = fs.open("holo.conf", "r")
- local conf = textutils.unserialise(f.readAll())
- f.close()
- local function find_by_partial_ID(id)
- return peripheral.find("hologram", function(name)
- return name:find(id) ~= nil
- end)
- end
- local real_holos = {}
- for id, pos in pairs(conf.projectors) do
- local p = find_by_partial_ID(id)
- if not p then error(id .. " not found!") end
- table.insert(real_holos, { peripheral = p, position = pos})
- end
- local function on_all(fn, ...)
- for _, h in pairs(real_holos) do
- h.peripheral[fn](...)
- end
- end
- local h = {}
- h.translation = {0, 0, 0}
- h.scale = 1
- function h.getTranslation()
- return unpack(h.translation)
- end
- function h.update_translation()
- local x, y, z = unpack(h.translation)
- for _, r in pairs(real_holos) do
- local hx, hy, hz = unpack(r.position)
- local tx, ty, tz = hx * h.scale * 3, hy * h.scale * 2, hz * h.scale * 3
- r.peripheral.setTranslation(x - tx, y - ty, z - tz)
- end
- end
- function h.setTranslation(x, y, z)
- h.translation = {x, y, z}
- h.update_translation()
- end
- function h.setScale(s)
- on_all("setScale", s)
- h.update_translation()
- h.scale = s
- end
- function h.getScale()
- return h.scale
- end
- function h.maxDepth()
- return 3 -- no idea what else to put - dynamically calculating it is probably fiddly
- end
- local function proxy(method)
- return function(...)
- on_all(method, ...)
- end
- end
- h.clear = proxy "clear"
- h.copy = proxy "copy"
- local function color_index(col)
- if col == 0 then return 1, 0 end
- local projector = math.ceil(col / 3)
- local index = (col % 3) + 1
- return projector, index
- end
- function h.set(x, y, z, c)
- on_all("set", x, y, z, 0) -- clear it on other projectors
- local p, i = color_index(c)
- real_holos[p].peripheral.set(x, y, z, i)
- end
- function h.get(x, y, z)
- error "Unavailable"
- end
- function h.fill(x, z, minY, maxY, c)
- on_all("fill", x, z, minY, maxY, 0) -- clear it on other projectors
- local p, i = color_index(c)
- real_holos[p].peripheral.fill(x, z, minY, maxY, i)
- end
- function h.getPaletteColor(c)
- local p, i = color_index(c)
- return real_holos[p].peripheral.getPaletteColor(i)
- end
- function h.setPaletteColor(c, rgb)
- local p, i = color_index(c)
- return real_holos[p].peripheral.setPaletteColor(i, rgb)
- end
- h.setScale(1)
- h.clear()
- h.setTranslation(0, 0, 0)
- return h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement