Jazz2::Editor::EditorLevelHandler class

Shows a level being edited.

A level handler without players, scripts or a HUD, which only draws the level. It's loaded from the document by the same loader as any level, rendered at the size of the window, and looked at through the free EditorCamera. The level music plays muffled, as under the pause menu.

Base classes

class Jazz2::LevelHandler
Level handler of a local game session.

Public static variables

static float EditMusicLowPass constexpr
How much the music is muffled while the level is edited, a bit more than by the pause menu, 1 for not at all.

Constructors, destructors, conversion operators

EditorLevelHandler(IRootController* root) explicit
Creates a new instance, the root controller is the editor session.
~EditorLevelHandler() override

Public functions

auto Initialize(const LevelDocument& document, StringView levelName, StringView fullPath) -> bool
Loads the level from a document.
auto GetCamera() -> EditorCamera&
Returns the camera.
auto GetViewport() const -> Rendering::PlayerViewport*
Returns the viewport, or nullptr before the viewports are initialized.
auto GetReferenceViewSize() const -> Vector2i
Returns the size of the view the game would show the level in, for the parallax of the layers.
void SetSceneContent(Function<void(UI::Canvas&)>&& drawContent)
Sets what is drawn into the level, among its layers, see EditorSceneCanvas.
void SetInitialCamera(Vector2f center, float scale, bool relative = false)
Places the camera before the level is loaded, otherwise it starts where the level does.
void SetMusicLowPass(float value)
Sets how much the music is muffled, 1 for not at all.
auto GetMusicLowPass() const -> float
Returns how much the music is muffled, 1 for not at all.
void SetMusicPaused(bool paused)
Pauses or continues the music, while the level is played.
void ApplyLevelProperties(const Formats::LevelProperties& properties)
Shows level properties that don't need the level loaded again, such as the water level, starts other music.
auto NeedsReload(const LevelDocument& document) const -> bool
Returns true if the level has to be loaded again to show the document as it is now.
auto GetFrameTexture() const -> Texture*
Returns the last image of the level as shown, it stays while the rendering is suspended.
void SetFrameContent(SceneNode* node)
Draws a node into the image of the level, over the level, see GetFrameTexture().
void SetFrameBlur(bool below, bool whole, bool windows = false)
Blurs the image of the level with what is drawn into it, below a layer and as a whole.
auto RequestFrameBlurBelow(std::uint16_t layer) -> Texture*
Blurs the image of the level as it's drawn below a layer in this frame, returns the blurred image or nullptr.
auto CanBlurFrameBelow() const -> bool
Returns true if the image can be blurred below a layer in this frame, see RequestFrameBlurBelow().
auto RequestFrameBlurBelowWindows(std::uint16_t layer) -> Texture*
Blurs the image of the level as it's drawn below the windows drawn into it in this frame, returns the blurred image or nullptr.
auto GetFrameBlur() const -> Texture*
Returns the whole image of the level blurred with what is drawn into it, or nullptr if it isn't blurred, see SetFrameBlur().
auto IsPausable() const -> bool override
Returns true if the level handler is pausable.
void OnBeginFrame() override
Called at the beginning of each frame.
void OnEndFrame() override
Called at the end of each frame.
void OnInitializeViewport(std::int32_t width, std::int32_t height) override
Called when the viewport needs to be initialized (e.g., when the resolution is changed).
void OnKeyPressed(const KeyboardEvent& event) override
Called when a key is pressed.
void OnKeyReleased(const KeyboardEvent& event) override
Called when a key is released.
void OnTextInput(const TextInputEvent& event) override
Called when a text input is detected.
void OnTouchEvent(const TouchEvent& event) override
Called when a touch event is triggered.
void ApplyLevelSettings(const Formats::LevelSettingsChunk::Settings& settings)
Shows the settings the properties have no room for, the water, as the level loader sets them.

Protected functions

auto GetViewportSetup(std::int32_t width, std::int32_t height) -> ViewportSetup override
Returns how the viewports of the level are rendered for a given size of the window.
auto LoadLevel(LevelDescriptor& descriptor) -> bool override
Loads the level of the handler into a level descriptor.
void LoadLevelScripts(StringView fullPath) override
Loads the scripts of the level, if there are any and they are allowed.
void SpawnPlayers(const LevelInitialization& levelInit) override
Spawns all players.

Function documentation

bool Jazz2::Editor::EditorLevelHandler::Initialize(const LevelDocument& document, StringView levelName, StringView fullPath)

Loads the level from a document.

Parameters
document The level
levelName Name of the level as episode/level
fullPath Path of the level file, may be empty for a level that wasn't saved yet

void Jazz2::Editor::EditorLevelHandler::SetInitialCamera(Vector2f center, float scale, bool relative = false)

Places the camera before the level is loaded, otherwise it starts where the level does.

With relative the scale is relative to the scale at which the view shows as much as the game, which is known only once the view is, and it's snapped to the nearest step of the zoom then.

void Jazz2::Editor::EditorLevelHandler::SetFrameContent(SceneNode* node)

Draws a node into the image of the level, over the level, see GetFrameTexture().

The handler doesn't own it, it's taken out of the image when the handler is destroyed. Does nothing before the viewports are initialized.

void Jazz2::Editor::EditorLevelHandler::SetFrameBlur(bool below, bool whole, bool windows = false)

Blurs the image of the level with what is drawn into it, below a layer and as a whole.

Called every frame. With below, the image is blurred in the middle of being drawn when it's asked for by RequestFrameBlurBelow(), with whole once it's drawn, see GetFrameBlur(). The passes are made the first time and only drawn while they're enabled. Nothing is blurred without the blur effects. With windows (only together with below), it's also blurred in the middle below the windows drawn into it, see RequestFrameBlurBelowWindows().

Texture* Jazz2::Editor::EditorLevelHandler::RequestFrameBlurBelow(std::uint16_t layer)

Blurs the image of the level as it's drawn below a layer in this frame, returns the blurred image or nullptr.

Called while the image is visited, by what is drawn into it over the layer, see SetFrameBlur().

Texture* Jazz2::Editor::EditorLevelHandler::RequestFrameBlurBelowWindows(std::uint16_t layer)

Blurs the image of the level as it's drawn below the windows drawn into it in this frame, returns the blurred image or nullptr.

For windows under a modal window, which are drawn into the image then, so the whole blurred image has them too. Called as RequestFrameBlurBelow(), with a layer above it.

ViewportSetup Jazz2::Editor::EditorLevelHandler::GetViewportSetup(std::int32_t width, std::int32_t height) override protected

Returns how the viewports of the level are rendered for a given size of the window.

The game renders the scene at a smaller size, see DefaultWidth and DefaultHeight, and upscales it. The level editor renders it at the size of the window.

bool Jazz2::Editor::EditorLevelHandler::LoadLevel(LevelDescriptor& descriptor) override protected

Loads the level of the handler into a level descriptor.

The level is looked up by its name, and in the unknown episode if it isn't found there.

void Jazz2::Editor::EditorLevelHandler::LoadLevelScripts(StringView fullPath) override protected

Loads the scripts of the level, if there are any and they are allowed.

The script is a .j2as file next to the level file. The level editor doesn't run scripts while a level is being edited.