-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f084281
commit 2e5b1d1
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export interface HistoryEntry { | ||
obj: PIXI.DisplayObject; | ||
properties: { [id: string]: any }; | ||
} | ||
|
||
const HISTORY_LIMIT = 100; | ||
|
||
class HistoryClass { | ||
private readonly entries: HistoryEntry[] = []; | ||
private holdingEntry: HistoryEntry; | ||
|
||
// TODO change this name please | ||
public readonly onHistoryWalk = new Phaser.Signal(); | ||
|
||
public holdEntry(entry: HistoryEntry) { this.holdingEntry = entry; } | ||
public cancel() { this.holdingEntry = null; } | ||
|
||
public commit() { | ||
if (!this.holdingEntry) return; | ||
if (this.entries.length === HISTORY_LIMIT) | ||
this.entries.shift(); | ||
this.entries.push(this.holdingEntry); | ||
this.holdingEntry = null; | ||
} | ||
|
||
public undo() { | ||
if (this.entries.length === 0) return; | ||
const entry = this.entries.pop(); | ||
Object.keys(entry.properties) | ||
.forEach(k => entry.obj[k] = entry.properties[k]); | ||
entry.obj.updateTransform(); | ||
this.onHistoryWalk.dispatch(entry); | ||
} | ||
} | ||
|
||
export const History = new HistoryClass(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters