148 lines
3.0 KiB
TypeScript
148 lines
3.0 KiB
TypeScript
import { useState, useEffect } from "react";
|
|
import type { Route } from "./+types/home";
|
|
|
|
export function meta({}: Route.MetaArgs) {
|
|
return [
|
|
{ title: "Collateral - Cyberware" },
|
|
{ name: "description", content: "Stats and Skills" },
|
|
];
|
|
}
|
|
|
|
const baseUrl =
|
|
typeof window !== "undefined"
|
|
? window.location.origin
|
|
: process.env.VITE_VERCEL_URL || "http://localhost:5173"; // Fallback for your server env
|
|
|
|
const c = await fetch(`${baseUrl}/characters/collateral/cyberware.json`).then(
|
|
(r) => r.json(),
|
|
);
|
|
|
|
type CyberBodyData = {
|
|
neural: FoundationData;
|
|
audio: FoundationData;
|
|
lefteye: FoundationData;
|
|
righteye: FoundationData;
|
|
leftarm: FoundationData;
|
|
rightarm: FoundationData;
|
|
leftleg: FoundationData;
|
|
rightleg: FoundationData;
|
|
internal: CyberData[];
|
|
external: CyberData[];
|
|
borgware: CyberData[];
|
|
};
|
|
|
|
type FoundationData = {
|
|
name: string;
|
|
slots: number;
|
|
upgraded: boolean;
|
|
hl: number;
|
|
contents: CyberData[];
|
|
};
|
|
|
|
type CyberData = {
|
|
name: string;
|
|
description: string;
|
|
hl: number;
|
|
};
|
|
|
|
function FoundationHeader(): ReactElement {
|
|
return (
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
);
|
|
}
|
|
|
|
function FoundationRow({
|
|
cyber,
|
|
}: {
|
|
cyber: CyberData | undefined;
|
|
}): ReactElement {
|
|
if (!cyber) {
|
|
return (
|
|
<tr>
|
|
<td>--</td>
|
|
<td>--</td>
|
|
</tr>
|
|
);
|
|
}
|
|
|
|
const upgrade = !cyber.upgraded ? (
|
|
<></>
|
|
) : (
|
|
<tr>
|
|
<td colspan="2">
|
|
{cyber.upgraded.name}: {cyber.upgraded.description}
|
|
</td>
|
|
</tr>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<tr>
|
|
<td>{cyber.name}</td>
|
|
<td>{cyber.description}</td>
|
|
</tr>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function Foundation({
|
|
foundation,
|
|
}: {
|
|
foundation: FoundationData;
|
|
}): ReactElement {
|
|
const rows: ReactElement[] = Array(foundation.slots);
|
|
|
|
for (let i = 0; i < foundation.slots; i++) {
|
|
rows[i] = <FoundationRow key={i} cyber={foundation.contents[i]} />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div>{foundation.name}</div>
|
|
<table className="cyber-table">
|
|
<FoundationHeader />
|
|
<tbody>{rows}</tbody>
|
|
</table>
|
|
</>
|
|
);
|
|
}
|
|
|
|
const rowStyle = {
|
|
display: "flex",
|
|
flexDirection: "column",
|
|
width: "25%",
|
|
};
|
|
|
|
export default function Cyberware() {
|
|
const [cyber, setCyber] = useState(c);
|
|
|
|
return (
|
|
<div style={{ display: "flex", flexDirection: "row" }}>
|
|
<div style={rowStyle}>
|
|
<Foundation foundation={cyber.lefteye} />
|
|
<Foundation foundation={cyber.leftarm} />
|
|
<Foundation foundation={cyber.leftleg} />
|
|
</div>
|
|
<div style={rowStyle}>
|
|
<Foundation foundation={cyber.neural} />
|
|
<Foundation foundation={cyber.audio} />
|
|
</div>
|
|
<div style={rowStyle}>
|
|
<Foundation foundation={cyber.righteye} />
|
|
<Foundation foundation={cyber.rightarm} />
|
|
<Foundation foundation={cyber.rightleg} />
|
|
</div>
|
|
<div style={rowStyle}>
|
|
<Foundation foundation={cyber.internal} />
|
|
<Foundation foundation={cyber.external} />
|
|
<Foundation foundation={cyber.borgware} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|