fix(state): force species selection to conform to template species options
This commit is contained in:
parent
14df227397
commit
48f8b46827
1 changed files with 8 additions and 1 deletions
|
|
@ -35,6 +35,9 @@ export const roster = {
|
||||||
|
|
||||||
async migrateToPreset(char: Character, preset: Template) {
|
async migrateToPreset(char: Character, preset: Template) {
|
||||||
migrateData(char, preset);
|
migrateData(char, preset);
|
||||||
|
if (preset.species?.length === 1) {
|
||||||
|
char.data[slugify('Species')] = preset.species[0];
|
||||||
|
}
|
||||||
char.template = $state.snapshot(preset);
|
char.template = $state.snapshot(preset);
|
||||||
await saveCharacter($state.snapshot(char));
|
await saveCharacter($state.snapshot(char));
|
||||||
},
|
},
|
||||||
|
|
@ -62,10 +65,14 @@ export const roster = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async create(template: Template, data: Record<string, unknown> = {}) {
|
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 = {
|
const char: Character = {
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
template: $state.snapshot(template),
|
template: $state.snapshot(template),
|
||||||
data: { ...data }
|
data: initial
|
||||||
};
|
};
|
||||||
characters.push(char);
|
characters.push(char);
|
||||||
activeId = char.id;
|
activeId = char.id;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue