start.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Formatters = Formatters or {} --table to hold the formatters so that they don't get GC'd
  2. --this will use two different ways to show how to create DataFormatter objects
  3. --first way is to set the FormatData function explicitly
  4. local formatter = DataFormatter.new("name")
  5. formatter.FormatData = function(raw_data)
  6. --[[
  7. Data format:
  8. raw_data[0] is the name.
  9. raw_data[1] is a bool - True means the name has to be entered. False means the name has been entered already.
  10. ]]
  11. formatted_data = ""
  12. if (raw_data[1] == "1") then
  13. --because we know that it is only used in the high_score.rml file, use that namespace for the OnKeyDown function
  14. formatted_data = "<input id=\"player_input\" type=\"text\" name=\"name\" onkeydown=\"HighScore.OnKeyDown(event)\" />"
  15. else
  16. formatted_data = raw_data[0]
  17. end
  18. return formatted_data
  19. end
  20. Formatters["name"] = formatter --using "name" as the key only for convenience
  21. --second example uses a previously defined function, and passes in as a parameter for 'new'
  22. function SecondFormatData(raw_data)
  23. return "<defender style=\"color: rgba(" .. raw_data[0] .. ");\" />"
  24. end
  25. Formatters["ship"] = DataFormatter.new("ship",SecondFormatData)
  26. function Startup()
  27. maincontext = rocket.contexts["main"]
  28. maincontext:LoadDocument("data/background.rml"):Show()
  29. maincontext:LoadDocument("data/main_menu.rml"):Show()
  30. end
  31. Startup()