Skip to content

Commit

Permalink
display artifact items in inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisinajar committed Feb 2, 2024
1 parent 3473a93 commit 2ad9ba9
Show file tree
Hide file tree
Showing 7 changed files with 451 additions and 364 deletions.
26 changes: 18 additions & 8 deletions src/components/artifact-modifiers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {

export function getArtifactModifier(
artifact: ArtifactItem,
type: ArtifactAttributeType
type: ArtifactAttributeType,
): ArtifactAttribute | undefined {
const modifiers = modifiersForArtifact(artifact);
const modifier = modifiers.find((mod) => mod.type === type);
return modifier;
}

export function modifiersForArtifact(
artifact: ArtifactItem
artifact: ArtifactItem,
): ArtifactAttribute[] {
const artifactBuffs: ArtifactAttribute[] = [
artifact.attributes.namePrefix,
Expand All @@ -38,7 +38,7 @@ export function modifiersForArtifact(
}

function modifierText(modifier: ArtifactAttribute): string {
const percentage = `${modifier.magnitude * 100 - 100}%`;
const percentage = `${Math.round((modifier.magnitude - 1) * 1000) / 10}%`;
switch (modifier.type) {
case ArtifactAttributeType.BonusStrength:
return `${percentage} increased strength`;
Expand Down Expand Up @@ -109,18 +109,28 @@ function modifierText(modifier: ArtifactAttribute): string {
export function ArtifactModifiers({
artifact,
sx,
children,
}: {
artifact: ArtifactItem;
sx?: any;
children?: JSX.Element;
}): JSX.Element {
const modifiers = modifiersForArtifact(artifact);
let decorator = (text: string, key: string) => (
<Typography variant="body1" key={key} sx={sx}>
<b>{text}</b>
</Typography>
);

if (typeof children === "function") {
decorator = children;
}

return (
<React.Fragment>
{modifiers.map((modifier) => (
<Typography variant="body1" key={modifier.type} sx={sx}>
<b>{modifierText(modifier)}</b>
</Typography>
))}
{modifiers.map((modifier) =>
decorator(modifierText(modifier), modifier.type),
)}
</React.Fragment>
);
}
Loading

0 comments on commit 2ad9ba9

Please sign in to comment.