MapHistory beta
Class of @v12-engine/editor
export declare class MapHistoryThe history of a map being edited: every change as an operation that can be undone and done again.
A change is made between begin and commit. Before anything of the map is changed, the history is told what is about to be: a thing of a list (touch, by its collection: touch('objects', id, object)), a value (field, look, data), a layer (layer), or all of the map (whole); it keeps how that was, and on commit compares and keeps the difference as one operation. What it is not told of is in no step: what the editor keeps of its own in the map's data (what is hidden, the groups) is written without it, and no undo puts it back. cancel puts everything back instead, as if nothing had begun. Changes begun inside a change are part of it: a drag is one operation however many moves it is made of. A game's own area of the map (MapAreaDef) tells it of its changes the same way (doc.history.data('td.waves'))
Members
constructor
constructor(map: GameMap);Constructs a new instance of the MapHistory class
begin
begin(name: string): void;Begins a change, or joins the one being made: the name of the outermost is the one kept
bytes
get bytes(): number;About how many bytes the steps kept hold (operationBytes), done and undone
cancel
cancel(): Operation | null;Puts back everything the change being made has touched, and forgets it. Returns what it had changed, if anything
canRedo
get canRedo(): boolean;Whether there is a step to do again
canUndo
get canUndo(): boolean;Whether there is a step to take back
commit
commit(name?: string): Operation | null;Ends a change. The outermost one becomes an operation of the history, and is returned; nothing is, when nothing is different after all. A name given here is the one kept: for what is only known at the end, like how far
data
data(key: string): void;A key of the map's data about to change (GameMap.data): that key alone is kept, whatever else the data holds
field
field(field: MapField): void;What the map says of itself, about to change: one field of it (MapField)
layer
layer(layer: LayerName): void;Keeps how the layer was before the first change to it in a step, so the step can take it back
limit
limit: number;How many steps are kept, at most: the oldest go first. Fewer than are kept now lets go of those at once
look
look(part: LookField): void;A part of the map's look about to change (LookField): the sky, the mist, the map's own grounds...
maxBytes
maxBytes: number;About how many bytes are kept, at most, in the steps done and undone: the oldest go first, the last always kept
names
get names(): {
undo: string[];
redo: string[];
};What there is to undo and to do again, by name, the nearest first
open
get open(): boolean;Whether a change is being made
position
get position(): number;Where the history stands: the mark of the last step done, with none the mark of the last one let go of (0 if none was). It moves with every step made, merged into or undone, and comes back to what it was when the steps are undone or redone back to there: what tells a map saved at one point from the same map after changes since (EditorMapFiles.dirty)
redo
redo(): Operation | null;Does again what was last taken back
step
step(step: OwnStep): void;A step of the game's own (OwnStep): done now, and part of the change being made, or a step of the history by itself. One with the merge key of the step before it, each alone, is folded into it: a drag is one step
touch
touch(kind: PatchKind, id: number, now: {
id: number;
} | undefined): void;A thing of a list about to change (PatchKind: a kind of thing on the map by its collection, the players, the cameras, the instances of prefabs): now is the thing as it is, or nothing for one about to be made
trim
trim(): void;Lets go of the steps past the limit, in steps and in bytes
undo
undo(): Operation | null;Takes the last operation back. A change that is still being made is cancelled instead. Returns what was taken back
watch
watch(watcher: (operation: Operation, how: OperationHow) => void): () => void;Told of each operation as it changes the map: made (done), taken back (undone), done again (redone), or a change being made put back as it was (cancelled); after the map is as the operation leaves it. Gives back what stops it. One that throws is not a reason for the operation to fail
whole
whole(): void;All of the map is about to change: kept whole, as is what it becomes. A resize, a heightmap of another size