Skip to content

Commit

Permalink
Merge pull request #647 from cynicaloptimist/development
Browse files Browse the repository at this point in the history
3.11.4 Bugfixes & v2 Imports
  • Loading branch information
cynicaloptimist authored Aug 27, 2024
2 parents 0cb3328 + 50c07c2 commit 48d138c
Show file tree
Hide file tree
Showing 8 changed files with 2,337 additions and 2,047 deletions.
362 changes: 187 additions & 175 deletions client/Components/StatBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,201 +19,213 @@ export function StatBlockComponent(props: StatBlockProps) {
const textEnricher = useContext(TextEnricherContext);
const statBlock = props.statBlock;

const modifierTypes = [
{ name: "Saves", data: statBlock.Saves },
{ name: "Skills", data: statBlock.Skills }
];

const keywordSetTypes = [
{ name: "Senses", data: statBlock.Senses },
{ name: "Damage Vulnerabilities", data: statBlock.DamageVulnerabilities },
{ name: "Damage Resistances", data: statBlock.DamageResistances },
{ name: "Damage Immunities", data: statBlock.DamageImmunities },
{ name: "Condition Immunities", data: statBlock.ConditionImmunities },
{ name: "Languages", data: statBlock.Languages }
];

const powerTypes = [
{ name: "Traits", data: statBlock.Traits },
{ name: "Actions", data: statBlock.Actions },
{ name: "Bonus Actions", data: statBlock.BonusActions },
{ name: "Reactions", data: statBlock.Reactions },
{ name: "Legendary Actions", data: statBlock.LegendaryActions },
{ name: "Mythic Actions", data: statBlock.MythicActions }
];

const headerEntries = (
<>
{props.hideName || (
<StatBlockHeader
name={statBlock.Name}
imageUrl={statBlock.ImageURL}
source={statBlock.Source}
type={statBlock.Type}
/>
)}

<hr />
</>
);

const statEntries = (
<>
<div className="AC">
<span className="stat-label">Armor Class</span>
<span className="stat-value">{statBlock.AC.Value}</span>
<span className="notes">
{textEnricher.EnrichText(statBlock.AC.Notes)}
</span>
</div>
try {
const modifierTypes = [
{ name: "Saves", data: statBlock.Saves },
{ name: "Skills", data: statBlock.Skills }
];

const keywordSetTypes = [
{ name: "Senses", data: statBlock.Senses },
{ name: "Damage Vulnerabilities", data: statBlock.DamageVulnerabilities },
{ name: "Damage Resistances", data: statBlock.DamageResistances },
{ name: "Damage Immunities", data: statBlock.DamageImmunities },
{ name: "Condition Immunities", data: statBlock.ConditionImmunities },
{ name: "Languages", data: statBlock.Languages }
];

const powerTypes = [
{ name: "Traits", data: statBlock.Traits },
{ name: "Actions", data: statBlock.Actions },
{ name: "Bonus Actions", data: statBlock.BonusActions },
{ name: "Reactions", data: statBlock.Reactions },
{ name: "Legendary Actions", data: statBlock.LegendaryActions },
{ name: "Mythic Actions", data: statBlock.MythicActions }
];

const headerEntries = (
<>
{props.hideName || (
<StatBlockHeader
name={statBlock.Name}
imageUrl={statBlock.ImageURL}
source={statBlock.Source}
type={statBlock.Type}
/>
)}

<div className="HP">
<span className="stat-label">Hit Points</span>
<span className="stat-value">{statBlock.HP.Value}</span>
<span className="notes">
{textEnricher.EnrichText(statBlock.HP.Notes)}
</span>
</div>
<hr />
</>
);

<div className="speed">
<span className="stat-label">Speed</span>
<span className="stat-value">
{statBlock.Speed.map((speed, i) => (
<span className="stat-value__item" key={"stat-value__speed-" + i}>
{speed}
</span>
))}
</span>
</div>
const statEntries = (
<>
<div className="AC">
<span className="stat-label">Armor Class</span>
<span className="stat-value">{statBlock.AC.Value}</span>
<span className="notes">
{textEnricher.EnrichText(statBlock.AC.Notes)}
</span>
</div>

<div className="HP">
<span className="stat-label">Hit Points</span>
<span className="stat-value">{statBlock.HP.Value}</span>
<span className="notes">
{textEnricher.EnrichText(statBlock.HP.Notes)}
</span>
</div>

<div className="Abilities">
{Object.keys(StatBlock.Default().Abilities).map(abilityName => {
const abilityScore = statBlock.Abilities[abilityName];
const abilityModifier =
textEnricher.GetEnrichedModifierFromAbilityScore(abilityScore);
return (
<div className="Ability" key={abilityName}>
<div className="stat-label">{abilityName}</div>
<span className={"score " + abilityName}>{abilityScore}</span>
<span className={"modifier " + abilityName}>
{abilityModifier}
<div className="speed">
<span className="stat-label">Speed</span>
<span className="stat-value">
{statBlock.Speed.map((speed, i) => (
<span className="stat-value__item" key={"stat-value__speed-" + i}>
{speed}
</span>
</div>
);
})}
</div>
))}
</span>
</div>

<hr />

<div className="modifiers">
{modifierTypes
.filter(modifierType => modifierType.data.length > 0)
.map(modifierType => (
<div key={modifierType.name} className={modifierType.name}>
<span className="stat-label">{modifierType.name}</span>
{modifierType.data.map((modifier, i) => (
<span className="stat-value" key={i + modifier.Name}>
{modifier.Name}
{textEnricher.EnrichModifier(modifier.Modifier)}{" "}
<div className="Abilities">
{Object.keys(StatBlock.Default().Abilities).map(abilityName => {
const abilityScore = statBlock.Abilities[abilityName];
const abilityModifier =
textEnricher.GetEnrichedModifierFromAbilityScore(abilityScore);
return (
<div className="Ability" key={abilityName}>
<div className="stat-label">{abilityName}</div>
<span className={"score " + abilityName}>{abilityScore}</span>
<span className={"modifier " + abilityName}>
{abilityModifier}
</span>
))}
</div>
))}
</div>
</div>
);
})}
</div>

<div className="keyword-sets">
{keywordSetTypes
.filter(keywordSetType => keywordSetType.data.length > 0)
.map(keywordSetType => (
<div key={keywordSetType.name} className={keywordSetType.name}>
<span className="stat-label">{keywordSetType.name}</span>
<span className="stat-value">
<span className="stat-value__item">
{keywordSetType.data.map((keyword, index) => {
return (
<span
className="stat-value__item"
key={`stat-value__${keywordSetType.name}-${index}`}
>
{keyword}
</span>
);
})}
</span>
</span>
</div>
))}
</div>
<hr />

{statBlock.Challenge && (
<div className="Challenge">
<span className="stat-label">
{statBlock.Player == "player" ? "Level" : "Challenge"}
</span>
<span className="stat-value">{statBlock.Challenge}</span>
<div className="modifiers">
{modifierTypes
.filter(modifierType => modifierType.data.length > 0)
.map(modifierType => (
<div key={modifierType.name} className={modifierType.name}>
<span className="stat-label">{modifierType.name}</span>
{modifierType.data.map((modifier, i) => (
<span className="stat-value" key={i + modifier.Name}>
{modifier.Name}
{textEnricher.EnrichModifier(modifier.Modifier)}{" "}
</span>
))}
</div>
))}
</div>
)}

<hr />
</>
);

const actionEntries = powerTypes
.filter(powerType => powerType?.data?.length > 0)
.map(powerType => (
<div key={powerType.name} className={powerType.name}>
<h4 className="stat-label">{powerType.name}</h4>
{powerType.data.map((power, j) => (
<div key={j + power.Name}>
{power.Name?.length ? (
<span className="stat-label">{power.Name}</span>
) : null}
{power.Usage && <span className="stat-label">{power.Usage}</span>}
<span className="power-content">
{textEnricher.EnrichText(power.Content)}

<div className="keyword-sets">
{keywordSetTypes
.filter(keywordSetType => keywordSetType.data.length > 0)
.map(keywordSetType => (
<div key={keywordSetType.name} className={keywordSetType.name}>
<span className="stat-label">{keywordSetType.name}</span>
<span className="stat-value">
<span className="stat-value__item">
{keywordSetType.data.map((keyword, index) => {
return (
<span
className="stat-value__item"
key={`stat-value__${keywordSetType.name}-${index}`}
>
{keyword}
</span>
);
})}
</span>
</span>
</div>
))}
</div>

{statBlock.Challenge && (
<div className="Challenge">
<span className="stat-label">
{statBlock.Player == "player" ? "Level" : "Challenge"}
</span>
<span className="stat-value">{statBlock.Challenge}</span>
</div>
))}
)}

<hr />
</div>
));
</>
);

const actionEntries = powerTypes
.filter(powerType => powerType?.data?.length > 0)
.map(powerType => (
<div key={powerType.name} className={powerType.name}>
<h4 className="stat-label">{powerType.name}</h4>
{powerType.data.map((power, j) => (
<div key={j + power.Name}>
{power.Name?.length ? (
<span className="stat-label">{power.Name}</span>
) : null}
{power.Usage && <span className="stat-label">{power.Usage}</span>}
<span className="power-content">
{textEnricher.EnrichText(power.Content)}
</span>
</div>
))}
<hr />
</div>
));

const description = statBlock.Description && (
<div className="Description">
{textEnricher.EnrichText(statBlock.Description)}
</div>
);
const description = statBlock.Description && (
<div className="Description">
{textEnricher.EnrichText(statBlock.Description)}
</div>
);

let innerEntries;
let innerEntries;

if (props.isLoading) {
if (props.isLoading) {
return (
<div className="c-statblock">
{headerEntries}
<LoadingIndicator />
</div>
);
}
if (props.displayMode == "active") {
innerEntries = (
<>
{actionEntries}
{statEntries}
</>
);
} else {
innerEntries = (
<>
{statEntries}
{actionEntries}
</>
);
}
return (
<div className="c-statblock">
{headerEntries}
<LoadingIndicator />
{innerEntries}
{description}
</div>
);
}
if (props.displayMode == "active") {
innerEntries = (
<>
{actionEntries}
{statEntries}
</>
);
} else {
innerEntries = (
<>
{statEntries}
{actionEntries}
</>
} catch (error) {
return (
<div className="c-statblock">
<div>
<p>There was a problem with this StatBlock:</p>
<pre className="c-statblock__error">{error.toString()}</pre>
<p>Please open it in the StatBlock Editor to check your JSON</p>
</div>
</div>
);
}
return (
<div className="c-statblock">
{headerEntries}
{innerEntries}
{description}
</div>
);
}
Loading

0 comments on commit 48d138c

Please sign in to comment.