Work in progress: CharacterSheet implementation and FeatureChoice rework

This commit is contained in:
Clément Pons
2025-09-29 17:53:41 +02:00
parent b1ac379f1a
commit 1642cd513f
13 changed files with 889 additions and 664 deletions

73
types/character.d.ts vendored
View File

@@ -1,4 +1,5 @@
import type { MAIN_STATS, ABILITIES, LEVELS, TRAINING_LEVELS, SPELL_TYPES, CATEGORIES, SPELL_ELEMENTS, ALIGNMENTS, RESISTANCES } from "#shared/character.util";
import type { Localized } from "#shared/general";
export type MainStat = typeof MAIN_STATS[number];
export type Ability = typeof ABILITIES[number];
@@ -13,14 +14,22 @@ export type Resistance = typeof RESISTANCES[number];
export type FeatureID = string;
export type i18nID = string;
export type RecursiveKeyOf<TObj extends object> = {
[TKey in keyof TObj & (string | number)]:
TObj[TKey] extends any[] ? `${TKey}` :
TObj[TKey] extends object
? `${TKey}` | `${TKey}/${RecursiveKeyOf<TObj[TKey]>}`
: `${TKey}`;
}[keyof TObj & (string | number)];
export type Character = {
id: number;
name: string;
people?: string;
name: string; //Free text
people?: string; //People ID
level: number;
aspect?: number;
notes?: string | null;
notes?: { public?: string, private?: string }; //Free text
training: Record<MainStat, Partial<Record<TrainingLevel, number>>>;
leveling: Partial<Record<Level, number>>;
@@ -38,11 +47,12 @@ export type CharacterVariables = {
exhaustion: number;
sickness: Array<{ id: string, state: number | true }>;
poisons: Array<{ id: string, state: number | true }>;
spells: string[]; //Spell ID
items: ItemState[];
};
type ItemState = {
id: string,
id: string;
amount: number;
enchantments?: [];
charges?: number;
@@ -55,11 +65,16 @@ export type CharacterConfig = {
spells: SpellConfig[];
aspects: AspectConfig[];
features: Record<FeatureID, Feature>;
enchantments: Record<string, { name: string, effect: FeatureEffect[], power: number }>; //TODO
enchantments: Record<string, EnchantementConfig>; //TODO
items: Record<string, ItemConfig>;
lists: Record<string, { id: string, name: string, [key: string]: any }[]>;
lists: Record<string, { id: string, config: ListConfig, values: Record<string, any> }>;
texts: Record<i18nID, Localized>;
};
export type EnchantementConfig = {
name: string; //TODO -> TextID
effect: Array<FeatureEquipment | FeatureValue | FeatureList>;
power: number;
}
export type ItemConfig = CommonItemConfig & (ArmorConfig | WeaponConfig | WondrousConfig | MundaneConfig);
type CommonItemConfig = {
id: string;
@@ -87,7 +102,7 @@ type WondrousConfig = {
category: 'wondrous';
name: string; //TODO -> TextID
description: i18nID;
effect: FeatureEffect[];
effect: FeatureItem[];
};
type MundaneConfig = {
category: 'mundane';
@@ -96,25 +111,25 @@ type MundaneConfig = {
};
export type SpellConfig = {
id: string;
name: string;
name: string; //TODO -> TextID
rank: 1 | 2 | 3 | 4;
type: SpellType;
cost: number;
speed: "action" | "reaction" | number;
elements: Array<SpellElement>;
effect: string;
effect: string; //TODO -> TextID
concentration: boolean;
tags?: string[];
};
export type RaceConfig = {
id: string;
name: string;
description: string;
name: string; //TODO -> TextID
description: string; //TODO -> TextID
options: Record<Level, FeatureID[]>;
};
export type AspectConfig = {
name: string;
description: string;
description: string; //TODO -> TextID
stat: MainStat | 'special';
alignment: Alignment;
magic: boolean;
@@ -122,33 +137,42 @@ export type AspectConfig = {
physic: { min: number, max: number };
mental: { min: number, max: number };
personality: { min: number, max: number };
options: FeatureEffect[];
options: FeatureItem[];
};
export type FeatureEffect = {
export type FeatureValue = {
id: FeatureID;
category: "value";
operation: "add" | "set" | "min";
property: string;
property: RecursiveKeyOf<CompiledCharacter> | 'spec' | 'ability' | 'training';
value: number | `modifier/${MainStat}` | false;
} | {
}
export type FeatureEquipment = {
id: FeatureID;
category: "value";
operation: "add" | "set" | "min";
property: 'weapon/damage' | 'armor/health' | 'armor/absorb/flat' | 'armor/absorb/percent';
value: number | `modifier/${MainStat}` | false;
}
export type FeatureList = {
id: FeatureID;
category: "list";
list: "spells" | "sickness" | "action" | "reaction" | "freeaction" | "passive";
action: "add" | "remove";
item: string;
item: string | i18nID;
extra?: any;
};
export type FeatureItem = FeatureEffect | {
export type FeatureChoice = {
id: FeatureID;
category: "choice";
text: string;
text: string; //TODO -> TextID
settings?: { //If undefined, amount is 1 by default
amount: number;
exclusive: boolean; //Disallow to pick the same option twice
};
options: Array<FeatureEffect & { text: string }>;
options: Array<{ text: string, effects: Array<FeatureValue | FeatureList> }>; //TODO -> TextID
};
export type FeatureItem = FeatureValue | FeatureList | FeatureChoice;
export type Feature = {
id: FeatureID;
description: i18nID;
@@ -199,13 +223,16 @@ export type CompiledCharacter = {
magicinstinct: number;
};
bonus: Record<string, number>; //Any special bonus goes here
bonus: {
defense: Partial<Record<MainStat, number>>;
abilities: Partial<Record<Ability, number>>;
}; //Any special bonus goes here
resistance: Record<string, number>;
modifier: Record<MainStat, number>;
abilities: Partial<Record<Ability, number>>;
level: number;
lists: { [K in Extract<FeatureEffect, { category: "list" }>["list"]]?: string[] };
lists: { [K in FeatureList['list']]?: string[] }; //string => ListItem ID
notes: string;
notes: { public: string, private: string };
};