routes.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. -- Once the ending owns the mission the route stops driving anything. The bookends
  14. -- need no client report: they are queued with their own state selection.
  15. if s:variable("ember.ending") then return end
  16. local active = controllers[s:variable("ember.region")]
  17. if not active then return end
  18. if not s:variable("ember.later.owns_hud") then
  19. c:set_variable("ember.later.owns_hud", true)
  20. a.darkness(c, s, false)
  21. end
  22. local rank = ({[56] = 1, [40] = 2, [0] = 3})[s:variable("ember.region")]
  23. if rank > (s:variable("ember.r.furthest") or 0) then c:set_variable("ember.r.furthest", rank) end
  24. local changed = s:variable("ember.r.region") ~= s:variable("ember.region")
  25. if changed then
  26. c:set_variable("ember.r.region", s:variable("ember.region"))
  27. if s:variable("ember.checkpoint.region") ~= s:variable("ember.region") then a.darkness(c, s, false) end
  28. end
  29. active.enter(c, s)
  30. if changed and active.resume then active.resume(c, s) end
  31. if active.guidance then active.guidance(c, s) end
  32. end
  33. function R.dispatch(method, c, s, e)
  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) a.squad(c, s, e) end
  45. function R.reset(c, s)
  46. local active = controllers[s:variable("ember.checkpoint.region")]
  47. assert(active, "checkpoint has no encounter controller")
  48. active.reset(c, s, s:variable("ember.checkpoint.name"))
  49. end
  50. R.terminated = ending.terminated
  51. return R
  52. end