forked from info-beamer/package-kvv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.lua
118 lines (102 loc) · 3.72 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
gl.setup(1024, 768)
util.init_hosted()
local json = require "json"
local departures = {}
util.file_watch("departures.json", function(content)
departures = json.decode(content)
end)
local white = resource.create_colored_texture(1,1,1,1)
local base_time = N.base_time or 0
util.data_mapper{
["clock/set"] = function(time)
base_time = tonumber(time) - sys.now()
N.base_time = base_time
end;
}
local function unixnow()
return base_time + sys.now()
end
local colored = resource.create_shader[[
uniform vec4 color;
void main() {
gl_FragColor = color;
}
]]
local fadeout = 5
function node.render()
CONFIG.background_color.clear()
local now = unixnow()
local y = 23
for idx, dep in ipairs(departures) do
if dep.date > now - fadeout then
if now > dep.date then
y = y - 120 / fadeout * (now - dep.date)
end
end
end
for idx, dep in ipairs(departures) do
if dep.date > now - fadeout then
local time = dep.nice_date
local remaining = math.floor((dep.date - now) / 60)
local append = ""
if remaining < 0 then
time = "In der Vergangenheit"
if dep.next_date then
append = string.format("und in %d min", math.floor((dep.next_date - now)/60))
end
elseif remaining < 1 then
if now % 2 < 1 then
time = "*jetzt"
else
time = "jetzt*"
end
if dep.next_date then
append = string.format("und in %d min", math.floor((dep.next_date - now)/60))
end
elseif remaining < 2 then
time = string.format("%d min", ((dep.date - now)/60))
if dep.next_nice_date then
append = "und wieder " .. math.floor((dep.next_date - dep.date)/60) .. " min später"
end
else
time = time -- .. " +" .. remaining
if dep.next_nice_date then
append = "und wieder " .. dep.next_nice_date
end
end
stop_r, stop_g, stop_b = 1,1,1
if remaining < 5 then
colored:use{color = {dep.color_r, dep.color_g, dep.color_b, 1}}
white:draw(0,y, 100,y + 40)
colored:deactivate()
CONFIG.font:write(50 - #dep.symbol*10, y, dep.symbol, 40, 1,1,1,1)
CONFIG.font:write(120, y, time , 45, 1,1,1,1)
if sys.now() % 6 < 2.5 and #dep.more > 0 then
CONFIG.font:write(250, y, dep.more, 30, 1,1,1,1)
else
CONFIG.font:write(250, y, dep.direction, 30, stop_r,stop_g,stop_b,1)
end
y = y + 30
CONFIG.font:write(250, y, append , 25, 1,1,1,1)
y = y + 40
else
colored:use{color = {dep.color_r, dep.color_g, dep.color_b, 1}}
white:draw(0,y, 100,y + 40)
colored:deactivate()
CONFIG.font:write(50 - #dep.symbol*10, y, dep.symbol, 40, 1,1,1,1)
CONFIG.font:write(120, y, time , 45, 1,1,1,1)
if sys.now() % 6 < 2.5 and #dep.more > 0 then
CONFIG.font:write(250, y, dep.more, 30, 1,1,1,1)
else
CONFIG.font:write(250, y, dep.direction, 30, stop_r,stop_g,stop_b,1)
end
y = y + 30
CONFIG.font:write(250, y, append , 25, 1,1,1,1)
y = y + 40
end
if y > HEIGHT - 50 then
break
end
end
end
end