123456789101112131415161718192021222324252627282930313233343536373839 |
- class HistoryHandler
- {
- #history;
-
- constructor()
- {
- this.#history = [];
- }
-
- restore()
- {
- if (this.empty()) return;
-
- let lastAction = this.#history.pop();
-
- for (let i = 0; i < lastAction.times; i++)
- {
- let color = lastAction.targetTube.removeColorLayer();
- lastAction.sourceTube.addColorLayer(color);
- }
- }
-
- empty()
- {
- return this.#history.length == 0;
- }
-
- size()
- {
- return this.#history.length;
- }
-
- log(_source, _target, _times)
- {
- let historyItem = new HistoryItem(_source, _target, _times);
-
- this.#history.push(historyItem);
- }
- }
|