Jazz2::Editor::PlayTestController class

Plays the level being edited, and returns to editing it.

Goes through PlayTestMode::Edit, PlayTestMode::Entering — the view of the editor flies to where the game will show the player — and PlayTestMode::Play, where the game is revealed in a ring growing over the last image of the editor, back to editing in PlayTestMode::Returning, where the editor is revealed in a ring over the last image of the game. It owns the play-tests: the one played, the one kept to be resumed, and the one left whose last image the ring back still shows.

A kept play-test goes on exactly as it was left if the level is still as it was made from, otherwise the new one starts where the player was, with what the player had, and what was collected or destroyed stays so in the cells that weren't edited, see PlayStartMode::Resume. The music is handed from the editor to the game and back, opened up and muffled again over a while.

Constructors, destructors, conversion operators

PlayTestController(IPlayTestHost& host) explicit
Creates a new instance.
~PlayTestController()
PlayTestController(const PlayTestController&) deleted

Public functions

auto operator=(const PlayTestController&) -> PlayTestController& deleted
auto GetMode() const -> PlayTestMode
Returns the state.
auto IsEditing() const -> bool
Returns true while the level is edited, also while the ring back into the editor grows.
auto IsEntering() const -> bool
Returns true while the view flies into the level.
auto IsInGame() const -> bool
Returns true while the level is played.
auto ArePanelsShown() const -> bool
Returns true if the panels of the editor are shown, while it's used and while the ring into the game grows over them.
auto GetPlayTest() const -> IPlayTest*
Returns the play-test played or kept, or nullptr.
auto GetClosingPlayTest() const -> IPlayTest*
Returns the play-test left, while the ring back into the editor shows its last image, or nullptr.
auto GetGameHandler() const -> LevelHandler*
Returns the level handler of the game while the level is played, or nullptr.
auto GetTransition() -> PlayTransition&
Returns the ring into the level and back.
auto GetLastPlayPath() const -> const PlayPath&
Returns the path the player took in the last play-test.
auto GetPathHistory() const -> const PlayPathHistory&
Returns the paths of the last play-tests, kept in the level.
void ReadPathHistory(const LevelDocument& document)
Reads the paths of the last play-tests from the level, the last one becomes the path shown.
void ClearPathHistory()
Forgets the paths of the play-tests.
auto GetEditCameraCenter() const -> Vector2f
Returns where the camera of the editor was when the level started to be played.
auto GetEditCameraScale() const -> float
Returns the scale of the camera of the editor when the level started to be played.
void Enter(PlayStartMode mode, const PlayTestOptions& options)
Starts playing the level, the view of the editor flies into it first.
void Stop(bool keep)
Stops playing, or the flight into the level, keep keeps the play-test to resume later.
void ReturnFromGame(StringView message, bool exited, Function<void()>&& afterwards = {})
Returns to editing after the frame of the game, which a play-test can't be destroyed inside of.
void Reset()
Forgets all play-tests and their path, as before another level is edited.
void Release()
Releases the play-tests and the rings at once, without returning to the editor, as when it's closed.
void NoteDocumentChanges(const DocumentChanges& changes)
Tells about changes of the level being edited.
void MarkPlayTestOutdated()
Makes the kept play-test start again when it's resumed, as after its script changed.
auto GetDebugOptions() const -> const PlayTestDebugOptions&
Returns the debug toggles of play-tests.
void SetDebugOptions(const PlayTestDebugOptions& options)
Sets the debug toggles of play-tests, applied to the one played now and to every one played later.
void StepFrame()
Advances the time of the level played by a single update, it stands still then.
auto TeleportPlayer(Vector2f screenPos, Vector2f screenSize) -> bool
Moves the first player to where a position on the screen shows in the level played.
void UpdateMusicFade(float timeMult)
Advances the music opening up or being muffled again.
void UpdateTransition(float timeMult)
Advances the rings, the play-test left is released once the ring back is done.
void UpdateEntering()
Plays the level once the view flew into it and a frame showing it was drawn, call it after the frame of the editor.

Function documentation

void Jazz2::Editor::PlayTestController::Enter(PlayStartMode mode, const PlayTestOptions& options)

Starts playing the level, the view of the editor flies into it first.

options say how it's played, with a spawn position already for PlayStartMode::Here.

void Jazz2::Editor::PlayTestController::ReturnFromGame(StringView message, bool exited, Function<void()>&& afterwards = {})

Returns to editing after the frame of the game, which a play-test can't be destroyed inside of.

With exited the path of the player ends by leaving the level. afterwards is called once the level is edited again.

void Jazz2::Editor::PlayTestController::NoteDocumentChanges(const DocumentChanges& changes)

Tells about changes of the level being edited.

Changes of only tiles and events of the grid are given to a kept play-test when it's resumed, instead of starting it again, see PlayStartMode::Resume.

bool Jazz2::Editor::PlayTestController::TeleportPlayer(Vector2f screenPos, Vector2f screenSize)

Moves the first player to where a position on the screen shows in the level played.

screenPos and screenSize are in pixels of the drawable. Returns false if the level isn't played or there's no place for the player near there.