diff --git a/src/core/savegame/index.js b/src/core/savegame/index.js index 9619ac3..8dd334c 100644 --- a/src/core/savegame/index.js +++ b/src/core/savegame/index.js @@ -244,14 +244,16 @@ export async function updateSaveSlot(slotNumber, updates) { } } - // Apply character update + // Apply character update(s) if (updates.character) { - const { characterIndex, field, value } = updates.character; - const charSerializer = createSerializer(newBuffer); - const result = charSerializer.updateCharacter(characterIndex, field, value); - if (result) { - newBuffer = result; - modified = true; + const entries = Array.isArray(updates.character) ? updates.character : [updates.character]; + for (const { characterIndex, field, value } of entries) { + const charSerializer = createSerializer(newBuffer); + const result = charSerializer.updateCharacter(characterIndex, field, value); + if (result) { + newBuffer = result; + modified = true; + } } } diff --git a/src/lib/save-editor/ActorEditor.svelte b/src/lib/save-editor/ActorEditor.svelte index 586c2e8..99b6e30 100644 --- a/src/lib/save-editor/ActorEditor.svelte +++ b/src/lib/save-editor/ActorEditor.svelte @@ -5,6 +5,7 @@ import { ActorInfoInit, ActorPart } from '../../core/savegame/actorConstants.js'; import { Actor } from '../../core/savegame/constants.js'; import NavButton from '../NavButton.svelte'; + import ResetButton from '../ResetButton.svelte'; import EditorTooltip from '../EditorTooltip.svelte'; export let slot; @@ -26,6 +27,18 @@ $: actorName = actorInfo?.name || 'Unknown'; $: charState = slot?.characters?.[actorIndex]; + $: isDefault = actorInfo && charState && + charState.sound === actorInfo.sound && + charState.move === actorInfo.move && + charState.mood === actorInfo.mood && + charState.hatPartNameIndex === actorInfo.parts[1].partNameIndex && + charState.hatNameIndex === actorInfo.parts[1].nameIndex && + charState.infogronNameIndex === actorInfo.parts[2].nameIndex && + charState.armlftNameIndex === actorInfo.parts[4].nameIndex && + charState.armrtNameIndex === actorInfo.parts[5].nameIndex && + charState.leglftNameIndex === actorInfo.parts[8].nameIndex && + charState.legrtNameIndex === actorInfo.parts[9].nameIndex; + function actorKey(slotNumber, idx, cs) { return `${slotNumber}-${idx}-${cs.hatPartNameIndex}-${cs.hatNameIndex}-${cs.infogronNameIndex}-${cs.armlftNameIndex}-${cs.armrtNameIndex}-${cs.leglftNameIndex}-${cs.legrtNameIndex}-${cs.move}-${cs.sound}`; } @@ -176,6 +189,25 @@ character: { characterIndex: actorIndex, field: 'mood', value: nextMood } }); } + + function resetActor() { + const i = actorIndex; + const p = actorInfo.parts; + onUpdate({ + character: [ + { characterIndex: i, field: 'sound', value: actorInfo.sound }, + { characterIndex: i, field: 'move', value: actorInfo.move }, + { characterIndex: i, field: 'mood', value: actorInfo.mood }, + { characterIndex: i, field: 'hatPartNameIndex', value: p[1].partNameIndex }, + { characterIndex: i, field: 'hatNameIndex', value: p[1].nameIndex }, + { characterIndex: i, field: 'infogronNameIndex', value: p[2].nameIndex }, + { characterIndex: i, field: 'armlftNameIndex', value: p[4].nameIndex }, + { characterIndex: i, field: 'armrtNameIndex', value: p[5].nameIndex }, + { characterIndex: i, field: 'leglftNameIndex', value: p[8].nameIndex }, + { characterIndex: i, field: 'legrtNameIndex', value: p[9].nameIndex } + ] + }); + } @@ -210,6 +242,12 @@ + + + {#if !isDefault && !loading && !error} + + {/if} +