diff --git a/components/prose/PreviewA.vue b/components/prose/PreviewA.vue index d1b0db5..5b6ed4d 100644 --- a/components/prose/PreviewA.vue +++ b/components/prose/PreviewA.vue @@ -4,7 +4,7 @@ \ No newline at end of file diff --git a/db/schema.ts b/db/schema.ts index 4a24196..2640c65 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -55,7 +55,7 @@ export const characterTable = table("character", { owner: int().notNull().references(() => usersTable.id, { onDelete: 'cascade', onUpdate: 'cascade' }), people: text().notNull(), level: int().notNull().default(1), - variables: text({ mode: 'json' }).notNull().default('{"health": 0,"mana": 0,"spells": [],"equipment": [],"exhaustion": 0,"sickness": []}'), + variables: text({ mode: 'json' }).notNull().default('{"health": 0,"mana": 0,"spells": [],"equipment": [],"exhaustion": 0,"sickness": [],"poisons": []}'), aspect: int(), notes: text(), diff --git a/pages/character/[id]/index.client.vue b/pages/character/[id]/index.client.vue index 8a712ad..b7397a8 100644 --- a/pages/character/[id]/index.client.vue +++ b/pages/character/[id]/index.client.vue @@ -2,25 +2,16 @@ import characterConfig from '#shared/character-config.json'; import { Icon } from '@iconify/vue/dist/iconify.js'; import PreviewA from '~/components/prose/PreviewA.vue'; -import { clamp } from '#shared/general.util'; +import { clamp, unifySlug } from '#shared/general.util'; import type { CompiledCharacter, SpellConfig } from '~/types/character'; import type { CharacterConfig } from '~/types/character'; -import { abilityTexts, CharacterCompiler, defaultCharacter, elementTexts, spellTypeTexts } from '#shared/character.util'; +import { abilityTexts, CharacterCompiler, CharacterSheet, defaultCharacter, elementTexts, spellTypeTexts } from '#shared/character.util'; import { getText } from '#shared/i18n'; -import { fakeA } from '#shared/proses'; +import { preview } from '#shared/proses'; import { div, dom, icon, text } from '#shared/dom.util'; import markdown from '#shared/markdown.util'; import { button, foldable } from '#shared/components.util'; import { fullblocker, tooltip } from '~/shared/floating.util'; - -const config = characterConfig as CharacterConfig; - -const id = useRouter().currentRoute.value.params.id; -const { user } = useUserSession(); - -const { data, status, error } = await useFetch(`/api/character/${id}`); -const compiler = new CharacterCompiler(data.value ?? defaultCharacter); -const character = ref(compiler.compiled); /* text-light-red dark:text-dark-red border-light-red dark:border-dark-red bg-light-red dark:bg-dark-red text-light-blue dark:text-dark-blue border-light-blue dark:border-dark-blue bg-light-blue dark:bg-dark-blue @@ -33,76 +24,26 @@ text-light-yellow dark:text-dark-yellow border-light-yellow dark:border-dark-yel text-light-purple dark:text-dark-purple border-light-purple dark:border-dark-purple bg-light-purple dark:bg-dark-purple */ -function openSpellPanel() { - const availableSpells = Object.values(config.spells).filter(spell => { - if (spell.rank === 4) return false; - if (character.value.spellranks[spell.type] < spell.rank) return false; - return true; - }); +const config = characterConfig as CharacterConfig; - const textAmount = text(character.value.variables.spells.length.toString()), textMax = text(character.value.spellslots.toString()); - const container = div("border-light-35 dark:border-dark-35 bg-light-10 dark:bg-dark-10 border-l absolute top-0 bottom-0 right-0 w-[10%] data-[state=active]:w-1/2 flex flex-col gap-4 text-light-100 dark:text-dark-100 p-8 transition-[width] transition-delay-[150ms]", [ - div("flex flex-row justify-between items-center mb-4", [ - dom("h2", { class: "text-xl font-bold", text: "Ajouter un sort" }), - div('flex flex-row gap-4 items-center', [ dom('span', { class: 'italic text-light-70 dark:text-dark-70 text-sm' }, [ textAmount, text(' / '), textMax, text(' sorts maitrisés') ]), tooltip(button(icon("radix-icons:cross-1", { width: 20, height: 20 }), () => { - setTimeout(blocker.close, 150); - container.setAttribute('data-state', 'inactive'); - }, "p-1"), "Fermer", "left") ]) - ]), - div('flex flex-col divide-y *:py-2 -my-2 overflow-y-auto', availableSpells.map(spell => { - let state = character.value.lists.spells?.includes(spell.id) ? 'given' : character.value.variables.spells.includes(spell.id) ? 'choosen' : 'empty'; - const toggleText = text(state === 'choosen' ? 'Supprimer' : state === 'given' ? 'Inné' : 'Ajouter'), toggleButton = button(toggleText, () => { - if(state === 'choosen') - { - compiler.variable('spells', character.value.variables.spells.filter(e => e !== spell.id)); - state = 'empty'; - } - else if(state === 'empty') - { - compiler.variable('spells', [...character.value.variables.spells, spell.id]); - state = 'choosen'; - } - character.value = compiler.compiled; - toggleText.textContent = state === 'choosen' ? 'Supprimer' : state === 'given' ? 'Inné' : 'Ajouter'; - textAmount.textContent = character.value.variables.spells.length.toString(); - }, "px-2 py-1 text-sm font-normal"); - toggleButton.disabled = state === 'given'; - return foldable(() => [ - markdown(spell.effect), - ], [ div("flex flex-row justify-between gap-2", [ - dom("span", { class: "text-lg font-bold", text: spell.name }), - div("flex flex-row items-center gap-6", [ - div("flex flex-row text-sm gap-2", - spell.elements.map(el => - dom("span", { - class: [`border !border-opacity-50 rounded-full !bg-opacity-20 px-2 py-px`, elementTexts[el].class], - text: elementTexts[el].text - }) - ) - ), - div("flex flex-row text-sm gap-1", [ - ...(spell.rank !== 4 ? [ - dom("span", { text: `Rang ${spell.rank}` }), - text("/"), - dom("span", { text: spellTypeTexts[spell.type] }), - text("/") - ] : []), - dom("span", { text: `${spell.cost} mana` }), - text("/"), - dom("span", { text: typeof spell.speed === "string" ? spell.speed : `${spell.speed} minutes` }) - ]), - toggleButton, - ]), - ]) ], { open: false, class: { container: "px-2 flex flex-col border-light-35 dark:border-dark-35", content: 'py-2' } }); - })) - ]); - const blocker = fullblocker([ container ], { closeWhenOutside: true }); - setTimeout(() => container.setAttribute('data-state', 'active'), 1); -} +const id = useRouter().currentRoute.value.params.id ? unifySlug(useRouter().currentRoute.value.params.id!) : undefined; +const { user } = useUserSession(); +const container = useTemplateRef('container'); + +onMounted(() => { + queueMicrotask(() => { + if(container.value && id) + { + const character = new CharacterSheet(id, user); + container.value.appendChild(character.container); + } + }); +}); \ No newline at end of file diff --git a/pages/character/list.client.vue b/pages/character/list.client.vue index daeebd2..a7d9d78 100644 --- a/pages/character/list.client.vue +++ b/pages/character/list.client.vue @@ -1,5 +1,8 @@