You've already forked obsidian-visualiser
Add CharacterBuilder class to unify and compile the features
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { z } from 'zod';
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
import { characterAbilitiesTable, characterLevelingTable, characterModifiersTable, characterSpellsTable, characterTable, characterTrainingTable } from '~/db/schema';
|
||||
import { CharacterValidation, type Ability, type DoubleIndex, type MainStat, type TrainingLevel } from '~/types/character';
|
||||
import { CharacterValidation } from '~/shared/character';
|
||||
import { type Ability, type MainStat } from '~/types/character';
|
||||
|
||||
|
||||
export default defineEventHandler(async (e) => {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { eq } from 'drizzle-orm';
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
import { characterAbilitiesTable, characterLevelingTable, characterModifiersTable, characterSpellsTable, characterTable, characterTrainingTable } from '~/db/schema';
|
||||
import { CharacterValidation, type Ability, type MainStat } from '~/types/character';
|
||||
import { CharacterValidation } from '~/shared/character';
|
||||
import { type Ability, type MainStat } from '~/types/character';
|
||||
|
||||
export default defineEventHandler(async (e) => {
|
||||
const params = getRouterParam(e, "id");
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
import { defaultCharacter, type Ability, type Character, type CharacterConfig, type CompiledCharacter, type DoubleIndex, type Feature, type FeatureItem, type Level, type MainStat, type TrainingLevel, type TrainingOption } from '~/types/character';
|
||||
import { type Character, type CharacterConfig, type CompiledCharacter, type DoubleIndex, type Level, type MainStat, type TrainingLevel, type TrainingOption } from '~/types/character';
|
||||
import characterData from '#shared/character-config.json';
|
||||
import { group } from '~/shared/general.util';
|
||||
import { defaultCharacter, MAIN_STATS } from '~/shared/character';
|
||||
|
||||
export default defineCachedEventHandler(async (e) => {
|
||||
const id = getRouterParam(e, "id");
|
||||
@@ -80,7 +81,7 @@ function compileCharacter(character: Character & { username?: string }): Compile
|
||||
action: [],
|
||||
reaction: [],
|
||||
freeaction: [],
|
||||
misc: [],
|
||||
passive: [],
|
||||
},
|
||||
abilities: {
|
||||
athletics: 0,
|
||||
@@ -130,90 +131,17 @@ function compileCharacter(character: Character & { username?: string }): Compile
|
||||
magicelement: 0,
|
||||
magicinstinct: 0,
|
||||
},
|
||||
resistance: {
|
||||
stun: [0, 0],
|
||||
bleed: [0, 0],
|
||||
poison: [0, 0],
|
||||
fear: [0, 0],
|
||||
influence: [0, 0],
|
||||
charm: [0, 0],
|
||||
possesion: [0, 0],
|
||||
precision: [0, 0],
|
||||
knowledge: [0, 0],
|
||||
instinct: [0, 0]
|
||||
},
|
||||
resistance: {},//Object.fromEntries(MAIN_STATS.map(e => [e as MainStat, [0, 0]])) as Record<MainStat, [number, number]>,
|
||||
initiative: 0,
|
||||
aspect: "",
|
||||
notes: character.notes ?? "",
|
||||
};
|
||||
|
||||
features.forEach(e => e[1].forEach(_e => _e.features?.forEach(f => applyFeature(compiled, f))));
|
||||
//features.forEach(e => e[1].forEach(_e => _e.features?.forEach(f => applyFeature(compiled, f))));
|
||||
|
||||
return compiled;
|
||||
}
|
||||
function applyFeature(character: CompiledCharacter, f: FeatureItem)
|
||||
{
|
||||
switch(f.category)
|
||||
{
|
||||
case "action":
|
||||
character.features.action.push(f.text);
|
||||
|
||||
return;
|
||||
case "reaction":
|
||||
character.features.reaction.push(f.text);
|
||||
|
||||
return;
|
||||
case "freeaction":
|
||||
character.features.freeaction.push(f.text);
|
||||
|
||||
return;
|
||||
case "misc":
|
||||
character.features.misc.push(f.text);
|
||||
|
||||
return;
|
||||
case "asset":
|
||||
if(f.type === 'add')
|
||||
character[f.kind].push(f.asset);
|
||||
else
|
||||
character[f.kind] = character[f.kind].filter(e => e !== f.asset);
|
||||
|
||||
return;
|
||||
case "value":
|
||||
const path = f.property.split(".");
|
||||
const object = path.slice(0, -1).reduce((p, v) => p[v], character as any);
|
||||
|
||||
switch(f.type)
|
||||
{
|
||||
case "add":
|
||||
if(!['number'].includes(typeof object[path[path.length - 1]]))
|
||||
break;
|
||||
|
||||
object[path[path.length - 1]] += f.value;
|
||||
|
||||
break;
|
||||
case "remove":
|
||||
if(!['number'].includes(typeof object[path[path.length - 1]]))
|
||||
break;
|
||||
|
||||
object[path[path.length - 1]] -= f.value as number;
|
||||
|
||||
break;
|
||||
case "set":
|
||||
if(!['number', 'boolean'].includes(typeof object[path[path.length - 1]]))
|
||||
break;
|
||||
|
||||
object[path[path.length - 1]] = f.value;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
export function getFeaturesOf(stat: MainStat, progression: DoubleIndex<TrainingLevel>[]): TrainingOption[]
|
||||
{
|
||||
const config = characterData as CharacterConfig;
|
||||
|
||||
Reference in New Issue
Block a user