autorun.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. local Editor = require("editor") --Require the editor
  2. local Terminal = require("terminal")
  3. local RT = require("runtime")
  4. local Active
  5. local EActive = false --Editor Active
  6. local GActive = false --Game Active
  7. local GStarted = false
  8. function _auto_init() --I have to seperate the autorun callbacks from the main ones so games can override the original ones without destroying these.
  9. api.setCursor("normal")
  10. Terminal:_init()
  11. Editor:_init()
  12. RT:_init()
  13. Active = Terminal
  14. if Active._redraw then Active:_redraw() end
  15. end
  16. function _auto_exitgame()
  17. Active = EActive and Editor or Terminal
  18. if Active._redraw then Active:_redraw() end
  19. GActive = false
  20. end
  21. function _auto_switchgame()
  22. GActive, GStarted, Active = true, false, RT
  23. --RT:startGame()
  24. end
  25. function _auto_update(dt)
  26. if (not GStarted) and GActive then GStarted = true RT:startGame() end
  27. if Active._update then Active:_update(dt) end
  28. end
  29. function _auto_mpress(...)
  30. if Active._mpress then Active:_mpress(...) end
  31. end
  32. function _auto_mmove(...)
  33. if Active._mmove then Active:_mmove(...) end
  34. end
  35. function _auto_mrelease(...)
  36. if Active._mrelease then Active:_mrelease(...) end
  37. end
  38. function _auto_tpress(...)
  39. if Active._tpress then Active:_tpress(...) end
  40. end
  41. function _auto_tmove(...)
  42. if Active._tmove then Active:_tmove(...) end
  43. end
  44. function _auto_trelease(...)
  45. if Active._trelease then Active:_trelease(...) end
  46. end
  47. function _auto_kpress(k,sc,ir)
  48. if k == "escape" then
  49. api.setCursor("normal")
  50. if not GActive then EActive = not EActive else GActive = false end
  51. if EActive then Active = Editor else Active = Terminal end
  52. if Active._redraw then Active:_redraw() end
  53. end
  54. if Active._kpress then Active:_kpress(k,sc,ir) end
  55. end
  56. function _auto_krelease(...)
  57. if Active._krelease then Active:_krelease(...) end
  58. end
  59. function _auto_tinput(t)
  60. if Active._tinput then Active:_tinput(t) end
  61. end