routes.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. return function(m)
  2. local controllers = {}
  3. local a = require("mission_ember.route_support")(m, function(c, s, name)
  4. local active = controllers[s:variable("ember.region")]
  5. if active and active.cleared then active.cleared(c, s, name) end
  6. end)
  7. local ending = require("mission_ember.ending")(m)
  8. controllers[56] = require("mission_ember.processing")(m, a)
  9. controllers[40] = require("mission_ember.cinder")(m, a)
  10. controllers[0] = require("mission_ember.apex")(m, a, ending)
  11. local R = {}
  12. function R.client(c, s, e)
  13. -- Native travel must reach the exact bookend before playback is offered.
  14. if s:variable("ember.ending") then ending.client(c, s, e); return end
  15. local active = controllers[s:variable("ember.region")]
  16. if not active then return end
  17. if not s:variable("ember.later.owns_hud") then
  18. c:set_variable("ember.later.owns_hud", true)
  19. a.darkness(c, s, false)
  20. end
  21. local rank = ({[56] = 1, [40] = 2, [0] = 3})[s:variable("ember.region")]
  22. if rank > (s:variable("ember.r.furthest") or 0) then c:set_variable("ember.r.furthest", rank) end
  23. local changed = s:variable("ember.r.region") ~= s:variable("ember.region")
  24. if changed then
  25. c:set_variable("ember.r.region", s:variable("ember.region"))
  26. if s:variable("ember.checkpoint.region") ~= s:variable("ember.region") then a.darkness(c, s, false) end
  27. end
  28. active.enter(c, s)
  29. if changed and active.resume then active.resume(c, s) end
  30. if active.guidance then active.guidance(c, s) end
  31. end
  32. function R.dispatch(method, c, s, e)
  33. if s:variable("ember.ending") then return end
  34. if method == "timer" then
  35. for _, region in ipairs({56, 40, 0}) do
  36. local controller = controllers[region]
  37. if controller.timer and controller.timer(c, s, e) then return true end
  38. end
  39. return false
  40. end
  41. local active = controllers[s:variable("ember.region")]
  42. if active and active[method] then return active[method](c, s, e) end
  43. end
  44. function R.squad(c, s, e)
  45. if not s:variable("ember.ending") then a.squad(c, s, e) end
  46. end
  47. function R.reset(c, s)
  48. local active = controllers[s:variable("ember.checkpoint.region")]
  49. assert(active, "checkpoint has no encounter controller")
  50. active.reset(c, s, s:variable("ember.checkpoint.name"))
  51. end
  52. R.terminated = ending.terminated
  53. R.started = ending.started
  54. R.skip = ending.skip
  55. return R
  56. end