diff --git a/frontend/src/lib/shadorwun/character.svelte b/frontend/src/lib/shadorwun/character.svelte index 40025cb..1811dab 100644 --- a/frontend/src/lib/shadorwun/character.svelte +++ b/frontend/src/lib/shadorwun/character.svelte @@ -24,7 +24,8 @@ characterData.NegativeQualities ??= []; characterData.PysicalCondition ??= Defaults.PysicalCondition characterData.StunCondition ??= Defaults.StunCondition - characterData.Notes ??= "" + characterData.Notes ??= {}; + let selectedDate : any = null // YYYY-MM-DD format const characterInfoTypes = { Metatype: "text", @@ -69,6 +70,54 @@ }); } + // Get sorted list of note dates + $: noteDates = Object.keys(characterData.Notes).sort((a, b) => + new Date(b) - new Date(a) // Most recent first + ); + + // Initialize with most recent note or null + $: if (noteDates.length > 0 && selectedDate === null) { + selectedDate = noteDates[0]; + } + + function createNewNote() { + const today = new Date().toISOString().split('T')[0]; // YYYY-MM-DD format + + // Check if note for today already exists + if (characterData.Notes[today]) { + alert('A note for today already exists!'); + selectedDate = today; + return; + } + + characterData.Notes[today] = ''; + selectedDate = today; + } + + function deleteNote() { + if (selectedDate !== null && confirm('Delete this note?')) { + delete characterData.Notes[selectedDate]; + characterData.Notes = characterData.Notes; // Trigger reactivity + + const remaining = Object.keys(characterData.Notes); + if (remaining.length > 0) { + selectedDate = remaining.sort((a, b) => new Date(b) - new Date(a))[0]; + } else { + selectedDate = null; + } + } + } + + function formatDateForDisplay(dateStr : any) { + const date = new Date(dateStr); + return date.toLocaleDateString('en-US', { + weekday: 'short', + year: 'numeric', + month: 'short', + day: 'numeric' + }); + } + // Inventory let inventory = currentCharacter?.inventory || []; @@ -426,14 +475,41 @@

Notes

+
+ + + + + {#if selectedDate !== null} + + {/if} +
+
- +
diff --git a/src/shadowrun/ShadowrunDb.hpp b/src/shadowrun/ShadowrunDb.hpp index d99576e..4c30e49 100644 --- a/src/shadowrun/ShadowrunDb.hpp +++ b/src/shadowrun/ShadowrunDb.hpp @@ -23,6 +23,7 @@ namespace shadowrun { Bioware = 8, PositiveQualities = 9, NegativeQualities = 10, + Notes = 11, }; struct ShadowrunCharacter {