opening.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. -- Arrival cinematic and control handoff. The cinematic owns a separate authored state.
  2. return function(mission, landing)
  3. local entry = assert(mission.states.STATE_80B3C09E_0006_0001_80B3C09A)
  4. local cinematic = assert(mission.Slot.PF_CINEMATIC_BOOKEND_CINEMATIC)
  5. local function phase(state) return state:variable("ember.cinematic") or 0 end
  6. local function finish(context, state)
  7. if phase(state) ~= 1 then return end
  8. context:set_variable("ember.cinematic", 2)
  9. context:slot(cinematic):set_cinematic_active{active = false}
  10. context:select_state(landing.initial_state)
  11. context:set_phase(2)
  12. end
  13. return {
  14. initial_state = entry,
  15. client_state = function(context, state, event)
  16. local held = event.held_region_index or event.current_region_index
  17. -- Only a held-region report starts the movie; a requested destination is insufficient.
  18. if held == entry.region_index and phase(state) == 0 then
  19. context:set_variable("ember.cinematic", 1)
  20. context:set_phase(1)
  21. context:slot(cinematic):set_cinematic_active{active = true}
  22. end
  23. end,
  24. terminated = function(context, state, event)
  25. if phase(state) ~= 1 then return end
  26. local slot = context:slot(cinematic)
  27. if event.registry_key ~= slot.registry_key or event.slot_type ~= slot.slot_type
  28. or event.slot_index ~= slot.slot_index then return end
  29. finish(context, state)
  30. end,
  31. }
  32. end