routes.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. ending.client(c, s, e)
  14. if s:variable("ember.ending") then 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 method == "timer" then
  34. for _, region in ipairs({56, 40, 0}) do
  35. local controller = controllers[region]
  36. if controller.timer and controller.timer(c, s, e) then return true end
  37. end
  38. return false
  39. end
  40. local active = controllers[s:variable("ember.region")]
  41. if active and active[method] then return active[method](c, s, e) end
  42. end
  43. function R.squad(c, s, e) a.squad(c, s, e) end
  44. function R.reset(c, s)
  45. local active = controllers[s:variable("ember.checkpoint.region")]
  46. assert(active, "checkpoint has no encounter controller")
  47. active.reset(c, s, s:variable("ember.checkpoint.name"))
  48. end
  49. R.terminated = ending.terminated
  50. return R
  51. end