Initial commit

This commit is contained in:
2026-09-22 16:27:53 +02:00
commit 9b29dc8253
70 changed files with 14726 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import type { Ability, CharacterClass } from '../api/types';
// Mirrors backend/src/game/data/classes.js spellcastingAbility column — used
// only to decide whether the builder's equipment step offers spell picks.
export const CLASS_SPELLCASTING_ABILITY: Record<CharacterClass, Ability | null> = {
FIGHTER: null,
BARBARIAN: null,
ROGUE: null,
RANGER: 'WIS',
WIZARD: 'INT',
SORCERER: 'CHA',
CLERIC: 'WIS',
PALADIN: 'CHA',
BARD: 'CHA',
WARLOCK: 'CHA',
DRUID: 'WIS',
MONK: null,
};
+78
View File
@@ -0,0 +1,78 @@
export const SPECIES_LABELS: Record<string, string> = {
HUMAN: 'Human',
HALF_ELF: 'Half-Elf',
ELF: 'Elf',
GNOME: 'Gnome',
DWARF: 'Dwarf',
HALFLING: 'Halfling',
DRAGONBORN: 'Dragonborn',
TIEFLING: 'Tiefling',
HALF_ORC: 'Half-Orc',
ORC: 'Orc',
};
export const CLASS_LABELS: Record<string, string> = {
FIGHTER: 'Fighter',
BARBARIAN: 'Barbarian',
ROGUE: 'Rogue',
RANGER: 'Ranger',
WIZARD: 'Wizard',
SORCERER: 'Sorcerer',
CLERIC: 'Cleric',
PALADIN: 'Paladin',
BARD: 'Bard',
WARLOCK: 'Warlock',
DRUID: 'Druid',
MONK: 'Monk',
};
export const SKILL_LABELS: Record<string, string> = {
ACROBATICS: 'Acrobatics',
ANIMAL_HANDLING: 'Animal Handling',
ARCANA: 'Arcana',
ATHLETICS: 'Athletics',
DECEPTION: 'Deception',
HISTORY: 'History',
INSIGHT: 'Insight',
INTIMIDATION: 'Intimidation',
INVESTIGATION: 'Investigation',
MEDICINE: 'Medicine',
NATURE: 'Nature',
PERCEPTION: 'Perception',
PERFORMANCE: 'Performance',
PERSUASION: 'Persuasion',
RELIGION: 'Religion',
SLEIGHT_OF_HAND: 'Sleight of Hand',
STEALTH: 'Stealth',
SURVIVAL: 'Survival',
};
export const ABILITY_LABELS: Record<string, string> = {
STR: 'Strength',
DEX: 'Dexterity',
CON: 'Constitution',
INT: 'Intelligence',
WIS: 'Wisdom',
CHA: 'Charisma',
};
export function fmtMod(mod: number): string {
return mod >= 0 ? `+${mod}` : `${mod}`;
}
export function extractErrorMessage(err: unknown): string {
const anyErr = err as { response?: { data?: { error?: unknown } } };
const apiError = anyErr?.response?.data?.error;
if (typeof apiError === 'string') return apiError;
if (apiError && typeof apiError === 'object') {
const flat = apiError as { formErrors?: string[]; fieldErrors?: Record<string, string[]> };
const messages = [
...(flat.formErrors || []),
...Object.values(flat.fieldErrors || {}).flat(),
];
if (messages.length) return messages.join(', ');
return JSON.stringify(apiError);
}
if (err instanceof Error) return err.message;
return 'Something went wrong.';
}
+28
View File
@@ -0,0 +1,28 @@
import type { Ability, Species } from '../api/types';
// Mirrors backend/src/game/data/species.js — used only to preview the running
// math live during the builder. The server recomputes authoritatively at
// finalize, so this duplication is display-only and never gameplay-deciding.
export const SPECIES_ABILITY_BONUSES: Record<Species, Partial<Record<Ability, number>>> = {
HUMAN: { STR: 1, DEX: 1, CON: 1, INT: 1, WIS: 1, CHA: 1 },
HALF_ELF: { CHA: 2 },
ELF: { DEX: 2 },
GNOME: { INT: 2 },
DWARF: { CON: 2 },
HALFLING: { DEX: 2 },
DRAGONBORN: { STR: 2, CHA: 1 },
TIEFLING: { INT: 1, CHA: 2 },
HALF_ORC: { STR: 2, CON: 1 },
ORC: { STR: 2, CON: 1 },
};
export function speciesBonusFor(species: Species | null, ability: Ability, halfElfBonusAbilities: Ability[] = []): number {
if (!species) return 0;
let bonus = SPECIES_ABILITY_BONUSES[species][ability] || 0;
if (species === 'HALF_ELF' && halfElfBonusAbilities.includes(ability)) bonus += 1;
return bonus;
}
export function abilityModifier(score: number): number {
return Math.floor((score - 10) / 2);
}