mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-21 12:53:56 +01:00
augment trees, pitch-limit fallback, and cached definitions
This commit is contained in:
57 files changed
+2196
-717
No files matched your search
@@ -1,6 +1,9 @@
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readPackedSprite,
|
||||
type PackedSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -13,8 +16,8 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
files.filter(
|
||||
(flag) =>
|
||||
flag.startsWith("flag_profile-stat_") &&
|
||||
!flag.endsWith("@2x.packed.webp"),
|
||||
),
|
||||
!flag.endsWith("@2x.packed.webp")
|
||||
)
|
||||
);
|
||||
|
||||
for (const flag of circleFiles) {
|
||||
@@ -23,17 +26,13 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
paths.push({
|
||||
params: { id },
|
||||
props: { path },
|
||||
props: { packed: path },
|
||||
});
|
||||
}
|
||||
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||
const image = sharp(await vfs.file(props.path));
|
||||
const content = await image.trim({ threshold: 100 }).toBuffer();
|
||||
const bytes = new Uint8Array(content);
|
||||
|
||||
return new Response(bytes);
|
||||
export async function GET({ props }: APIContext<PackedSpriteProps>) {
|
||||
return new Response(await readPackedSprite(props.packed));
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import sharp from "sharp";
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readPackedSprite,
|
||||
type PackedSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -12,8 +15,8 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
.then((files) =>
|
||||
files.filter(
|
||||
(flag) =>
|
||||
flag.startsWith("flag_filter_") && flag.endsWith("@2x.packed.webp"),
|
||||
),
|
||||
flag.startsWith("flag_filter_") && flag.endsWith("@2x.packed.webp")
|
||||
)
|
||||
);
|
||||
|
||||
for (const flag of fadedFiles) {
|
||||
@@ -22,18 +25,13 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
paths.push({
|
||||
params: { id },
|
||||
props: { path },
|
||||
props: { packed: path },
|
||||
});
|
||||
}
|
||||
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||
const bytes = await sharp(new Uint8Array(await vfs.file(props.path)))
|
||||
.trim({ background: { r: 0, g: 0, b: 0, alpha: 0 }, threshold: 1 })
|
||||
.webp()
|
||||
.toBuffer();
|
||||
|
||||
return new Response(new Uint8Array(bytes));
|
||||
export async function GET({ props }: APIContext<PackedSpriteProps>) {
|
||||
return new Response(await readPackedSprite(props.packed));
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import type { SquadBattleTypeStylesYaml } from "@blitzkit/core";
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readPackedSprite,
|
||||
type PackedSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -9,26 +12,26 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
const paths: GetStaticPathsItem[] = [];
|
||||
|
||||
const gameTypeSelectorStyles = await vfs.yaml<SquadBattleTypeStylesYaml>(
|
||||
`Data/UI/Screens/Lobby/Hangar/GameTypeSelector.yaml`,
|
||||
`Data/UI/Screens/Lobby/Hangar/GameTypeSelector.yaml`
|
||||
);
|
||||
const squadBattleTypeStyles = await vfs.yaml<SquadBattleTypeStylesYaml>(
|
||||
`Data/UI/Screens3/Lobby/Hangar/Squad/SquadBattleType.yaml`,
|
||||
`Data/UI/Screens3/Lobby/Hangar/Squad/SquadBattleType.yaml`
|
||||
);
|
||||
const bannerMatches: { name: string; path: string }[] = [];
|
||||
|
||||
for (const match of gameTypeSelectorStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll(
|
||||
/eGameMode\.(\w+) -> "~res:([^"]+)"/g,
|
||||
/eGameMode\.(\w+) -> "~res:([^"]+)"/g
|
||||
)) {
|
||||
bannerMatches.push({ name: match[1], path: match[2] });
|
||||
}
|
||||
|
||||
for (const match of squadBattleTypeStyles.Prototypes[0].components.UIDataLocalBindingsComponent.data[1][2].matchAll(
|
||||
/eGameMode\.(\w+) -> "battleType\/([a-zA-Z]+)"/g,
|
||||
/eGameMode\.(\w+) -> "battleType\/([a-zA-Z]+)"/g
|
||||
)) {
|
||||
const id = match[1];
|
||||
const name = match[2];
|
||||
let path = bannerMatches.find(
|
||||
(bannerMatch) => bannerMatch.name.toLowerCase() === name.toLowerCase(),
|
||||
(bannerMatch) => bannerMatch.name.toLowerCase() === name.toLowerCase()
|
||||
)?.path;
|
||||
|
||||
if (path === undefined) {
|
||||
@@ -37,18 +40,13 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
paths.push({
|
||||
params: { id },
|
||||
props: { path: `Data${path}.packed.webp` },
|
||||
props: { packed: `Data${path}.packed.webp` },
|
||||
});
|
||||
}
|
||||
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||
const buffer = await sharp(await vfs.file(props.path))
|
||||
.trim({ background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
||||
.toBuffer();
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
export async function GET({ props }: APIContext<PackedSpriteProps>) {
|
||||
return new Response(await readPackedSprite(props.packed));
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readPackedSprite,
|
||||
type PackedSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
const ROOT = "Data/Gfx/Lobby/icons/upgrades";
|
||||
|
||||
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
const paths: GetStaticPathsItem[] = [];
|
||||
|
||||
const files = await vfs.dir(ROOT);
|
||||
|
||||
for (const file of files) {
|
||||
if (file.endsWith("@2x.packed.webp")) continue;
|
||||
|
||||
const match = file.match(/^(.+)\.packed\.webp$/);
|
||||
|
||||
if (match === null) continue;
|
||||
|
||||
paths.push({
|
||||
params: { id: match[1] },
|
||||
props: { packed: `${ROOT}/${file}` },
|
||||
});
|
||||
}
|
||||
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<PackedSpriteProps>) {
|
||||
return new Response(await readPackedSprite(props.packed));
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readDiscreteSprite,
|
||||
type DiscreteSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -11,8 +14,8 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
.dir("Data/Gfx/Shared/boosters")
|
||||
.then((files) =>
|
||||
files.filter(
|
||||
(file) => !file.includes("@2x.txt") && !file.startsWith("texture0"),
|
||||
),
|
||||
(file) => !file.includes("@2x.txt") && !file.startsWith("texture0")
|
||||
)
|
||||
);
|
||||
|
||||
for (const file of boosterFiles) {
|
||||
@@ -20,34 +23,20 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
if (id === undefined) continue;
|
||||
|
||||
const sizes = (await vfs.text(`Data/Gfx/Shared/boosters/${file}`))
|
||||
.split("\n")[4]
|
||||
.split(" ")
|
||||
.map(Number);
|
||||
|
||||
paths.push({
|
||||
params: { id },
|
||||
props: { sizes },
|
||||
props: {
|
||||
descriptor: `Data/Gfx/Shared/boosters/${file}`,
|
||||
texture: `Data/Gfx/Shared/boosters/texture0.packed.webp`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ sizes: number[] }>) {
|
||||
const image = sharp(
|
||||
await vfs.file(`Data/Gfx/Shared/boosters/texture0.packed.webp`),
|
||||
export async function GET({ props }: APIContext<DiscreteSpriteProps>) {
|
||||
return new Response(
|
||||
await readDiscreteSprite(props.descriptor, props.texture)
|
||||
);
|
||||
const buffer = await image
|
||||
.clone()
|
||||
.extract({
|
||||
left: props.sizes[0],
|
||||
top: props.sizes[1],
|
||||
width: props.sizes[2],
|
||||
height: props.sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
import sharp from "sharp";
|
||||
import { vfs } from "../../../core/blitzkit/vfs";
|
||||
import { readPackedSprite } from "../../../core/blitz/readSprite";
|
||||
|
||||
export { getStaticPaths } from "../_index";
|
||||
|
||||
export async function GET() {
|
||||
const buffer = await sharp(
|
||||
await vfs.file("Data/Gfx/UI/Hangar/IconCamouflage.packed.webp"),
|
||||
)
|
||||
.trim()
|
||||
.toBuffer();
|
||||
|
||||
return new Response(new Uint8Array(buffer));
|
||||
return new Response(
|
||||
await readPackedSprite("Data/Gfx/UI/Hangar/IconCamouflage.packed.webp"),
|
||||
);
|
||||
}
|
||||
@@ -3,8 +3,7 @@ import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { api } from "../../../../api/dynamic";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import { extractPackedIcon } from "../../../../core/blitz/extractPackedIcon";
|
||||
import { parsePackedSpriteRect } from "../../../../core/blitz/parsePackedSpriteRect";
|
||||
import { readPackedSprite } from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -38,16 +37,8 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||
const path = (await vfs.resolve(`${props.path}@2x.packed.webp`))
|
||||
const packed = (await vfs.resolve(`${props.path}@2x.packed.webp`))
|
||||
? `${props.path}@2x.packed.webp`
|
||||
: `${props.path}.packed.webp`;
|
||||
const packed = await vfs.file(path);
|
||||
const texture = sharp(packed);
|
||||
const sizes = parsePackedSpriteRect(packed);
|
||||
const image = sizes
|
||||
? sharp(await extractPackedIcon(texture, sizes))
|
||||
: texture;
|
||||
const bytes = await image.webp().toBuffer();
|
||||
|
||||
return new Response(new Uint8Array(bytes));
|
||||
return new Response(await readPackedSprite(packed));
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { ConsumablesCommon } from "@blitzkit/core";
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import { extractPackedIcon } from "../../../../core/blitz/extractPackedIcon";
|
||||
import { parsePackedSpriteRect } from "../../../../core/blitz/parsePackedSpriteRect";
|
||||
import { readStyleSprite } from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -70,43 +68,5 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||
let buffer: Buffer;
|
||||
|
||||
if (await vfs.resolve(`Data/${props.path}.packed.webp`)) {
|
||||
const packedBuffer = await vfs.file(`Data/${props.path}.packed.webp`);
|
||||
const consumablesTexture = sharp(packedBuffer);
|
||||
const sizes = parsePackedSpriteRect(packedBuffer);
|
||||
|
||||
if (sizes) {
|
||||
buffer = await extractPackedIcon(consumablesTexture, sizes);
|
||||
} else {
|
||||
buffer = await consumablesTexture.trim({ threshold: 80 }).toBuffer();
|
||||
}
|
||||
} else {
|
||||
const consumablesTexture = sharp(
|
||||
await vfs.file(
|
||||
`${`Data/${props.path}`
|
||||
.split("/")
|
||||
.slice(0, -1)
|
||||
.join("/")}/texture0.packed.webp`,
|
||||
),
|
||||
);
|
||||
const sizes = (await vfs.text(`Data/${props.path}.txt`))
|
||||
.split("\n")[4]
|
||||
.split(" ")
|
||||
.map(Number);
|
||||
buffer = await consumablesTexture
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
}
|
||||
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
return new Response(await readStyleSprite(`Data/${props.path}`));
|
||||
}
|
||||
@@ -5,9 +5,8 @@ import {
|
||||
} from "@blitzkit/core";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { readPackedSprite } from "../../../../core/blitz/readSprite";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
const ICONS = [
|
||||
@@ -36,13 +35,11 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
}
|
||||
|
||||
const glossary = await fetch(
|
||||
`${WOTB_GLOSSARY_DOMAIN}/${locales.default}/${WOTB_GLOSSARY_PATH}`,
|
||||
`${WOTB_GLOSSARY_DOMAIN}/${locales.default}/${WOTB_GLOSSARY_PATH}`
|
||||
)
|
||||
.then((response) => response.json() as Promise<BlitzGlossary>)
|
||||
.then((glossary) =>
|
||||
Object.values(glossary)
|
||||
.entries()
|
||||
.filter(([key]) => /^prx_season_\d+$/.test(`${key}`)),
|
||||
Object.entries(glossary).filter(([key]) => /^prx_season_\d+$/.test(key))
|
||||
);
|
||||
|
||||
for (const [id, item] of glossary) {
|
||||
@@ -63,25 +60,12 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
export async function GET({
|
||||
props,
|
||||
}: APIContext<{ local: boolean; source: string }>) {
|
||||
let buffer: Buffer;
|
||||
|
||||
if (props.local) {
|
||||
buffer = await sharp(await vfs.file(props.source))
|
||||
.trim()
|
||||
.toBuffer();
|
||||
} else {
|
||||
const imageRaw = await fetch(props.source).then((response) =>
|
||||
response.arrayBuffer(),
|
||||
);
|
||||
buffer = await sharp(imageRaw)
|
||||
.trim({
|
||||
threshold: 100,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
})
|
||||
.toBuffer();
|
||||
return new Response(await readPackedSprite(props.source));
|
||||
}
|
||||
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
// The glossary already serves these cropped
|
||||
return new Response(
|
||||
await fetch(props.source).then((response) => response.arrayBuffer())
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
import type { OptionalDevices } from "@blitzkit/core";
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readDiscreteSprite,
|
||||
readPackedSprite,
|
||||
type DiscreteSpriteProps,
|
||||
type PackedSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -14,16 +19,18 @@ interface Mappings {
|
||||
}[];
|
||||
}
|
||||
|
||||
type Props = PackedSpriteProps | DiscreteSpriteProps;
|
||||
|
||||
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
const paths: GetStaticPathsItem[] = [];
|
||||
|
||||
console.log("Building equipment icons...");
|
||||
|
||||
const optionalDevices = await vfs.xml<{ root: OptionalDevices }>(
|
||||
`Data/XML/item_defs/vehicles/common/optional_devices.xml`,
|
||||
`Data/XML/item_defs/vehicles/common/optional_devices.xml`
|
||||
);
|
||||
const mappings = await vfs.yaml<Mappings>(
|
||||
`Data/UI/Screens3/Lobby/Inventory/OptionalDevices/OptionalDevicesItemImage.style.yaml`,
|
||||
`Data/UI/Screens3/Lobby/Inventory/OptionalDevices/OptionalDevicesItemImage.style.yaml`
|
||||
);
|
||||
|
||||
for (const optionalDeviceKey in optionalDevices.root) {
|
||||
@@ -33,8 +40,8 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
const mapping = mappings.StyleSheets.find((mapping) =>
|
||||
mapping.selectors.includes(
|
||||
`.optional_device_item.${optionalDevice.icon} #Img`,
|
||||
),
|
||||
`.optional_device_item.${optionalDevice.icon} #Img`
|
||||
)
|
||||
);
|
||||
|
||||
if (!mapping) {
|
||||
@@ -50,20 +57,14 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
paths.push({
|
||||
params: { id: optionalDevice.id },
|
||||
props: {
|
||||
sizes: undefined,
|
||||
source: `Data/${configPathWebp}.packed.webp`,
|
||||
},
|
||||
props: { packed: `Data/${configPathWebp}.packed.webp` },
|
||||
});
|
||||
} else {
|
||||
const config = await vfs.text(`Data/${configPath}`);
|
||||
const sizes = config.split("\n")[4].split(" ").map(Number);
|
||||
|
||||
paths.push({
|
||||
params: { id: optionalDevice.id },
|
||||
props: {
|
||||
sizes,
|
||||
source: `Data/Gfx/UI/InventoryIcons/Big/OptionalDevices/texture0.packed.webp`,
|
||||
descriptor: `Data/${configPath}`,
|
||||
texture: `Data/Gfx/UI/InventoryIcons/Big/OptionalDevices/texture0.packed.webp`,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -72,26 +73,10 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({
|
||||
props,
|
||||
}: APIContext<{ sizes?: number[]; source: string }>) {
|
||||
const image = sharp(await vfs.file(props.source));
|
||||
let buffer: Buffer;
|
||||
|
||||
if (props.sizes) {
|
||||
buffer = await image
|
||||
.extract({
|
||||
left: props.sizes[0],
|
||||
top: props.sizes[1],
|
||||
width: props.sizes[2],
|
||||
height: props.sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
} else {
|
||||
buffer = await image.trim().toBuffer();
|
||||
}
|
||||
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
export async function GET({ props }: APIContext<Props>) {
|
||||
return new Response(
|
||||
"packed" in props
|
||||
? await readPackedSprite(props.packed)
|
||||
: await readDiscreteSprite(props.descriptor, props.texture)
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readPackedSprite,
|
||||
type PackedSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -12,8 +15,8 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
.then((files) =>
|
||||
files.filter(
|
||||
(file) =>
|
||||
!file.endsWith("@2x.packed.webp") && file.startsWith("vehicle"),
|
||||
),
|
||||
!file.endsWith("@2x.packed.webp") && file.startsWith("vehicle")
|
||||
)
|
||||
);
|
||||
|
||||
for (const file of files) {
|
||||
@@ -23,18 +26,13 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
paths.push({
|
||||
params: { id },
|
||||
props: { path },
|
||||
props: { packed: path },
|
||||
});
|
||||
}
|
||||
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||
const buffer = await sharp(await vfs.file(props.path))
|
||||
.trim()
|
||||
.toBuffer();
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
export async function GET({ props }: APIContext<PackedSpriteProps>) {
|
||||
return new Response(await readPackedSprite(props.packed));
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { ProvisionsCommon } from "@blitzkit/core";
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { extractPackedIcon } from "../../../../core/blitz/extractPackedIcon";
|
||||
import { parsePackedSpriteRect } from "../../../../core/blitz/parsePackedSpriteRect";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import { readStyleSprite } from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -70,43 +68,5 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||
let buffer: Buffer;
|
||||
|
||||
if (await vfs.resolve(`Data/${props.path}.packed.webp`)) {
|
||||
const packedBuffer = await vfs.file(`Data/${props.path}.packed.webp`);
|
||||
const provisionsTexture = sharp(packedBuffer);
|
||||
const sizes = parsePackedSpriteRect(packedBuffer);
|
||||
|
||||
if (sizes) {
|
||||
buffer = await extractPackedIcon(provisionsTexture, sizes);
|
||||
} else {
|
||||
buffer = await provisionsTexture.trim({ threshold: 80 }).toBuffer();
|
||||
}
|
||||
} else {
|
||||
const provisionsTexture = sharp(
|
||||
await vfs.file(
|
||||
`${`Data/${props.path}`
|
||||
.split("/")
|
||||
.slice(0, -1)
|
||||
.join("/")}/texture0.packed.webp`,
|
||||
),
|
||||
);
|
||||
const sizes = (await vfs.text(`Data/${props.path}.txt`))
|
||||
.split("\n")[4]
|
||||
.split(" ")
|
||||
.map(Number);
|
||||
buffer = await provisionsTexture
|
||||
.clone()
|
||||
.extract({
|
||||
left: sizes[0],
|
||||
top: sizes[1],
|
||||
width: sizes[2],
|
||||
height: sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
}
|
||||
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
return new Response(await readStyleSprite(`Data/${props.path}`));
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readDiscreteSprite,
|
||||
type DiscreteSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -13,38 +16,21 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
for (const file of files) {
|
||||
const id = file.match(/(.+)_l\.txt/)![1];
|
||||
const sizes = (
|
||||
await vfs.text(`Data/Gfx/Shared/tank-supply/ammunition/big/${file}`)
|
||||
)
|
||||
.split("\n")[4]
|
||||
.split(" ")
|
||||
.map(Number);
|
||||
|
||||
paths.push({
|
||||
params: { id },
|
||||
props: { sizes },
|
||||
props: {
|
||||
descriptor: `Data/Gfx/Shared/tank-supply/ammunition/big/${file}`,
|
||||
texture: `Data/Gfx/Shared/tank-supply/ammunition/big/texture0.packed.webp`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ sizes: number[] }>) {
|
||||
const image = sharp(
|
||||
await vfs.file(
|
||||
`Data/Gfx/Shared/tank-supply/ammunition/big/texture0.packed.webp`,
|
||||
),
|
||||
export async function GET({ props }: APIContext<DiscreteSpriteProps>) {
|
||||
return new Response(
|
||||
await readDiscreteSprite(props.descriptor, props.texture)
|
||||
);
|
||||
const buffer = await image
|
||||
.clone()
|
||||
.extract({
|
||||
left: props.sizes[0],
|
||||
top: props.sizes[1],
|
||||
width: props.sizes[2],
|
||||
height: props.sizes[3],
|
||||
})
|
||||
.toBuffer();
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import type { TankmenAvatar } from "@blitzkit/core";
|
||||
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
|
||||
import {
|
||||
readPackedSprite,
|
||||
type PackedSpriteProps,
|
||||
} from "../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||
|
||||
@@ -9,7 +12,7 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
const paths: GetStaticPathsItem[] = [];
|
||||
|
||||
const avatar = await vfs.xml<{ root: TankmenAvatar }>(
|
||||
`Data/XML/item_defs/tankmen/avatar.xml`,
|
||||
`Data/XML/item_defs/tankmen/avatar.xml`
|
||||
);
|
||||
|
||||
for (const key in avatar.root.skills) {
|
||||
@@ -20,18 +23,13 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||
|
||||
paths.push({
|
||||
params: { id },
|
||||
props: { path },
|
||||
props: { packed: path },
|
||||
});
|
||||
}
|
||||
|
||||
return paths;
|
||||
});
|
||||
|
||||
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||
const buffer = await sharp(await vfs.file(props.path))
|
||||
.trim()
|
||||
.toBuffer();
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
return new Response(bytes);
|
||||
export async function GET({ props }: APIContext<PackedSpriteProps>) {
|
||||
return new Response(await readPackedSprite(props.packed));
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import {
|
||||
type VehicleDefinitionList,
|
||||
} from "@blitzkit/core";
|
||||
import type { APIContext } from "astro";
|
||||
import sharp from "sharp";
|
||||
import { parsePackedSpriteRect } from "../../../../../core/blitz/parsePackedSpriteRect";
|
||||
import { readPackedSprite } from "../../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../../core/blitzkit/vfs";
|
||||
|
||||
export { getStaticPaths } from "../_index";
|
||||
@@ -33,52 +32,11 @@ export async function GET({ props }: APIContext<{ id: number }>) {
|
||||
const parameters = await vfs.yaml<TankParameters>(
|
||||
`Data/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`,
|
||||
);
|
||||
const bigPath = `Data/${parameters.resourcesPath.bigIconPath
|
||||
const packed = `Data/${parameters.resourcesPath.bigIconPath
|
||||
.replace(/~res:\//, "")
|
||||
.replace(/\..+/, "")}.packed.webp`;
|
||||
const big = await extractPackedTankIcon(await vfs.file(bigPath));
|
||||
|
||||
return new Response(big);
|
||||
return new Response(await readPackedSprite(packed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function extractPackedTankIcon(bytes: Uint8Array) {
|
||||
const texture = sharp(bytes);
|
||||
const spriteRect = parsePackedSpriteRect(bytes);
|
||||
|
||||
if (!spriteRect) {
|
||||
throw new Error(`Missing RIFF sprite bounds`);
|
||||
}
|
||||
|
||||
const [left, top, width, height] = spriteRect;
|
||||
const bounds = [left, top, width, height];
|
||||
|
||||
if (!bounds.every(Number.isInteger)) {
|
||||
throw new Error(`Invalid RIFF sprite bounds: ${bounds.join(" ")}`);
|
||||
}
|
||||
|
||||
const metadata = await texture.metadata();
|
||||
|
||||
if (metadata.width === undefined || metadata.height === undefined) {
|
||||
throw new Error(`Failed to read image dimensions`);
|
||||
}
|
||||
|
||||
if (
|
||||
left < 0 ||
|
||||
top < 0 ||
|
||||
width <= 0 ||
|
||||
height <= 0 ||
|
||||
left + width > metadata.width ||
|
||||
top + height > metadata.height
|
||||
) {
|
||||
throw new Error(
|
||||
`Out-of-bounds RIFF sprite: ${bounds.join(" ")} in ${metadata.width}x${metadata.height}`,
|
||||
);
|
||||
}
|
||||
|
||||
const buffer = await texture.extract({ left, top, width, height }).toBuffer();
|
||||
const array = new Uint8Array(buffer);
|
||||
|
||||
return array;
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
type VehicleDefinitionList,
|
||||
} from "@blitzkit/core";
|
||||
import type { APIContext } from "astro";
|
||||
import { readPackedSprite } from "../../../../../core/blitz/readSprite";
|
||||
import { vfs } from "../../../../../core/blitzkit/vfs";
|
||||
import { extractPackedTankIcon } from "./big.webp";
|
||||
|
||||
export { getStaticPaths } from "../_index";
|
||||
|
||||
@@ -32,12 +32,11 @@ export async function GET({ props }: APIContext<{ id: number }>) {
|
||||
const parameters = await vfs.yaml<TankParameters>(
|
||||
`Data/3d/Tanks/Parameters/${nation}/${tankKey}.yaml`,
|
||||
);
|
||||
const bigPath = `Data/${parameters.resourcesPath.smallIconPath
|
||||
const packed = `Data/${parameters.resourcesPath.smallIconPath
|
||||
.replace(/~res:\//, "")
|
||||
.replace(/\..+/, "")}.packed.webp`;
|
||||
const big = await extractPackedTankIcon(await vfs.file(bigPath));
|
||||
|
||||
return new Response(big);
|
||||
return new Response(await readPackedSprite(packed));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user