summaryrefslogtreecommitdiff
path: root/john.lua
blob: 9837cd3879c65506beab567fb15ea3f221f23b59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local URL = "https://john.citrons.xyz/api/minecraft"

local framebuf = require("framebuf")
local fb = framebuf.new()

local function splitw(str)
	local res = {}
	for s in str:gmatch("%S+") do
		table.insert(res,s)
	end
	return res
end

local monitors = splitw(settings.get"john.monitors")
if monitors == nil or #monitors < 1 then
	error("need john.monitors setting")
end

local h = assert(http.get(URL, {}, true))
fb:ppm(h)

local W,H = fb:get_size()

local total_width = 0
for ix,iname in ipairs(monitors) do
	local mon = peripheral.wrap(iname)
	total_width = total_width + (mon.getSize())*2
end
local leftover = total_width - W
print("mmm",total_width,W,leftover)
local xoffs = -math.floor(leftover/2)

for ix,iname in ipairs(monitors) do
	print("doing",ix,iname,"at",xoffs)
	local mon = peripheral.wrap(iname)
	mon.clear()
	mon.setTextScale(0.5)
	local _, bee = pcall(function() fb:present(mon,xoffs,0) end)
	xoffs = xoffs + (mon.getSize())*2 + 8
	-- print(bee)
end

h.close()

-- local m = peripheral.wrap "bottom"
-- m.clear()
-- m.setTextScale(0.5)
-- local t = term.redirect(m)
-- local _, bee = pcall(function()
--     fb:present()
-- end)
-- term.redirect(t)
-- print(bee)