mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 15:52:55 +01:00
feat: start of all tanks
This commit is contained in:
1 parent
53d05e73a6
commit
fcfc97b964
14 files changed
+174
-58
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import { api } from "../../core/api/dynamic";
|
||||
import { Tanks } from "../../protos/tanks";
|
||||
|
||||
/**
|
||||
* Literally all the tanks in one place lmao.
|
||||
*/
|
||||
export async function GET() {
|
||||
const tanks = await api.tanks();
|
||||
return new Response(Tanks.encode(tanks).finish());
|
||||
}
|
||||
@@ -3,9 +3,9 @@ import { api } from "../../../core/api/dynamic";
|
||||
import { Tank } from "../../../protos/tank";
|
||||
|
||||
export const getStaticPaths = (async () => {
|
||||
const { tanks } = await api.tanks();
|
||||
const { list } = await api.tankList();
|
||||
|
||||
return tanks.map(({ id }) => ({ params: { id } }));
|
||||
return list.map(({ id }) => ({ params: { id } }));
|
||||
}) satisfies GetStaticPaths;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { times } from "lodash-es";
|
||||
import { Suspense, useMemo } from "react";
|
||||
import { TankopediaCharacteristic } from "../../../components/TankopediaCharacteristic";
|
||||
import { TankopediaToy } from "../../../components/TankopediaToy";
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
import { characteristicsOrder } from "../../../core/tankopedia/characteristicsOrder";
|
||||
import { computeCharacteristics } from "../../../core/tankopedia/computeCharacteristics";
|
||||
import { renderCharacteristic } from "../../../core/tankopedia/renderCharacteristic";
|
||||
import { TerrainHardness } from "../../../core/tankopedia/tankState";
|
||||
import { useAwait } from "../../../hooks/useAwait";
|
||||
import { Tankopedia } from "../../../stores/tankopedia";
|
||||
import { Tankopedia, TankopediaCompare } from "../../../stores/tankopedia";
|
||||
|
||||
export function Page({ id }: { id: string }) {
|
||||
return (
|
||||
@@ -18,10 +19,12 @@ export function Page({ id }: { id: string }) {
|
||||
|
||||
function Content({ id }: { id: string }) {
|
||||
const { tank, compensation } = useAwait(() => api.tank(id), `tank-${id}`);
|
||||
const otherTanks = useAwait(() => api.tanks(), "tanks");
|
||||
|
||||
Tankopedia.useInitialization(tank!.upgrade_stages.length);
|
||||
Tankopedia.useInitialization(tank!);
|
||||
|
||||
const protagonist = Tankopedia.use((state) => state.protagonist);
|
||||
const compare = Tankopedia.use((state) => state.compare);
|
||||
const { characteristics, parameters } = useMemo(
|
||||
() => computeCharacteristics(id, tank!, compensation!, protagonist),
|
||||
[protagonist]
|
||||
@@ -181,27 +184,41 @@ function Content({ id }: { id: string }) {
|
||||
|
||||
<br />
|
||||
|
||||
<div style={{ display: "flex", flexWrap: "wrap" }}>
|
||||
{Object.values(TankopediaCompare).map(
|
||||
(c) =>
|
||||
typeof c === "number" && (
|
||||
<button
|
||||
key={c}
|
||||
onClick={() => {
|
||||
Tankopedia.mutate((draft) => {
|
||||
draft.compare = c;
|
||||
});
|
||||
}}
|
||||
>
|
||||
{TankopediaCompare[c]} {c === compare && "(selected)"}
|
||||
</button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
{characteristicsOrder.map(({ group, order }) => (
|
||||
<>
|
||||
<h2 key={group}>{group}</h2>
|
||||
|
||||
{order.map((config) => {
|
||||
if ("toy" in config) {
|
||||
return <p key={`toy-${config.toy}`}>toy: {config.toy}</p>;
|
||||
} else {
|
||||
const characteristic = characteristics[config.name];
|
||||
|
||||
if (characteristic === null) return null;
|
||||
|
||||
const rendered = renderCharacteristic(characteristic, config);
|
||||
|
||||
return (
|
||||
<p key={`characteristic-${config.name}`}>
|
||||
{config.name}: {rendered} {config.units && `${config.units}`}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
})}
|
||||
{order.map((config) =>
|
||||
"toy" in config ? (
|
||||
<TankopediaToy key={`toy-${config.toy}`} toy={config.toy} />
|
||||
) : (
|
||||
<TankopediaCharacteristic
|
||||
key={`characteristic-${config.name}`}
|
||||
characteristic={characteristics[config.name]}
|
||||
config={config}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</>
|
||||
))}
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user