From da9761d187eb8ab39dd4a3143697a61053f8732b Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Tue, 4 Jun 2024 20:27:29 -0300 Subject: [PATCH 01/13] Change appearend of the "Add frame" button. --- src/components/PlayerEditor.vue | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/PlayerEditor.vue b/src/components/PlayerEditor.vue index 476b005..0ae2503 100644 --- a/src/components/PlayerEditor.vue +++ b/src/components/PlayerEditor.vue @@ -71,6 +71,19 @@ + + mdi-plus +
Add frame
+
@@ -78,18 +91,6 @@ - - mdi-plus - From dab91a211d12e7469003ac7134ab1f76a7387ed3 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Tue, 4 Jun 2024 20:53:32 -0300 Subject: [PATCH 03/13] Add button for deleting an animation. Starting to implement #55 and #77 --- src/components/PlayerEditor.vue | 47 ++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/components/PlayerEditor.vue b/src/components/PlayerEditor.vue index 4b1bb0c..d503b95 100644 --- a/src/components/PlayerEditor.vue +++ b/src/components/PlayerEditor.vue @@ -8,6 +8,45 @@ + + + + + + Delete this animation? + + + + mdi-check + + Yes, delete + + + + mdi-cancel + + No, don't delete + + + + + { + }; + + return {state, handleChildChange, + handleAddFrame, handleDeleteFrame, + handleAddAnimation, handleDeleteAnimation, + props}; }, }); From e49e16834d146d59366a90e7261311a0e3e00bfd Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Tue, 4 Jun 2024 21:26:28 -0300 Subject: [PATCH 04/13] Fix duplicate ids. --- src/components/PlayerEditor.vue | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/PlayerEditor.vue b/src/components/PlayerEditor.vue index d503b95..d9909e4 100644 --- a/src/components/PlayerEditor.vue +++ b/src/components/PlayerEditor.vue @@ -157,11 +157,23 @@ export default defineComponent({ components: {PixelEditor}, props: ['storageFactory', 'title', 'fgColor'], setup(props) { + const getMaxId = (elements) => { + return max(elements.map((o) => o.id))||0; + }; + const playerStorage = props.storageFactory(); const state = computed({ get() { try { - return processPlayerStorageDefaults(playerStorage); + const player = processPlayerStorageDefaults(playerStorage); + let nextId = getMaxId(player.animations); + for (const animation of player.animations) { + if (!animation.id) { + animation.id = nextId; + nextId++; + } + } + return player; } catch (e) { console.error('Error loading player 0 from local storage', e); return DEFAULT_SPRITES; @@ -180,7 +192,7 @@ export default defineComponent({ const instance = getCurrentInstance(); const handleAddFrame = () => { const frames = state.value.animations[0].frames; - const maxId = max(frames.map((o) => o.id)) || 0; + const maxId = getMaxId(frames); const newFrame = { id: maxId+1, duration: 10, @@ -209,8 +221,12 @@ export default defineComponent({ }; const handleAddAnimation = () => { - const original = state.value.animations[state.value.animations.length-1]; - state.value.animations.push(structuredClone(original)); + const newAnimation = structuredClone(state.value.animations[state.value.animations.length-1]); + state.value.animations.push({ + ...newAnimation, + id: getMaxId(state.value.animations) + 1, + }); + handleChildChange(); instance.proxy.$forceUpdate(); }; From f3e7a6bacc442193f1c648a5075a8cebc70330f2 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Tue, 4 Jun 2024 21:36:46 -0300 Subject: [PATCH 05/13] Implement animation deletion. --- src/components/PlayerEditor.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/PlayerEditor.vue b/src/components/PlayerEditor.vue index d9909e4..10aa0c7 100644 --- a/src/components/PlayerEditor.vue +++ b/src/components/PlayerEditor.vue @@ -11,6 +11,7 @@