This repository was archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.lua
More file actions
75 lines (63 loc) · 2.12 KB
/
node.lua
File metadata and controls
75 lines (63 loc) · 2.12 KB
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
-- Initializes the virtual screen of the current node. The variables NATIVE_WIDTH and NATIVE_HEIGHT
-- contain the native screen width
gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
-- Setup an image variable to hold the name of the image coming in from node js
local visibleObject = ''
local TYPE_IMAGE_1 = '.JPEG'
local TYPE_IMAGE_2 = '.png'
local TYPE_VIEO = '.mp4'
if not N.clients then
N.clients = {}
end
node.event("connect", function(client)
local handler = coroutine.wrap(echo)
N.clients[client] = handler
end)
node.event("input", function(line, client)
N.clients[client](line)
end)
node.event("disconnect", function(client)
N.clients[client] = nil
end)
function echo(print)
while true do
-- Read a line of content coming in from nodejs server
local line = readln()
-- We know the line coming in is either an image name or a video. Save it in the visibleObject
-- variable declared earlier.
-- This image/video variable will now be used in node.render()
-- Check if content is IMAGE
if(string.find(line, TYPE_IMAGE_1) ~= nil)
then
visibleObject = resource.load_image(line)
break
end
-- Check if content is IMAGE
if(string.find(line, TYPE_IMAGE_2) ~= nil)
then
visibleObject = resource.load_image(line)
break
end
-- Check if content is VIDEO
if(string.find(line, TYPE_VIEO) ~= nil)
then
visibleObject = resource.load_video {
file = line;
looped = false;
audio = true;
paused = false;
}
break
end
break
end
end
function readln()
return coroutine.yield()
end
-- node.render is called for each frame so the moment a new image name comes in, it'll be replaced
function node.render()
gl.clear(1, 1, 1, 1)
-- util.draw_correct(visibleObject, 0, 0, NATIVE_WIDTH, NATIVE_HEIGHT)
visibleObject:draw(0, 0, NATIVE_WIDTH, NATIVE_HEIGHT)
end