fix(state): force species selection to conform to template species options

This commit is contained in:
lew 2026-03-24 01:45:39 +00:00
parent 14df227397
commit 48f8b46827

View file

@ -35,6 +35,9 @@ export const roster = {
async migrateToPreset(char: Character, preset: Template) {
migrateData(char, preset);
if (preset.species?.length === 1) {
char.data[slugify('Species')] = preset.species[0];
}
char.template = $state.snapshot(preset);
await saveCharacter($state.snapshot(char));
},
@ -62,10 +65,14 @@ export const roster = {
},
async create(template: Template, data: Record<string, unknown> = {}) {
const initial: Record<string, unknown> = { ...data };
if (template.species?.length === 1) {
initial[slugify('Species')] ??= template.species[0];
}
const char: Character = {
id: crypto.randomUUID(),
template: $state.snapshot(template),
data: { ...data }
data: initial
};
characters.push(char);
activeId = char.id;