node.lua 960 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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("1.png")
  5. node.alias("eba")
  6. function decode_command(line)
  7. local cmd = json.decode(line)
  8. print(line)
  9. if cmd.type == "diapo" then
  10. cur_image:dispose()
  11. cur_image = resource.load_image(cmd.image)
  12. elseif cmd.type == "pregunta" then
  13. cur_preg = cmd.preg
  14. elseif cmd.type == "time" then
  15. time = cmd.time
  16. print(time)
  17. elseif cmd.type == "video" then
  18. -- ?
  19. elseif cmd.type == "switch" then
  20. state = cmd.new_state
  21. end
  22. end
  23. --node.event("input", decode_command) -- listen to TCP
  24. node.event("data", decode_command) -- listen to UDP
  25. state = "diapo"
  26. cur_preg = ""
  27. time = "0:0"
  28. function node.render()
  29. if state == "diapo" then
  30. cur_image:draw(0,0,WIDTH,HEIGHT)
  31. font:write(730,580,time,20,1,1,1,1)
  32. elseif state == "pregunta" then
  33. preguntas:draw(0,0,WIDTH,HEIGHT)
  34. font:write(120,320,cur_preg,20,1,1,1,1)
  35. end
  36. end