Jazz2::Editor::SnapshotCommand class

Change of parts of a level kept as snapshots before and after it.

Used for changes too large or too varied for a dedicated command, such as adding or resizing a layer. The change is made directly on the document between Begin() and End().

Base classes

class EditCommand
Undoable change of a level being edited.

Public static functions

static auto Begin(const LevelDocument& document, SnapshotParts parts, String name, DocumentChangeKind kinds = DocumentChangeKind::None, std::int32_t layer = -1) -> std::unique_ptr<SnapshotCommand>
Takes the snapshot before a change.

Public functions

void End(const LevelDocument& document, DocumentChanges& changes)
Takes the snapshot after the change, the command can then be recorded.
void Do(LevelDocument& document, DocumentChanges& changes) override
Applies the change to the document, again after it was undone.
void Undo(LevelDocument& document, DocumentChanges& changes) override
Reverts the change.
auto GetName() const -> String override
Returns the name shown in the history.
auto GetMemoryUsage() const -> std::size_t override
Returns the memory the command takes.

Function documentation

static std::unique_ptr<SnapshotCommand> Jazz2::Editor::SnapshotCommand::Begin(const LevelDocument& document, SnapshotParts parts, String name, DocumentChangeKind kinds = DocumentChangeKind::None, std::int32_t layer = -1)

Takes the snapshot before a change.

The change is reported as changing all that the parts hold, unless kinds says what it really changes — a change of tile references only doesn't have to load the shown level again as a change of layers would. With layer, only that layer of SnapshotParts::Layers is kept, for a change of a single layer that doesn't add or remove any.

void Jazz2::Editor::SnapshotCommand::End(const LevelDocument& document, DocumentChanges& changes)

Takes the snapshot after the change, the command can then be recorded.

The document already is as the change made it, so the command is recorded by CommandHistory::Record() rather than executed, which would only put the same state back.