Added Notes section
This commit is contained in:
@@ -24,7 +24,8 @@
|
|||||||
characterData.NegativeQualities ??= [];
|
characterData.NegativeQualities ??= [];
|
||||||
characterData.PysicalCondition ??= Defaults.PysicalCondition
|
characterData.PysicalCondition ??= Defaults.PysicalCondition
|
||||||
characterData.StunCondition ??= Defaults.StunCondition
|
characterData.StunCondition ??= Defaults.StunCondition
|
||||||
characterData.Notes ??= ""
|
characterData.Notes ??= {};
|
||||||
|
let selectedDate : any = null // YYYY-MM-DD format
|
||||||
|
|
||||||
const characterInfoTypes = {
|
const characterInfoTypes = {
|
||||||
Metatype: "text",
|
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
|
// Inventory
|
||||||
let inventory = currentCharacter?.inventory || [];
|
let inventory = currentCharacter?.inventory || [];
|
||||||
</script>
|
</script>
|
||||||
@@ -426,13 +475,40 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Notes</h2>
|
<h2>Notes</h2>
|
||||||
|
<div class="notes-controls">
|
||||||
|
<select
|
||||||
|
bind:value={selectedDate}
|
||||||
|
class="note-selector"
|
||||||
|
>
|
||||||
|
{#if noteDates.length === 0}
|
||||||
|
<option value={null}>No notes yet</option>
|
||||||
|
{:else}
|
||||||
|
{#each noteDates as date}
|
||||||
|
<option value={date}>
|
||||||
|
{formatDateForDisplay(date)}
|
||||||
|
</option>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button on:click={createNewNote} class="btn-new">
|
||||||
|
+ New Note (Today)
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{#if selectedDate !== null}
|
||||||
|
<button on:click={deleteNote} class="btn-delete">
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<textarea
|
<textarea
|
||||||
id="notes"
|
bind:value={characterData.Notes[selectedDate]}
|
||||||
bind:value={characterData.Notes}
|
|
||||||
rows="10"
|
rows="10"
|
||||||
cols="100"
|
cols="100"
|
||||||
placeholder="Write your character notes here..."
|
placeholder={noteDates.length === 0 ? "Click 'New Note' to start..." : "Write your session notes here..."}
|
||||||
|
disabled={selectedDate === null}
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace shadowrun {
|
|||||||
Bioware = 8,
|
Bioware = 8,
|
||||||
PositiveQualities = 9,
|
PositiveQualities = 9,
|
||||||
NegativeQualities = 10,
|
NegativeQualities = 10,
|
||||||
|
Notes = 11,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ShadowrunCharacter {
|
struct ShadowrunCharacter {
|
||||||
|
|||||||
Reference in New Issue
Block a user