Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions dist/artimus.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
window.artimus = {
tools: {},
maxHistory: 10,

//Just a small performance thing to prevent un-needed function alls while copying
clipboardMagic: "H_ARTIMUS",
hexArray: [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" ],
Expand Down Expand Up @@ -352,6 +349,7 @@ window.artimus = {
"+"
],

tools: {},
tool: class {
get icon() { return artimus.unknownToolIcon; }

Expand Down Expand Up @@ -389,6 +387,26 @@ window.artimus = {
colorProperties = [];
constructive = true;
},

//History is important, and it's finally getting some TLC
maxHistory: 10,
historicalEventTypes: {
"imageChange": (workspace, data) => {
console.log(data);
}
},

historicalEvent: class {
constructor(type, data, workspace) {
this.type = type;
this.data = data;
this.workspace = workspace;
}

restoreTo() {
artimus.historicalEventTypes[this.type](this.workspace, this.data);
}
},

layer: class {
blendMode = "source-over";
Expand Down Expand Up @@ -708,7 +726,7 @@ window.artimus = {
}

//History
layerHistory = [];
history = [];
historyIndex = 0;

//CSS classes
Expand Down Expand Up @@ -2032,7 +2050,6 @@ window.artimus = {
//Now setup stuff we need/want like blitting the newly selected layer onto the editing canvas
const current = this.layers[this.#currentLayer];
this.editGL.putImageData(current.dataRaw, 0, 0);
this.layerHistory = [this.editGL.getImageData(0, 0, this.width, this.height)];

label.className = this.layerClass;
current.label.className = this.layerClass + this.layerClassSelected;
Expand Down Expand Up @@ -2289,16 +2306,12 @@ window.artimus = {
return [];
}

//Legacy history function
updateLayerHistory() {
if (this.historyIndex > 0) {
this.layerHistory.splice(0, this.historyIndex);
}

this.historyIndex = 0;
this.layerHistory.splice(0, 0, this.editGL.getImageData(0, 0, this.width, this.height));
if (this.layerHistory.length > artimus.maxHistory) {
this.layerHistory.pop();
}
this.addHistoricalEvent("imageChange", {
data: this.editGL.getImageData(0, 0, this.width, this.height),
rect: [0, 0, this.width, this.height]
});
}

transferLayerData(from, to) {
Expand Down Expand Up @@ -2473,10 +2486,10 @@ window.artimus = {
undo() {
if (this.toolFunction.undo && this.toolFunction.undo(this.editGL, this.previewGL, this.toolProperties)) return true;

if (this.historyIndex >= this.layerHistory.length - 1) return;
if (this.historyIndex >= this.history.length - 1) return;
this.historyIndex++;

this.editGL.putImageData(this.layerHistory[this.historyIndex], 0, 0);
this.editGL.putImageData(this.history[this.historyIndex], 0, 0);
this.dirty = true;

this.sendEvent("undo", { historyIndex: this.historyIndex });
Expand All @@ -2488,12 +2501,24 @@ window.artimus = {
if (this.historyIndex <= 0) return;
this.historyIndex--;

this.editGL.putImageData(this.layerHistory[this.historyIndex], 0, 0);
this.editGL.putImageData(this.history[this.historyIndex], 0, 0);
this.dirty = true;

this.sendEvent("redo", { historyIndex: this.historyIndex });
}

addHistoricalEvent(type, data) {
if (this.historyIndex > 0) {
this.history.splice(0, this.historyIndex);
}

this.historyIndex = 0;
this.history.splice(0, 0, new artimus.historicalEvent(type, data, this));
if (this.history.length > artimus.maxHistory) {
this.history.pop();
}
}

copy() {
let toCopy = [];
let imgData = {};
Expand Down Expand Up @@ -2697,7 +2722,7 @@ window.artimus = {
});

this.historyIndex = 0;
this.layerHistory = [];
this.history = [];
this.fileSystemHandle = null;

this.sendEvent("new", { width: width, height: height });
Expand Down
2 changes: 1 addition & 1 deletion site/src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
window.editor = {
version: "Γ 1.4.1",
version: "Γ 1.5.0",
bannerTitle: "Help Wanted",
bannerAuthor: "ObviousAlexC",
bannerAuthorURL: "https://ObviousStudios.dev",
Expand Down