Finalize CharacterBuilder

This commit is contained in:
Clément Pons
2025-07-22 17:46:16 +02:00
parent 3ef98df5d2
commit 7d6f9162ed
13 changed files with 1830 additions and 145 deletions

View File

@@ -1,6 +1,5 @@
import { relations } from 'drizzle-orm';
import { int, text, sqliteTable as table, primaryKey, blob } from 'drizzle-orm/sqlite-core';
import { ABILITIES, MAIN_STATS } from '../shared/character.util';
export const usersTable = table("users", {
id: int().primaryKey({ autoIncrement: true }),
@@ -66,7 +65,7 @@ export const characterTable = table("character", {
export const characterTrainingTable = table("character_training", {
character: int().notNull().references(() => characterTable.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
stat: text({ enum: MAIN_STATS }).notNull(),
stat: text({ enum: ["strength","dexterity","constitution","intelligence","curiosity","charisma","psyche"] }).notNull(),
level: int().notNull(),
choice: int().notNull(),
}, (table) => [primaryKey({ columns: [table.character, table.stat, table.level] })]);
@@ -79,14 +78,14 @@ export const characterLevelingTable = table("character_leveling", {
export const characterAbilitiesTable = table("character_abilities", {
character: int().notNull().references(() => characterTable.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
ability: text({ enum: ABILITIES }).notNull(),
ability: text({ enum: ["athletics","acrobatics","intimidation","sleightofhand","stealth","survival","investigation","history","religion","arcana","understanding","perception","performance","medecine","persuasion","animalhandling","deception"] }).notNull(),
value: int().notNull().default(0),
max: int().notNull().default(0),
}, (table) => [primaryKey({ columns: [table.character, table.ability] })]);
export const characterModifiersTable = table("character_modifiers", {
character: int().notNull().references(() => characterTable.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
modifier: text({ enum: MAIN_STATS }).notNull(),
modifier: text({ enum: ["strength","dexterity","constitution","intelligence","curiosity","charisma","psyche"] }).notNull(),
value: int().notNull().default(0),
}, (table) => [primaryKey({ columns: [table.character, table.modifier] })]);
@@ -95,6 +94,12 @@ export const characterSpellsTable = table("character_spell", {
value: text().notNull(),
}, (table) => [primaryKey({ columns: [table.character, table.value] })]);
export const characterChoicesTable = table("character_choices", {
character: int().notNull().references(() => characterTable.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
id: text().notNull(),
choice: int().notNull(),
}, (table) => [primaryKey({ columns: [table.character, table.id, table.choice] })]);
export const usersRelation = relations(usersTable, ({ one, many }) => ({
data: one(usersDataTable, { fields: [usersTable.id], references: [usersDataTable.id], }),
session: many(userSessionsTable),
@@ -119,7 +124,8 @@ export const characterRelation = relations(characterTable, ({ one, many }) => ({
levels: many(characterLevelingTable),
abilities: many(characterAbilitiesTable),
modifiers: many(characterModifiersTable),
spells: many(characterSpellsTable)
spells: many(characterSpellsTable),
choices: many(characterChoicesTable)
}));
export const characterTrainingRelation = relations(characterTrainingTable, ({ one }) => ({
@@ -136,4 +142,7 @@ export const characterModifierRelation = relations(characterModifiersTable, ({ o
}));
export const characterSpellsRelation = relations(characterSpellsTable, ({ one }) => ({
character: one(characterTable, { fields: [characterSpellsTable.character], references: [characterTable.id] })
}));
export const characterChoicesRelation = relations(characterChoicesTable, ({ one }) => ({
character: one(characterTable, { fields: [characterChoicesTable.character], references: [characterTable.id] })
}));