routes.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. -- Pre-rendered playback is observed without replacing the gameplay world.
  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
  34. if method == "timer" then return ending.timer(c, s, e) end
  35. return
  36. end
  37. if method == "timer" then
  38. for _, region in ipairs({56, 40, 0}) do
  39. local controller = controllers[region]
  40. if controller.timer and controller.timer(c, s, e) then return true end
  41. end
  42. return false
  43. end
  44. local active = controllers[s:variable("ember.region")]
  45. if active and active[method] then return active[method](c, s, e) end
  46. end
  47. function R.squad(c, s, e)
  48. if not s:variable("ember.ending") then a.squad(c, s, e) end
  49. end
  50. function R.reset(c, s)
  51. local active = controllers[s:variable("ember.checkpoint.region")]
  52. assert(active, "checkpoint has no encounter controller")
  53. active.reset(c, s, s:variable("ember.checkpoint.name"))
  54. end
  55. R.terminated = ending.terminated
  56. R.started = ending.started
  57. R.skip = ending.skip
  58. return R
  59. end