undo and redo with new chunked diff code

This commit is contained in:
Hugh Bord 2021-12-17 16:13:01 +10:00
parent 392fe3f0b0
commit 5ff8ad1ee6
3 changed files with 53 additions and 16 deletions

View File

@ -69,10 +69,7 @@ ASCIIBIRD is mostly usable. There are some bugs however to note at the moment. R
## Focusing on Now / Roadmap
* We can store chunked editing differences! Just need to fix up undo and redo with this new system.
* Warning to the user for width and clipping, on export
* Optimise the export code to use less chars
* More Context Menus (right click menu)
* Brushes Canvas right click

View File

@ -539,12 +539,14 @@ export const exportMirc = () => {
} else {
if (curBlock.bg === undefined && curBlock.fg !== undefined) {
pushString = `\u0003\u0003${zeroPad(curBlock.fg, 2)}`;
pushString = `\u0003${zeroPad(curBlock.fg, 2)}`;
}
if (curBlock.bg !== undefined && curBlock.fg !== undefined) {
// Asciiblaster export will check if the next char is a number and add 0 padding
// to the ,bg value, if we get that we can save some bytes on the bg char.
// if (blocks[y][x + 1].char && Number.parseInt(blocks[y][x + 1].char)) {
pushString = `\u0003${curBlock.fg},${zeroPad(curBlock.bg, 2)}`;
pushString = `\u0003${curBlock.fg},${zeroPad(curBlock.bg, 2)}`;
// } else {
// pushString = `\u0003${curBlock.fg},${curBlock.bg}`;
// }
@ -797,7 +799,7 @@ export const mergeLayers = function (blocks = null) {
store.getters.currentAsciiLayers[z] &&
store.getters.currentAsciiLayers[z].data &&
store.getters.currentAsciiLayers[z].data[y] &&
store.getters.currentAsciiLayers[z].data[y][x]
store.getters.currentAsciiLayers[z].data[y][x]
) {
if (curBlock.char === undefined) {

View File

@ -225,8 +225,15 @@ export default new Vuex.Store({
state.asciibirdMeta[state.tab].current = LZString.compressToUTF16(JSON.stringify(mergeLayers()));
let historyIndex = state.asciibirdMeta[state.tab].historyIndex;
if (payload.diff && payload.diff.new && payload.diff.new.length) {
state.asciibirdMeta[state.tab].history.push(LZString.compressToUTF16(JSON.stringify(payload.diff)))
if (state.asciibirdMeta[state.tab].history.length !== historyIndex) {
state.asciibirdMeta[state.tab].history.splice(historyIndex,state.asciibirdMeta[state.tab].history.length);
}
state.asciibirdMeta[state.tab].history.push(LZString.compressToUTF16(JSON.stringify(payload.diff)))
state.asciibirdMeta[state.tab].historyIndex = state.asciibirdMeta[state.tab].history.length;
}
},
@ -367,19 +374,50 @@ export default new Vuex.Store({
// BLOCKS
undoBlocks(state) {
// if (state.asciibirdMeta[state.tab].history.length > 1) {
let historyIndex = state.asciibirdMeta[state.tab].historyIndex;
// state.asciibirdMeta[state.tab].layers = state.asciibirdMeta[state.tab].history.pop();
// state.asciibirdMeta[state.tab].redo.push(state.asciibirdMeta[state.tab].layers);
if (state.asciibirdMeta[state.tab].history[historyIndex-1]) {
let prev = JSON.parse(LZString.decompressFromUTF16(state.asciibirdMeta[state.tab].history[
historyIndex - 1]));
// }
let tempLayers = JSON.parse(LZString.decompressFromUTF16(state.asciibirdMeta[state.tab]
.layers))
if (prev.old) {
for(let change in prev.old) {
let data = prev.old[change];
tempLayers[data.l].data[data.d.y][data.d.x] = data.d.b;
}
}
state.asciibirdMeta[state.tab].layers = LZString.compressToUTF16(JSON.stringify(
tempLayers));
state.asciibirdMeta[state.tab].historyIndex--;
}
},
redoBlocks(state) {
// if (state.asciibirdMeta[state.tab].redo.length) {
// const next = state.asciibirdMeta[state.tab].redo.pop();
// state.asciibirdMeta[state.tab].layers = next;
// state.asciibirdMeta[state.tab].history.push(next);
// }
let historyIndex = state.asciibirdMeta[state.tab].historyIndex;
if (state.asciibirdMeta[state.tab].history[historyIndex]) {
let prev = JSON.parse(LZString.decompressFromUTF16(state.asciibirdMeta[state.tab].history[
historyIndex]));
let tempLayers = JSON.parse(LZString.decompressFromUTF16(state.asciibirdMeta[state.tab]
.layers))
if (prev.new) {
for (let change in prev.new) {
let data = prev.new[change];
tempLayers[data.l].data[data.d.y][data.d.x] = data.d.b;
}
}
state.asciibirdMeta[state.tab].layers = LZString.compressToUTF16(JSON.stringify(
tempLayers));
state.asciibirdMeta[state.tab].historyIndex++;
}
},
//