Jazz2::Editor::IEditorContext class

What the panels and the dialogs of the level editor need from it.

Everything tools get (see IToolHost), and the level being edited as a whole — its file, its history and its tile sets — with the settings, the actions and the tools of the editor. Implemented by EditorSession.

Base classes

class IToolHost
What tools need from the level editor.

Derived classes

class EditorSession
The level editor.

Public types

using ChangeObserver = Function<void(const DocumentChanges&)>
Function told about changes of the level, see AddChangeObserver().

Public static functions

static auto GetHotkeysPath() -> String
Returns the path of the shortcuts the user changed, Jazz2.EditorHotkeys.json in the configuration directory.
static auto MakeLevelName(StringView path) -> String
Returns the name of a level as episode/level from the path of its file.
static auto IsLevelLockedElsewhere(StringView levelPath) -> bool
Returns whether another editor holds the lock of a level file.

Constructors, destructors, conversion operators

~IEditorContext() defaulted override

Public functions

auto GetHistory() -> CommandHistory& pure virtual
Returns the history of the level being edited.
auto GetActions() -> ActionRegistry& pure virtual
Returns the actions.
auto GetTools() -> ToolManager& pure virtual
Returns the tools.
auto GetBlockGrab() -> BlockGrab& pure virtual
Returns the block grabbed by its corners with a key, marked in the level or in the picker of tiles.
auto GetSettings() -> EditorSettings& pure virtual
Returns the settings.
auto GetEditHandler() const -> EditorLevelHandler* pure virtual
Returns the level handler that shows the level, or nullptr.
auto GetInputModality() const -> InputModality pure virtual
Returns what the editor was used with last.
auto GetTileSetLibrary() -> ContentTileSetLibrary& pure virtual
Returns what is known about the tile sets of the game.
auto GetTileSetData(StringView name) -> const Formats::TileSetData* pure virtual
Returns a whole tile set with the pixels and masks of its tiles, read once, or nullptr if it can't be read.
auto GetTileSetDataCache() -> TileSetDataCache& pure virtual
Returns the tile sets read whole for the level being edited, see GetTileSetData().
void InvalidateTileSet(StringView name) pure virtual
Forgets what was read of a tile set, after its file was written.
auto GetFilePath() const -> StringView pure virtual
Returns the path of the level file, may be empty.
auto GetLevelName() const -> StringView pure virtual
Returns the name of the level as episode/level, may be empty.
void GetFileRoots(bool forSaving, SmallVectorImpl<FileRoot>& roots) pure virtual
Returns the places levels are opened from or saved to.
void GetImageRoots(bool forSaving, SmallVectorImpl<FileRoot>& roots) pure virtual
Returns the places images are opened from or saved to, outside of the content of the game too.
void OpenFile(StringView path) pure virtual
Opens a level file in the editor, asking about unsaved changes first.
void OpenRecoveryCopy(StringView recoveryPath) pure virtual
Restores a recovery copy into the editor, asking about unsaved changes first, see EditorSession::OpenRecoveryCopy().
auto SaveAsFile(StringView path, bool move) -> bool pure virtual
Saves the level into another file and edits that one from then on, see EditorSession::SaveAsFile().
auto CanSaveInPlace() const -> bool pure virtual
Returns true if the level can be saved to its file.
void ShowSaveAsDialog(bool exportOnly, Function<void()>&& onSaved = {}) pure virtual
Shows a dialog to save the level as a new file, or to export it, onSaved is called once it's saved.
void NoteLevelFileMoved(StringView from, StringView to) pure virtual
Tells that a level file was moved or renamed outside of Save As, its place among the recent files goes along.
auto Undo() -> bool pure virtual
Undoes the last change.
auto Redo() -> bool pure virtual
Redoes the last undone change.
void AddChangeObserver(const std::shared_ptr<ChangeObserver>& observer) pure virtual
Tells a function about every change of the level being edited, all of it changes when another level is opened.
auto RecordSnapshotStep(String name, SnapshotParts parts, Function<bool(LevelDocument&)>&& change, DocumentChangeKind kinds = DocumentChangeKind::None, std::int32_t layer = -1) -> bool pure virtual
Makes a change directly on the level and records it as an undoable step, see EditorSession::RecordSnapshotStep().
void SetEditorState(Function<void(LevelDocument&)>&& change) pure virtual
Changes the editor state of the level, which isn't a change to undo, see EditorSession::SetEditorState().
void SetCurrentLayer(std::int32_t layer) pure virtual
Changes the layer being edited.
void ToggleLayerFlag(std::int32_t layer, std::uint8_t flag) pure virtual
Toggles the editor state of a layer, such as whether it's hidden.
void MoveLayerTo(std::int32_t from, std::int32_t to) pure virtual
Moves a layer to another position in the list of layers, as an undoable step.
auto IsEditingEvents() const -> bool pure virtual
Returns true if the editing actions work on events, not on tiles.
auto GetHoverPointer(ToolPointer& pointer) -> bool pure virtual
Returns the pointer over the view, false if it's not over the view.
auto AreEventsShown() const -> bool pure virtual
Returns true if events are shown over the level.
auto GetPickerPanel() const -> PickerPanel pure virtual
Returns what the panel with the tiles and the events shows.
void SetPickerPanel(PickerPanel panel) pure virtual
Changes what the panel with the tiles and the events shows.
void PickEventFromList(Function<void(EventType)>&& callback) pure virtual
Lets the next event chosen in the list go to a callback, instead of becoming the one to place.
auto IsPickingEvent() const -> bool pure virtual
Returns true if the next event chosen in the list goes to a callback.
void CancelEventPick() pure virtual
Lets the next event chosen in the list become the one to place again, see PickEventFromList().
void OnEventChosen(EventType type) pure virtual
Called when an event is chosen in the list.
auto IsPlaying() const -> bool pure virtual
Returns true while the level is played, or is about to be.
auto ArePanelsShown() const -> bool pure virtual
Returns true if the panels are shown, while the level is edited and while the ring into the game grows over them.
auto GetPlayPathHistory() const -> const PlayPathHistory& pure virtual
Returns the paths of the last play-tests, kept in the level.
auto ComputeReachability(SmallVectorImpl<std::int32_t>& distances) -> bool pure virtual
Finds where the player can get from the start of the play character, see EditorSession::ComputeReachability().
void ReloadRuntime() pure virtual
Loads the level again from the document, so the events in the game are as they are now, see ComputeReachability().
void PlayTestWeapon(WeaponType weapon, bool poweredUp) pure virtual
Plays the level from the middle of the view with a weapon in hand and full of ammo, to try it.

Function documentation

static bool Jazz2::Editor::IEditorContext::IsLevelLockedElsewhere(StringView levelPath)

Returns whether another editor holds the lock of a level file.

A lock written less than the lock timeout ago counts, unless it's of this editor or of an editor of this computer whose process has ended.

void Jazz2::Editor::IEditorContext::AddChangeObserver(const std::shared_ptr<ChangeObserver>& observer) pure virtual

Tells a function about every change of the level being edited, all of it changes when another level is opened.

Only a weak reference is kept, the function is called as long as its owner keeps it.