get ammo and gear tables working
This commit is contained in:
1 parent
49dec31761
commit
9298ebcd3e
23 files changed
+928
-391
No files matched your search
@@ -0,0 +1,135 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import type { Route } from "./+types/home";
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [
|
||||
{ title: "Collateral - Gear" },
|
||||
{ name: "description", content: "Gear" },
|
||||
];
|
||||
}
|
||||
|
||||
const baseUrl =
|
||||
typeof window !== "undefined"
|
||||
? window.location.origin
|
||||
: process.env.VITE_VERCEL_URL || "http://localhost:5173"; // Fallback for your server env
|
||||
|
||||
const g = await fetch(`${baseUrl}/characters/collateral/gear.json`).then((r) =>
|
||||
r.json(),
|
||||
);
|
||||
|
||||
type AmmunitionData = {
|
||||
caliber: string;
|
||||
type: string;
|
||||
count: number;
|
||||
};
|
||||
|
||||
type GearData = {
|
||||
name: string;
|
||||
description: string;
|
||||
count: number;
|
||||
contents: GearData[];
|
||||
};
|
||||
|
||||
function AmmunitionRow({ ammo }: { ammo: AmunitionData }) {
|
||||
return (
|
||||
<tr>
|
||||
<td>{ammo.caliber}</td>
|
||||
<td>{ammo.type}</td>
|
||||
<td>{ammo.count}x</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
function AmmunitionHeader() {
|
||||
return (
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Caliber</th>
|
||||
<th>Type</th>
|
||||
<th>Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
);
|
||||
}
|
||||
|
||||
function Ammunition({ ammo }: { ammo: AmmunitionData[] }) {
|
||||
const ammoRows: ReactElement[] = ammo.map((entry, index) => (
|
||||
<AmmunitionRow key={index} ammo={entry} />
|
||||
));
|
||||
|
||||
return (
|
||||
<table className="cyber-table">
|
||||
<AmmunitionHeader />
|
||||
<tbody>{ammoRows}</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
|
||||
function InventoryHeader(): ReactElement {
|
||||
return (
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
);
|
||||
}
|
||||
|
||||
function InventoryWithDepth(name: string, depth: number): string {
|
||||
if (depth === 0) {
|
||||
return name;
|
||||
}
|
||||
|
||||
return "|" + "-".repeat(depth - 1) + "> " + name;
|
||||
}
|
||||
|
||||
function InventoryRow({
|
||||
gear,
|
||||
depth,
|
||||
}: {
|
||||
gear: GearData;
|
||||
depth: number;
|
||||
}): ReactElement {
|
||||
const contents = gear.contents
|
||||
? gear.contents.map((entry, index) => (
|
||||
<InventoryRow gear={entry} key={index} depth={depth + 1} />
|
||||
))
|
||||
: [];
|
||||
|
||||
return (
|
||||
<>
|
||||
<tr>
|
||||
<td>{InventoryWithDepth(gear.name, depth)}</td>
|
||||
<td>{InventoryWithDepth(gear.description, depth)}</td>
|
||||
<td>{gear.count}x</td>
|
||||
</tr>
|
||||
{contents}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Inventory({ gear }: { gear: GearData[] }) {
|
||||
const inventoryRows = gear.map((entry, index) => (
|
||||
<InventoryRow key={index} gear={entry} depth={0} />
|
||||
));
|
||||
|
||||
return (
|
||||
<table className="cyber-table">
|
||||
<InventoryHeader />
|
||||
<tbody>{inventoryRows}</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Gear() {
|
||||
const [gear] = useState(g);
|
||||
|
||||
return (
|
||||
<main>
|
||||
<Ammunition ammo={gear.ammo} />
|
||||
<Inventory gear={gear.gear} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
import type { Route } from "./+types/home";
|
||||
import { Awareness } from "../skills/awareness";
|
||||
import { Body } from "../skills/body";
|
||||
import { Control } from "../skills/control";
|
||||
import { EducationTop, EducationBottom } from "../skills/education"
|
||||
import { Fighting } from "../skills/fighting"
|
||||
import { Performance } from "../skills/performance"
|
||||
import { RangedTop, RangedBottom } from "../skills/ranged"
|
||||
import { Social } from "../skills/social"
|
||||
import { Technique } from "../skills/technique"
|
||||
import { Details } from "../details/details"
|
||||
import { Stats } from "../details/stats"
|
||||
import { WeaponsAndArmor } from "../details/weaponsandarmor"
|
||||
|
||||
export function meta({ }: Route.MetaArgs) {
|
||||
return [
|
||||
{ title: "New React Router App" },
|
||||
{ name: "description", content: "Welcome to React Router!" },
|
||||
];
|
||||
}
|
||||
|
||||
function SkillTable() {
|
||||
return (
|
||||
<div style={{display: "flex", flexDirection: "row"}}>
|
||||
<div style={{flexGrow: 1}} >
|
||||
<Awareness />
|
||||
<Body />
|
||||
<Control />
|
||||
<EducationTop />
|
||||
</div>
|
||||
<div style={{flexGrow: 1}} >
|
||||
<EducationBottom />
|
||||
<Fighting />
|
||||
<Performance />
|
||||
<RangedTop />
|
||||
</div>
|
||||
<div style={{flexGrow: 1}} >
|
||||
<RangedBottom />
|
||||
<Social />
|
||||
<Technique />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main style={{display:"flex", flexDirection:"column", height:"100vh"}}>
|
||||
|
||||
<nav className="cyber-nav">
|
||||
<span className="cyber-nav__brand">Collateral</span>
|
||||
<ul className="cyber-nav__links">
|
||||
<li><span className="cyber-nav__link cyber-nav__link--active">Stats and Skills</span></li>
|
||||
<li><span className="cyber-nav__link">Cyber</span></li>
|
||||
<li><span className="cyber-nav__link">Gear</span></li>
|
||||
<li><span className="cyber-nav__link">Loadouts</span></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div style={{position:"relative", height:"100%", margin:"10px"}}>
|
||||
<div style={{display:"flex", flexDirection:"row", justifyContent:"space-evenly", position:"absolute", height:"100%"}}>
|
||||
|
||||
<div style={{width: "400px", height: "100%"}}>
|
||||
<Details />
|
||||
</div>
|
||||
|
||||
<div style={{overflow:"auto"}}><Stats /></div>
|
||||
|
||||
<div style={{display:"flex", flexDirection:"column"}}>
|
||||
<div style={{overflow:"auto"}}><SkillTable /></div>
|
||||
<div><WeaponsAndArmor /></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,80 @@
|
||||
import type { Route } from "./+types/home";
|
||||
import { Awareness } from "../skills/awareness";
|
||||
import { Body } from "../skills/body";
|
||||
import { Control } from "../skills/control";
|
||||
import { EducationTop, EducationBottom } from "../skills/education";
|
||||
import { Fighting } from "../skills/fighting";
|
||||
import { Performance } from "../skills/performance";
|
||||
import { RangedTop, RangedBottom } from "../skills/ranged";
|
||||
import { Social } from "../skills/social";
|
||||
import { Technique } from "../skills/technique";
|
||||
import { Details } from "../details/details";
|
||||
import { Stats } from "../details/stats";
|
||||
import { WeaponsAndArmor } from "../details/weaponsandarmor";
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [
|
||||
{ title: "Collateral - Stats and Skills" },
|
||||
{ name: "description", content: "Stats and Skills" },
|
||||
];
|
||||
}
|
||||
|
||||
function SkillTable() {
|
||||
return (
|
||||
<div style={{ display: "flex", flexDirection: "row" }}>
|
||||
<div style={{ flexGrow: 1 }}>
|
||||
<Awareness />
|
||||
<Body />
|
||||
<Control />
|
||||
<EducationTop />
|
||||
</div>
|
||||
<div style={{ flexGrow: 1 }}>
|
||||
<EducationBottom />
|
||||
<Fighting />
|
||||
<Performance />
|
||||
<RangedTop />
|
||||
</div>
|
||||
<div style={{ flexGrow: 1 }}>
|
||||
<RangedBottom />
|
||||
<Social />
|
||||
<Technique />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function StatsAndSkills() {
|
||||
return (
|
||||
<main style={{ display: "flex", flexDirection: "column", height: "100vh" }}>
|
||||
<div style={{ position: "relative", height: "100%", margin: "10px" }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-evenly",
|
||||
position: "absolute",
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<div style={{ width: "400px", height: "100%" }}>
|
||||
<Details />
|
||||
</div>
|
||||
|
||||
<div style={{ overflow: "auto" }}>
|
||||
<Stats />
|
||||
</div>
|
||||
|
||||
<div style={{ display: "flex", flexDirection: "column" }}>
|
||||
<div style={{ overflow: "auto" }}>
|
||||
<SkillTable />
|
||||
</div>
|
||||
<div>
|
||||
<WeaponsAndArmor />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user