Add redirect URL when logging in, fix choices for characters not being saved

This commit is contained in:
Clément Pons
2026-01-05 17:34:42 +01:00
parent 04534b2530
commit 7021264c11
15 changed files with 50 additions and 49 deletions

View File

@@ -305,4 +305,8 @@ export class CampaignSheet
])
];
}
settings()
{
}
}

File diff suppressed because one or more lines are too long

View File

@@ -558,6 +558,7 @@ export class CharacterBuilder extends CharacterCompiler
private _content?: RedrawableHTML;
private _stepsHeader: RedrawableHTML[] = [];
private _steps: Array<BuilderTabConstructor> = [];
private _currentStep: number = 0;
private _helperText!: Text;
private id?: string;
@@ -621,12 +622,20 @@ export class CharacterBuilder extends CharacterCompiler
this._content = dom('div', { class: 'flex-1 outline-none max-w-full w-full overflow-y-auto', attributes: { id: 'characterEditorContainer' } });
this._container.appendChild(div('flex flex-1 flex-col justify-start items-center px-8 w-full h-full overflow-y-hidden', [
div("flex w-full flex-row gap-4 items-center justify-between px-4 bg-light-0 dark:bg-dark-0 z-20", [
div('flex flex-row gap-2', [ floater(tooltip(button(icon('radix-icons:pencil-2', { width: 16, height: 16 }), undefined, 'p-1'), 'Notes publics', 'left'), [ publicNotes.dom ], { pinned: true, events: { show: ['click'], hide: [] }, title: 'Notes publics', position: 'bottom-start' }), floater(tooltip(button(icon('radix-icons:eye-none', { width: 16, height: 16 }), undefined, 'p-1'), 'Notes privés', 'right'), [ privateNotes.dom ], { pinned: true, events: { show: ['click'], hide: [] }, title: 'Notes privés', position: 'bottom-start' }) ]), div("flex w-full flex-row gap-4 items-center justify-center relative", this._stepsHeader), div(undefined, [ tooltip(icon("radix-icons:question-mark-circled", { height: 20, width: 20 }), this._helperText, "bottom-end") ]),
div('flex flex-row gap-2', [ floater(tooltip(button(icon('radix-icons:pencil-2', { width: 16, height: 16 }), undefined, 'p-1'), 'Notes publics', 'left'), [ publicNotes.dom ], { pinned: true, events: { show: ['click'], hide: [] }, title: 'Notes publics', position: 'bottom-start' }), floater(tooltip(button(icon('radix-icons:eye-none', { width: 16, height: 16 }), undefined, 'p-1'), 'Notes privés', 'right'), [ privateNotes.dom ], { pinned: true, events: { show: ['click'], hide: [] }, title: 'Notes privés', position: 'bottom-start' }) ]), div("flex w-full flex-row gap-4 items-center justify-center relative", this._stepsHeader), div('flex flex-row gap-2', [ tooltip(button(icon("radix-icons:chevron-right", { height: 16, width: 16 }), () => this.next(), 'p-1'), 'Suivant', "bottom"), tooltip(button(icon("radix-icons:paper-plane", { height: 16, width: 16 }), () => this.save(), 'p-1'), 'Enregistrer', "bottom"), tooltip(icon("radix-icons:question-mark-circled", { height: 20, width: 20 }), this._helperText, "bottom-end") ]),
]),
this._content,
]));
}
display(step: number)
previous()
{
this.display(this._currentStep - 1);
}
next()
{
this.display(this._currentStep + 1);
}
private display(step: number)
{
if(step < 0 || step >= this._stepsHeader.length)
return;
@@ -638,15 +647,15 @@ export class CharacterBuilder extends CharacterCompiler
Toaster.add({ title: 'Erreur de validation', content: this._steps[i]!.errorMessage, type: 'error', duration: 25000, timer: true })
return;
}
else
{}
}
if(step !== 0 && this._steps.slice(0, step).some(e => !e.validate(this)))
return;
this._stepsHeader.forEach(e => e.setAttribute('data-state', 'inactive'));
this._stepsHeader[this._currentStep]!.setAttribute('data-state', 'inactive');
this._stepsHeader[step]!.setAttribute('data-state', 'active');
this._currentStep = step;
this._content?.replaceChildren(...(new this._steps[step]!(this)).dom);
this._helperText.textContent = this._steps[step]!.description;
@@ -676,7 +685,6 @@ export class CharacterBuilder extends CharacterCompiler
}
else
{
//@ts-ignore
await useRequestFetch()(`/api/character/${this._character.id}`, {
method: 'post',
body: this._character,
@@ -793,7 +801,7 @@ export class CharacterBuilder extends CharacterCompiler
if(choices.length === 0)
return;
const menu = followermenu(element, [ div('px-24 py-6 flex flex-col items-center text-light-100 dark:text-dark-100', choices.map(e => div('flex flex-row items-center', [ text(e.text), div('flex flex-col', Array(e.settings?.amount ?? 1).fill(0).map((_, i) => (
const menu = followermenu(element, [ div('px-24 py-6 flex flex-col items-center text-light-100 dark:text-dark-100', choices.map(e => div('flex flex-row items-center', [ text(e.text), div('flex flex-col gap-2', Array(e.settings?.amount ?? 1).fill(0).map((_, i) => (
select(e.options.map((_e, _i) => ({ text: _e.text, value: _i })), { defaultValue: this._character.choices![e.id] !== undefined ? this._character.choices![e.id]![i] : undefined, change: (value) => {
this._character.choices![e.id] ??= [];
this._character.choices![e.id]![i] = value;
@@ -820,7 +828,7 @@ type BuilderTabConstructor = {
description: string;
errorMessage: string;
validate(builder: CharacterBuilder): boolean;
}
}
class PeoplePicker extends BuilderTab
{
private _nameInput: HTMLInputElement;
@@ -862,7 +870,6 @@ class PeoplePicker extends BuilderTab
dom("span", { class: "md:text-base text-sm", text: "Privé ?" }),
this._visibilityInput,
]),
button(text('Suivant'), () => this._builder.display(1), 'h-[35px] px-[15px]'),
]), div('flex flex-1 gap-4 p-2 overflow-x-auto justify-center', this._options)];
this.update();
@@ -934,7 +941,6 @@ class LevelPicker extends BuilderTab
dom("span", { text: "Mana" }),
text(() => this._builder.compiled.mana),
]),
button(text('Suivant'), () => this._builder.display(2), 'h-[35px] px-[15px]'),
]), div('flex flex-col flex-1 gap-4 mx-8 my-4', this._options.flatMap(e => [...e]))];
this.update();
@@ -1023,7 +1029,6 @@ class TrainingPicker extends BuilderTab
dom("span", { text: "Mana" }),
text(() => this._builder.compiled.mana),
]),
button(text('Suivant'), () => this._builder.display(3), 'h-[35px] px-[15px]'),
]), dom('span')
]), div('flex flex-1 px-6 overflow-hidden max-w-full', [ this._statContainer ])];
@@ -1098,7 +1103,6 @@ class AbilityPicker extends BuilderTab
dom("span", { class: "md:text-base text-sm", text: "Points restantes" }),
this._pointsInput,
]),
button(text('Suivant'), () => this._builder.display(4), 'h-[35px] px-[15px]'),
]), div('flex flex-row flex-wrap justify-center items-center flex-1 gap-12 mx-8 my-4 px-48', this._options)];
this.update();
@@ -1203,7 +1207,6 @@ class AspectPicker extends BuilderTab
dom("span", { class: "md:text-base text-sm", text: "Filtrer ?" }),
filterSwitch,
]),
button(text('Enregistrer'), () => this._builder.save(), 'h-[35px] px-[15px]'),
]), div('flex flex-row flex-wrap justify-center items-center flex-1 gap-8 mx-8 my-4 px-8', this._options)];
this.update();
@@ -1631,7 +1634,7 @@ export class CharacterSheet
div("flex flex-row items-center justify-center gap-4", [
div("flex flex-row items-center justify-center gap-2", [ dom("div", { class: 'text-lg font-semibold', text: "Actions" }), proses('a', preview, [ icon('radix-icons:question-mark-circled', { width: 16, height: 16, class: 'text-light-70 dark:text-dark-70' }) ], { href: 'regles/le-combat/actions-en-combat#Actions', class: 'h-4' }) ]),
div("flex flex-1 border-t border-dashed border-light-50 dark:border-dark-50"),
div('flex flex-row items-center gap-2', [ ...Array(character.action).fill(undefined).map(e => div('border border-dashed border-light-50 dark:border-dark-50 w-5 h-5')), dom('span', { class: 'tracking-tight', text: '/ round' }) ]),
div('flex flex-row items-center gap-2', [ ...Array(3).fill(undefined).map(e => div('border border-dashed border-light-50 dark:border-dark-50 w-5 h-5')), dom('span', { class: 'tracking-tight', text: '/ round' }) ]),
]),
div('flex flex-col gap-2', [
@@ -1646,7 +1649,7 @@ export class CharacterSheet
div("flex flex-row items-center justify-center gap-4", [
div("flex flex-row items-center justify-center gap-2", [ dom("div", { class: 'text-lg font-semibold', text: "Réactions" }), proses('a', preview, [ icon('radix-icons:question-mark-circled', { width: 16, height: 16, class: 'text-light-70 dark:text-dark-70' }) ], { href: 'regles/le-combat/actions-en-combat#Réaction', class: 'h-4' }) ]),
div("flex flex-1 border-t border-dashed border-light-50 dark:border-dark-50"),
div('flex flex-row items-center gap-2', [ ...Array(character.reaction).fill(undefined).map(e => div('border border-dashed border-light-50 dark:border-dark-50 w-5 h-5')), dom('span', { class: 'tracking-tight', text: '/ round' }) ]),
div('flex flex-row items-center gap-2', [ ...Array(2).fill(undefined).map(e => div('border border-dashed border-light-50 dark:border-dark-50 w-5 h-5')), dom('span', { class: 'tracking-tight', text: '/ round' }) ]),
]),
div('flex flex-col gap-2', [
@@ -1956,18 +1959,15 @@ export class CharacterSheet
if(!id) return true;
const item = config.items[id]!;
if(enchant.restrictions?.type && item.category === enchant.restrictions.type)
{
switch(item.category)
{
case 'armor':
return enchant.restrictions.subtype ? item.type === enchant.restrictions.subtype : true;
case 'weapon':
return enchant.restrictions.subtype ? item.type.includes(enchant.restrictions.subtype) : true;
default: return true;
}
}
return true;
if(!enchant.restrictions)
return true;
if(enchant.restrictions.includes(item.category))
return true;
else if(item.category === 'armor' && enchant.restrictions.includes(`armor/${item.type}`))
return true;
else if(item.category === 'weapon' && item.type.some(e => enchant.restrictions!.includes(`weapon/${e}`)))
return true;
return false;
}
const itempower = () => current.item && config.items[current.item.id] !== undefined ? ((config.items[current.item.id]!.powercost ?? 0) + (current.item.enchantments?.reduce((_p, _v) => (config.enchantments[_v]?.power ?? 0) + _p, 0) ?? 0)) : 0;