autorun.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. Terminal:_init()
  10. Editor:_init()
  11. RT:_init()
  12. Active = Terminal
  13. if Active._redraw then Active:_redraw() end
  14. end
  15. function _auto_exitgame()
  16. Active = EActive and Editor or Terminal
  17. if Active._redraw then Active:_redraw() end
  18. GActive = false
  19. end
  20. function _auto_switchgame()
  21. GActive, GStarted, Active = true, false, RT
  22. --RT:startGame()
  23. end
  24. function _auto_update(dt)
  25. if (not GStarted) and GActive then GStarted = true RT:startGame() end
  26. if Active._update then Active:_update(dt) end
  27. end
  28. function _auto_mpress(...)
  29. if Active._mpress then Active:_mpress(...) end
  30. end
  31. function _auto_mmove(...)
  32. if Active._mmove then Active:_mmove(...) end
  33. end
  34. function _auto_mrelease(...)
  35. if Active._mrelease then Active:_mrelease(...) end
  36. end
  37. function _auto_tpress(...)
  38. if Active._tpress then Active:_tpress(...) end
  39. end
  40. function _auto_tmove(...)
  41. if Active._tmove then Active:_tmove(...) end
  42. end
  43. function _auto_trelease(...)
  44. if Active._trelease then Active:_trelease(...) end
  45. end
  46. function _auto_kpress(k,sc,ir)
  47. if k == "escape" then
  48. if not GActive then EActive = not EActive else GActive = false end
  49. if EActive then Active = Editor else Active = Terminal end
  50. if Active._redraw then Active:_redraw() end
  51. end
  52. if Active._kpress then Active:_kpress(k,sc,ir) end
  53. end
  54. function _auto_krelease(...)
  55. if Active._krelease then Active:_krelease(...) end
  56. end
  57. function _auto_tinput(t)
  58. if Active._tinput then Active:_tinput(t) end
  59. end