node.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. gl.setup(800,600)
  2. local json = require "json"
  3. local font = resource.load_font("silkscreen.ttf")
  4. local cur_image = resource.load_image("/home/david/git/especificos-node/node/1.png")
  5. local state = "diapo"
  6. local cur_preg = ""
  7. local time = "0:0"
  8. local img_prog="0/0"
  9. node.alias("eba")
  10. function decode_command(line)
  11. local cmd = json.decode(line)
  12. print(line)
  13. print(cmd.type)
  14. if cmd.type == "diapo" then
  15. cur_image:dispose()
  16. cur_image = resource.load_image(cmd.value)
  17. img_prog= cmd.progress
  18. elseif cmd.type == "pregunta" then
  19. cur_preg = cmd.preg
  20. elseif cmd.type == "time" then
  21. time = cmd.time
  22. print(time)
  23. elseif cmd.type == "video" then
  24. -- ?
  25. elseif cmd.type == "switch" then
  26. state = cmd.new_state
  27. end
  28. end
  29. --node.event("input", decode_command) -- listen to TCP
  30. node.event("data", decode_command) -- listen to UDP
  31. function node.render()
  32. if state == "diapo" then
  33. cur_image:draw(0,0,WIDTH,HEIGHT)
  34. font:write(730,580,time,20,1,1,1,1)
  35. font:write(10,580,img_prog,20,1,1,1,1)
  36. elseif state == "pregunta" then
  37. preguntas:draw(0,0,WIDTH,HEIGHT)
  38. font:write(120,320,cur_preg,20,1,1,1,1)
  39. end
  40. end