mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
fix: resolve requested changes
This commit is contained in:
1 parent
7cfc30c7a1
commit
504f143ff7
1 file changed
+48
-40
@@ -14,6 +14,42 @@ interface Mappings {
|
|||||||
|
|
||||||
const listItemsPattern = /<items path="(.+)\.xml"\/>/g;
|
const listItemsPattern = /<items path="(.+)\.xml"\/>/g;
|
||||||
|
|
||||||
|
async function extractPackedIcon(
|
||||||
|
texture: sharp.Sharp,
|
||||||
|
sizes: number[],
|
||||||
|
context: string,
|
||||||
|
) {
|
||||||
|
const [left, top, width, height] = sizes;
|
||||||
|
const bounds = [left, top, width, height];
|
||||||
|
|
||||||
|
if (!bounds.every(Number.isInteger)) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid RIFF sprite bounds for ${context}: ${bounds.join(" ")}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const metadata = await texture.metadata();
|
||||||
|
|
||||||
|
if (metadata.width === undefined || metadata.height === undefined) {
|
||||||
|
throw new Error(`Failed to read image dimensions for ${context}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 for ${context}: ${bounds.join(" ")} in ${metadata.width}x${metadata.height}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await texture.clone().extract({ left, top, width, height }).toBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
export async function consumableProvisionIcons() {
|
export async function consumableProvisionIcons() {
|
||||||
console.log("Building consumable and provision icons...");
|
console.log("Building consumable and provision icons...");
|
||||||
|
|
||||||
@@ -64,28 +100,13 @@ export async function consumableProvisionIcons() {
|
|||||||
let content: Buffer;
|
let content: Buffer;
|
||||||
|
|
||||||
if (sizes) {
|
if (sizes) {
|
||||||
try {
|
content = await extractPackedIcon(
|
||||||
content = await consumablesTexture
|
consumablesTexture,
|
||||||
.clone()
|
sizes,
|
||||||
.extract({
|
`consumable ${consumable.icon}`,
|
||||||
left: sizes[0],
|
);
|
||||||
top: sizes[1],
|
|
||||||
width: sizes[2],
|
|
||||||
height: sizes[3],
|
|
||||||
})
|
|
||||||
.toBuffer();
|
|
||||||
} catch {
|
|
||||||
console.warn(
|
|
||||||
`Failed to extract consumable ${consumable.icon} from RIFF data; falling back to trim...`,
|
|
||||||
);
|
|
||||||
content = await consumablesTexture
|
|
||||||
.trim({ threshold: 100 })
|
|
||||||
.toBuffer();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
content = await consumablesTexture
|
content = await consumablesTexture.trim({ threshold: 80 }).toBuffer();
|
||||||
.trim({ threshold: 100 })
|
|
||||||
.toBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await uploader.add({
|
await uploader.add({
|
||||||
@@ -156,26 +177,13 @@ export async function consumableProvisionIcons() {
|
|||||||
let content: Buffer;
|
let content: Buffer;
|
||||||
|
|
||||||
if (sizes) {
|
if (sizes) {
|
||||||
try {
|
content = await extractPackedIcon(
|
||||||
content = await provisionsTexture
|
provisionsTexture,
|
||||||
.clone()
|
sizes,
|
||||||
.extract({
|
`provision ${provision.icon}`,
|
||||||
left: sizes[0],
|
);
|
||||||
top: sizes[1],
|
|
||||||
width: sizes[2],
|
|
||||||
height: sizes[3],
|
|
||||||
})
|
|
||||||
.toBuffer();
|
|
||||||
} catch {
|
|
||||||
console.warn(
|
|
||||||
`Failed to extract provision ${provision.icon} from RIFF data; falling back to trim...`,
|
|
||||||
);
|
|
||||||
content = await provisionsTexture
|
|
||||||
.trim({ threshold: 100 })
|
|
||||||
.toBuffer();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
content = await provisionsTexture.trim({ threshold: 100 }).toBuffer();
|
content = await provisionsTexture.trim({ threshold: 80 }).toBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
await uploader.add({
|
await uploader.add({
|
||||||
|
|||||||
Reference in new issue
Block a user