This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
SA3/hw6/Claudio_Maggioni/public/scripts/undo.js
2019-10-28 15:01:43 +01:00

37 lines
723 B
JavaScript

// vim: set ts=2 sw=2 et tw=80:
const history = {
paths: []
}
history.pop = () => {
if (history.paths.length == 0) return;
return history.paths.pop();
};
history.initializeNewPath = () => {
history.paths.push([]);
};
history.push = (stroke) => {
if (!stroke || !stroke instanceof Stroke) {
throw new Error(JSON.stringify(stroke) + ' is not a Stroke instance');
}
history.paths[history.paths.length - 1].push(stroke);
return history.paths[history.paths.length - 1];
}
history.clear = () => {
history.paths = [];
};
class Stroke {
constructor(brushName, strokeStyle, x, y) {
this.brushName = brushName;
this.strokeStyle = strokeStyle;
this.offsetX = x;
this.offsetY = y;
}
}