From 5e6f296c56db04ff48873d6c91744a2f5657d22e Mon Sep 17 00:00:00 2001 From: Peaceultime Date: Wed, 23 Apr 2025 23:06:15 +0200 Subject: [PATCH] Add character duplication, fix prelevel unselect and ability points calculation --- db.sqlite | Bin 614400 -> 614400 bytes db.sqlite-shm | Bin 32768 -> 32768 bytes db.sqlite-wal | Bin 12392 -> 8272 bytes pages/character/[id]/edit.client.vue | 12 +++---- pages/character/index.client.vue | 13 +++++-- server/api/character/[id]/duplicate.post.ts | 37 ++++++++++++++++++++ shared/character-config.json | 5 +-- 7 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 server/api/character/[id]/duplicate.post.ts diff --git a/db.sqlite b/db.sqlite index 502978611997e8e6d32510fa5245cde919a3b742..a3b8409113488f4a5b7fdedc6ea7ef5b5fd773f0 100644 GIT binary patch delta 328 zcmZoTpxSUib;GMTrjY-e-^2+jg6RMCU*#FOn!nE9{&ha1$OHCfwswAVrc;|01$HqB zw_9zv&nr_?8q&;1}k12{DC~2Xj15u=;V>rE{kI9P#tYcpvlk@cF9ZY=F z|MxLjY;SL4TFk^2!=TRDn>~GDH%H%nnsg23Low1(@h?#+y1&CRJm<@>8 Lw=?#0{J#JIp?NvD diff --git a/db.sqlite-shm b/db.sqlite-shm index f35daa88943d506a28afe3360f7b9ab9a8282593..3c186026b741f21dd78e6e34940ca06b49647496 100644 GIT binary patch delta 161 zcmZo@U}|V!s+V}A%K!pQK+MR%AONDL0kM?rX|v~jciS?YEnm{%i5OZvtm>jtIL--$7M&^wZ_bP4v5*Wk^01t^aF#rGn diff --git a/db.sqlite-wal b/db.sqlite-wal index 8c48a87f5e3d23eed04ca13bfe33541d3d35bac3..9137541825aec6de671224cd34c7942f6005481d 100644 GIT binary patch delta 100 zcmaEnaKXXCyq>LzLHCga1A_nq2=Jd;rOKuq@cP%pvr2PMo<9o|Vgur7Fmc(%wg*cW o)~as~5O~GM6xy}fMqY+d048g8+E(glWajhD847>-nM1oY0H5L`5C8xG literal 12392 zcmeI0&5ImG6u^5oyR$pU?uZvf5QY*>3|*l=s=uNl1~CDJM2LqtSx9wt^>mTm?xnkD zNeGL&BCCj!lagb=e?btD+`V}4;yE6?7|@d!FTSdt*`1wrKfDCQYM8F+>i1s1_j|AE zH66U)**5Sm<v&hCF`!-nB)s30MW2oGJBY?27meUGI)7)&L^#t0NKd2*31EN#-lqP$$0d}qmN8m$_3-=P>yTx(59lI06*n3 zSVk*RuTyE+R(2hAcGa1vGXjhD+M0=2S=5baMvW+o;}zi1;DT~>$^}Qd6ip0{DpA&= zxqX~9r8Q;Ek?sJUhF6Dbqa(l^^a|{WqTzWihP;scr+L85jrumrW~R--K}>Db%D=j) zcrk3U{k9G&%?78krn1$dQqJ1eIGy$+|MsK+YzS28*iZuS_5mnr0VpVJ5F!5G@-h7?9LL@))yCbZJo5X zq7&8D^Zl!^My?l^Z<>8}8vgdr4$Cq*d+yklaD36t=22}a`?i?JT#RjNIB7Yesou61 z3TW?Z0Y?{e+r|F5DJdM2rZn3IjyCJ54(G$ZYYu|8+wJE%-8zmlrFQYDzCGIsR2Sac znFj67cE~mXp+e(U{ounlmzRtey4$sJmBM!2zs7Eka(-v>`eFae4ep3qIk-2?_J-M&(ku#Ho2CJ_! K!m9jKa^`O{>`L7L diff --git a/pages/character/[id]/edit.client.vue b/pages/character/[id]/edit.client.vue index 3ea156a..65da917 100644 --- a/pages/character/[id]/edit.client.vue +++ b/pages/character/[id]/edit.client.vue @@ -85,7 +85,7 @@ const trainingSpent = computed(() => Object.values(maxTraining.value).reduce((p, const modifiers = computed(() => Object.entries(maxTraining.value).reduce((p, v) => { p[v[0] as MainStat] = Math.floor(v[1] / 3) + (data.value.progress.modifiers ? (data.value.progress.modifiers[v[0] as MainStat] ?? 0) : 0); return p; }, {} as Record)) const modifierPoints = computed(() => (selectedRaceOptions.value ? selectedRaceOptions.value.reduce((p, v) => p + (v?.modifier ?? 0), 0) : 0) + training.value.reduce((p, v) => p + v[1].reduce((_p, _v) => _p + (_v?.modifier ?? 0), 0), 0)); const modifierSpent = computed(() => Object.values(data.value.progress.modifiers ?? {}).reduce((p, v) => p + v, 0)); -const abilityPoints = computed(() => training.value.flatMap(e => e[1].filter(_e => _e.ability !== undefined)).reduce((p, v) => p + v.ability!, 0)); +const abilityPoints = computed(() => (selectedRaceOptions.value ? selectedRaceOptions.value.reduce((p, v) => p + (v?.abilities ?? 0), 0) : 0) + training.value.flatMap(e => e[1].filter(_e => _e.ability !== undefined)).reduce((p, v) => p + v.ability!, 0)); const abilityMax = computed(() => Object.entries(characterConfig.abilities).reduce((p, v) => { p[v[0] as Ability] = abilitySpecialFeatures("max", data.value.progress.training.curiosity, Math.floor(maxTraining.value[v[1].max[0]] / 3) + Math.floor(maxTraining.value[v[1].max[1]] / 3)); return p; }, {} as Record)); const abilitySpent = computed(() => Object.values(data.value.progress.abilities ?? {}).reduce((p, v) => p + v[0], 0)); @@ -119,9 +119,9 @@ function selectRaceOption(level: Level, choice: number) return; } - if(character.progress.race.progress.some(e => e[0] === level)) + if(character.progress.race.progress.some(e => e[0] == level)) { - character.progress.race.progress.splice(character.progress.race.progress.findIndex(e => e[0] === level), 1, [level, choice]); + character.progress.race.progress.splice(character.progress.race.progress.findIndex(e => e[0] == level), 1, [level, choice]); } else { @@ -143,9 +143,9 @@ function switchTrainingOption(stat: MainStat, level: TrainingLevel, choice: numb return; } - if(character.progress.training[stat].some(e => e[0] === level)) + if(character.progress.training[stat].some(e => e[0] == level)) { - if(character.progress.training[stat].some(e => e[0] === level && e[1] === choice)) + if(character.progress.training[stat].some(e => e[0] == level && e[1] === choice)) { for(let i = 15; i >= level; i --) //Invalidate higher levels { @@ -155,7 +155,7 @@ function switchTrainingOption(stat: MainStat, level: TrainingLevel, choice: numb } } else - character.progress.training[stat].splice(character.progress.training[stat].findIndex(e => e[0] === level), 1, [level, choice]); + character.progress.training[stat].splice(character.progress.training[stat].findIndex(e => e[0] == level), 1, [level, choice]); } else if(trainingPoints.value && trainingPoints.value > 0) { diff --git a/pages/character/index.client.vue b/pages/character/index.client.vue index 2bd22d5..4c12977 100644 --- a/pages/character/index.client.vue +++ b/pages/character/index.client.vue @@ -19,6 +19,14 @@ async function deleteCharacter(id: number) add({ content: 'Personnage supprimé', type: 'info', duration: 25000, timer: true, }); characters.value = characters.value?.filter(e => e.id !== id); } +async function duplicateCharacter(id: number) +{ + loading.value = true; + const newId = await useRequestFetch()(`/api/character/${id}/duplicate`, { method: 'post' }); + loading.value = false; + add({ content: 'Personnage dupliqué', type: 'info', duration: 25000, timer: true, }); + useRouter().push({ name: 'character-id', params: { id: newId } }); +}