added racevariant parsing
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import type {CharacterData} from "../../../../../types/CharacterJson.ts";
|
||||
import type {AttributeWithValue} from "../../../../../utils/loaders";
|
||||
import {useState, useEffect} from 'react';
|
||||
import {loadRace, loadProfession, loadAttributesWithValues} from "../../../../../utils/loaders";
|
||||
import {
|
||||
type AttributeWithValue,
|
||||
loadAttributesWithValues,
|
||||
loadProfession,
|
||||
loadRace,
|
||||
loadRaceVariant
|
||||
} from "../../../../../utils/loaders";
|
||||
import {useEffect, useState} from 'react';
|
||||
|
||||
export default function SheetHeader({jsonData}: { jsonData: CharacterData }) {
|
||||
const [raceName, setRaceName] = useState<string>(jsonData.r);
|
||||
const [raceVariantName, setRaceVariantName] = useState<string>(jsonData.rv || '');
|
||||
const [professionName, setProfessionName] = useState<string>(jsonData.p);
|
||||
const [attributes, setAttributes] = useState<AttributeWithValue[]>([]);
|
||||
|
||||
@@ -14,8 +20,9 @@ export default function SheetHeader({jsonData}: { jsonData: CharacterData }) {
|
||||
const loadData = async () => {
|
||||
try {
|
||||
// Load race and profession using the new loader functions
|
||||
const [race, profession] = await Promise.all([
|
||||
const [race, raceVariant, profession] = await Promise.all([
|
||||
loadRace(jsonData.r),
|
||||
loadRaceVariant(jsonData.rv || ''),
|
||||
loadProfession(jsonData.p)
|
||||
]);
|
||||
|
||||
@@ -24,6 +31,7 @@ export default function SheetHeader({jsonData}: { jsonData: CharacterData }) {
|
||||
|
||||
if (isMounted) {
|
||||
setRaceName(race?.name || jsonData.r);
|
||||
setRaceVariantName(raceVariant?.name|| '');
|
||||
// For profession, handle gendered name
|
||||
if (profession?.name) {
|
||||
setProfessionName(profession.name.m || profession.name.f || jsonData.p);
|
||||
@@ -47,7 +55,7 @@ export default function SheetHeader({jsonData}: { jsonData: CharacterData }) {
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, [jsonData.r, jsonData.p, jsonData.attr]);
|
||||
}, [jsonData.r, jsonData.rv, jsonData.p, jsonData.attr]);
|
||||
|
||||
console.log(jsonData)
|
||||
|
||||
@@ -62,7 +70,7 @@ export default function SheetHeader({jsonData}: { jsonData: CharacterData }) {
|
||||
</div>
|
||||
<div className="w-[30%]">
|
||||
<p className="border-b border-gray-500 font-semibold">
|
||||
{raceName}
|
||||
{raceName} {raceVariantName ? <>({raceVariantName})</> : ''}
|
||||
</p>
|
||||
<small>Spezies</small>
|
||||
</div>
|
||||
|
@@ -87,6 +87,7 @@ export interface CharacterData {
|
||||
ap: AdventurePoints;
|
||||
el: string; // Experience Level
|
||||
r: string; // Race
|
||||
rv?: string;// Race_Variant
|
||||
c: string; // Culture
|
||||
p: string; // Profession
|
||||
sex: string;
|
||||
|
@@ -49,6 +49,7 @@ import type {AnimistForce} from '../types/AnimistForce';
|
||||
// import type { RogueSpell } from '../types/RogueSpell';
|
||||
// import type { SkillGroup } from '../types/SkillGroup';
|
||||
import type {Skill} from '../types/Skill';
|
||||
import type {RaceVariant} from "../types/RaceVariant.ts";
|
||||
// import type { SocialStatuse } from '../types/SocialStatuse';
|
||||
// import type { SpecialAbilitie } from '../types/SpecialAbilitie';
|
||||
// import type { SpecialAbilityGroup } from '../types/SpecialAbilityGroup';
|
||||
@@ -136,6 +137,11 @@ export async function loadRace(id: string): Promise<Race | undefined> {
|
||||
return getItemById<Race>('Races.json', id);
|
||||
}
|
||||
|
||||
// Race_Variant loader
|
||||
export async function loadRaceVariant(id: string): Promise<RaceVariant | undefined> {
|
||||
return getItemById<RaceVariant>('RaceVariants.json', id);
|
||||
}
|
||||
|
||||
// Profession loader
|
||||
export async function loadProfession(id: string): Promise<Profession | undefined> {
|
||||
return getItemById<Profession>('Professions.json', id);
|
||||
|
Reference in New Issue
Block a user