mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-04 23:32:54 +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,9 +1,10 @@
|
||||
import { normalizeAngleRad } from "@blitzkit/core";
|
||||
import type { PitchLimits, YawLimits } from "@blitzkit/protos";
|
||||
import { clamp } from "lodash-es";
|
||||
import { degToRad } from "three/src/math/MathUtils.js";
|
||||
import { degToRad, radToDeg } from "three/src/math/MathUtils.js";
|
||||
|
||||
export const DEFAULT_PITCH_TRANSITION = 20;
|
||||
// The game's default is 0.4 rad
|
||||
export const DEFAULT_PITCH_TRANSITION = radToDeg(0.4);
|
||||
|
||||
export function applyPitchYawLimits(
|
||||
pitch: number, // rad
|
||||
|
||||
@@ -27,5 +27,5 @@ export async function extractPackedIcon(texture: sharp.Sharp, sizes: number[]) {
|
||||
);
|
||||
}
|
||||
|
||||
return await texture.clone().extract({ left, top, width, height }).toBuffer();
|
||||
return await texture.clone().extract({ left, top, width, height }).webp().toBuffer();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import sharp from "sharp";
|
||||
import { vfs } from "../blitzkit/vfs";
|
||||
import { extractPackedIcon } from "./extractPackedIcon";
|
||||
import { parsePackedSpriteRect } from "./parsePackedSpriteRect";
|
||||
|
||||
// Route props that point at a sprite, for each way of reading one
|
||||
export interface PackedSpriteProps {
|
||||
packed: string;
|
||||
}
|
||||
|
||||
export interface DiscreteSpriteProps {
|
||||
descriptor: string;
|
||||
texture: string;
|
||||
}
|
||||
|
||||
// A standalone texture; the sprite rect lives in its RIFF `extr` chunk. Reads
|
||||
// it the way the client does, as webp. Trimming is only a guess, so it is
|
||||
// used solely for textures that carry no rect.
|
||||
export async function readPackedSprite(path: string) {
|
||||
const packed = await vfs.file(path);
|
||||
const texture = sharp(packed);
|
||||
const rect = parsePackedSpriteRect(packed);
|
||||
|
||||
if (rect === null) {
|
||||
return new Uint8Array(await texture.trim().webp().toBuffer());
|
||||
}
|
||||
|
||||
return new Uint8Array(await extractPackedIcon(texture, rect));
|
||||
}
|
||||
|
||||
// A rect in a `.txt` descriptor (line 4) cut out of a shared atlas texture
|
||||
export async function readDiscreteSprite(descriptor: string, texture: string) {
|
||||
const rect = (await vfs.text(descriptor))
|
||||
.split("\n")[4]
|
||||
.split(" ")
|
||||
.map(Number);
|
||||
|
||||
return new Uint8Array(
|
||||
await extractPackedIcon(sharp(await vfs.file(texture)), rect)
|
||||
);
|
||||
}
|
||||
|
||||
// Sprites in the UI styles are named without an extension and are either a
|
||||
// standalone texture or an entry of the `texture0` atlas next to them
|
||||
export async function readStyleSprite(path: string) {
|
||||
const packed = `${path}.packed.webp`;
|
||||
|
||||
if (await vfs.resolve(packed)) return await readPackedSprite(packed);
|
||||
|
||||
return await readDiscreteSprite(
|
||||
`${path}.txt`,
|
||||
`${path.split("/").slice(0, -1).join("/")}/texture0.packed.webp`
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user