forked from info-beamer/package-conference-room
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.lua
410 lines (354 loc) · 13 KB
/
node.lua
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
gl.setup(1280, 720)
sys.set_flag("slow_gc")
local json = require "json"
local schedule
local current_room
util.resource_loader{
"progress.frag",
}
local white = resource.create_colored_texture(1,1,1)
util.file_watch("schedule.json", function(content)
print("reloading schedule")
schedule = json.decode(content)
end)
local rooms
local spacer = white
node.event("config_update", function(config)
rooms = {}
for idx, room in ipairs(config.rooms) do
if room.serial == sys.get_env("SERIAL") then
print("found my room")
current_room = room
end
rooms[room.name] = room
end
spacer = resource.create_colored_texture(CONFIG.foreground_color.rgba())
end)
hosted_init()
local base_time = N.base_time or 0
local current_talk
local all_talks = {}
local day = 0
function get_now()
return base_time + sys.now()
end
function check_next_talk()
local now = get_now()
local room_next = {}
for idx, talk in ipairs(schedule) do
if rooms[talk.place] and not room_next[talk.place] and talk.start_unix + 25 * 60 > now then
room_next[talk.place] = talk
end
end
for room, talk in pairs(room_next) do
talk.slide_lines = wrap(talk.title, 30)
if #talk.title > 25 then
talk.lines = wrap(talk.title, 60)
if #talk.lines == 1 then
talk.lines[2] = table.concat(talk.speakers, ", ")
end
end
end
if room_next[current_room.name] then
current_talk = room_next[current_room.name]
else
current_talk = nil
end
all_talks = {}
for room, talk in pairs(room_next) do
if current_talk and room ~= current_talk.place then
all_talks[#all_talks + 1] = talk
end
end
table.sort(all_talks, function(a, b)
if a.start_unix < b.start_unix then
return true
elseif a.start_unix > b.start_unix then
return false
else
return a.place < b.place
end
end)
end
function wrap(str, limit, indent, indent1)
limit = limit or 72
local here = 1
local wrapped = str:gsub("(%s+)()(%S+)()", function(sp, st, word, fi)
if fi-here > limit then
here = st
return "\n"..word
end
end)
local splitted = {}
for token in string.gmatch(wrapped, "[^\n]+") do
splitted[#splitted + 1] = token
end
return splitted
end
local clock = (function()
local base_time = N.base_time or 0
local function set(time)
base_time = tonumber(time) - sys.now()
end
util.data_mapper{
["clock/midnight"] = function(since_midnight)
print("NEW midnight", since_midnight)
set(since_midnight)
end;
}
local function get()
local time = (base_time + sys.now()) % 86400
return string.format("%d:%02d", math.floor(time / 3600), math.floor(time % 3600 / 60))
end
return {
get = get;
set = set;
}
end)()
util.data_mapper{
["clock/set"] = function(time)
base_time = tonumber(time) - sys.now()
N.base_time = base_time
check_next_talk()
print("UPDATED TIME", base_time)
end;
["clock/day"] = function(new_day)
day = new_day
print("UPDATED DAY", new_day)
end;
}
function switcher(get_screens)
local current_idx = 0
local current
local current_state
local switch = sys.now()
local switched = sys.now()
local blend = 0.8
local mode = "switch"
local old_screen
local current_screen
local screens = get_screens()
local function prepare()
local now = sys.now()
if now > switch and mode == "show" then
mode = "switch"
switched = now
-- snapshot old screen
gl.clear(CONFIG.background_color.rgb_with_a(0.0))
if current then
current.draw(current_state)
end
old_screen = resource.create_snapshot()
-- find next screen
current_idx = current_idx + 1
if current_idx > #screens then
screens = get_screens()
current_idx = 1
end
current = screens[current_idx]
switch = now + current.time
current_state = current.prepare()
-- snapshot next screen
gl.clear(CONFIG.background_color.rgb_with_a(0.0))
current.draw(current_state)
current_screen = resource.create_snapshot()
elseif now - switched > blend and mode == "switch" then
if current_screen then
current_screen:dispose()
end
if old_screen then
old_screen:dispose()
end
current_screen = nil
old_screen = nil
mode = "show"
end
end
local function draw()
local now = sys.now()
local percent = ((now - switched) / (switch - switched)) * 3.14129 * 2 - 3.14129
progress:use{percent = percent}
white:draw(WIDTH-50, HEIGHT-50, WIDTH-10, HEIGHT-10)
progress:deactivate()
if mode == "switch" then
local progress = (now - switched) / blend
gl.pushMatrix()
gl.translate(WIDTH/2, 0)
if progress < 0.5 then
gl.rotate(180 * progress, 0, 1, 0)
gl.translate(-WIDTH/2, 0)
old_screen:draw(0, 0, WIDTH, HEIGHT)
else
gl.rotate(180 + 180 * progress, 0, 1, 0)
gl.translate(-WIDTH/2, 0)
current_screen:draw(0, 0, WIDTH, HEIGHT)
end
gl.popMatrix()
else
current.draw(current_state)
end
end
return {
prepare = prepare;
draw = draw;
}
end
local content = switcher(function()
return {{
time = CONFIG.other_rooms,
prepare = function()
local content = {}
local function add_content(func)
content[#content+1] = func
end
local function mk_spacer(y)
return function()
spacer:draw(0, y, WIDTH, y+2, 0.6)
end
end
local function mk_talkmulti(y, talk, is_running)
local alpha
if is_running then
alpha = 0.5
else
alpha = 1.0
end
local line_idx = 999999
local top_line
local bottom_line
local function next_line()
line_idx = line_idx + 1
if line_idx > #talk.lines then
line_idx = 2
top_line = talk.lines[1]
bottom_line = talk.lines[2] or ""
else
top_line = bottom_line
bottom_line = talk.lines[line_idx]
end
end
next_line()
local switch = sys.now() + 3
return function()
CONFIG.font:write(30, y, talk.start_str, 50, CONFIG.foreground_color.rgb_with_a(alpha))
CONFIG.font:write(190, y, rooms[talk.place].name_short, 50, CONFIG.foreground_color.rgb_with_a(alpha))
CONFIG.font:write(400, y, top_line, 30, CONFIG.foreground_color.rgb_with_a(alpha))
CONFIG.font:write(400, y+28, bottom_line, 30, CONFIG.foreground_color.rgb_with_a(alpha*0.6))
if sys.now() > switch then
next_line()
switch = sys.now() + 1
end
end
end
local function mk_talk(y, talk, is_running)
local alpha
if is_running then
alpha = 0.5
else
alpha = 1.0
end
return function()
CONFIG.font:write(30, y, talk.start_str, 50, CONFIG.foreground_color.rgb_with_a(alpha))
CONFIG.font:write(190, y, rooms[talk.place].name_short, 50, CONFIG.foreground_color.rgb_with_a(alpha))
CONFIG.font:write(400, y, talk.title, 50, CONFIG.foreground_color.rgb_with_a(alpha))
end
end
local y = 300
local time_sep = false
if #all_talks > 0 then
for idx, talk in ipairs(all_talks) do
if not time_sep and talk.start_unix > get_now() then
if idx > 1 then
y = y + 5
add_content(mk_spacer(y))
y = y + 20
end
time_sep = true
end
if talk.lines then
add_content(mk_talkmulti(y, talk, not time_sep))
else
add_content(mk_talk(y, talk, not time_sep))
end
y = y + 62
end
else
CONFIG.font:write(400, 330, "No other talks.", 50, CONFIG.foreground_color.rgba())
end
return content
end;
draw = function(content)
CONFIG.font:write(400, 180, "Other talks", 80, CONFIG.foreground_color.rgba())
spacer:draw(0, 280, WIDTH, 282, 0.6)
for _, func in ipairs(content) do
func()
end
end
}, {
time = CONFIG.current_room,
prepare = function()
end;
draw = function()
if not current_talk then
CONFIG.font:write(400, 180, "Next talk", 80, CONFIG.foreground_color.rgba())
spacer:draw(0, 300, WIDTH, 302, 0.6)
CONFIG.font:write(400, 310, "Nope. That's it.", 50, CONFIG.foreground_color.rgba())
else
local delta = current_talk.start_unix - get_now()
if delta > 0 then
CONFIG.font:write(400, 180, "Next talk", 80, CONFIG.foreground_color.rgba())
else
CONFIG.font:write(400, 180, "This talk", 80, CONFIG.foreground_color.rgba())
end
spacer:draw(0, 280, WIDTH, 282, 0.6)
CONFIG.font:write(130, 310, current_talk.start_str, 50, CONFIG.foreground_color.rgba())
if delta > 180*60 then
CONFIG.font:write(130, 310 + 60, string.format("in %d h", math.floor(delta/3660)+1), 50, CONFIG.foreground_color.rgb_with_a(0.6))
elseif delta > 0 then
CONFIG.font:write(130, 310 + 60, string.format("in %d min", math.floor(delta/60)+1), 50, CONFIG.foreground_color.rgb_with_a(0.6))
end
for idx, line in ipairs(current_talk.slide_lines) do
if idx >= 5 then
break
end
CONFIG.font:write(400, 310 - 60 + 60 * idx, line, 50, CONFIG.foreground_color.rgba())
end
for i, speaker in ipairs(current_talk.speakers) do
CONFIG.font:write(400, 490 + 50 * i, speaker, 50, CONFIG.foreground_color.rgb_with_a(0.6))
end
end
end
}, {
time = CONFIG.room_info,
prepare = function()
end;
draw = function(t)
CONFIG.font:write(400, 180, "Room information", 80, CONFIG.foreground_color.rgba())
spacer:draw(0, 280, WIDTH, 282, 0.6)
CONFIG.font:write(30, 300, "Audio", 50, CONFIG.foreground_color.rgba())
CONFIG.font:write(400, 300, "Dial " .. current_room.dect, 50, CONFIG.foreground_color.rgba())
CONFIG.font:write(30, 360, "Translation", 50, CONFIG.foreground_color.rgba())
CONFIG.font:write(400, 360, "Dial " .. current_room.translation, 50, CONFIG.foreground_color.rgba())
CONFIG.font:write(30, 460, "IRC", 50, CONFIG.foreground_color.rgba())
CONFIG.font:write(400, 460, current_room.irc, 50, CONFIG.foreground_color.rgba())
CONFIG.font:write(30, 520, "Hashtag", 50, CONFIG.foreground_color.rgba())
CONFIG.font:write(400, 520, current_room.hashtag, 50, CONFIG.foreground_color.rgba())
end
}}
end)
function node.render()
if base_time == 0 then
return
end
content.prepare()
CONFIG.background_color.clear()
CONFIG.background.ensure_loaded():draw(0, 0, WIDTH, HEIGHT)
util.draw_correct(CONFIG.logo.ensure_loaded(), 20, 20, 300, 120)
CONFIG.font:write(400, 20, current_room.name_short, 100, CONFIG.foreground_color.rgba())
CONFIG.font:write(850, 20, clock.get(), 100, CONFIG.foreground_color.rgba())
-- font:write(WIDTH-300, 20, string.format("Day %d", day), 100, CONFIG.foreground_color.rgba())
local fov = math.atan2(HEIGHT, WIDTH*2) * 360 / math.pi
gl.perspective(fov, WIDTH/2, HEIGHT/2, -WIDTH,
WIDTH/2, HEIGHT/2, 0)
content.draw()
end