Update jimp to version 1.6.0

Resolves #854
This commit is contained in:
Hornwitser committed 2026-03-12 14:45:48 +01:00
1 parent 4c01f6a789
commit f4916594b8
2 files changed
+20 -19

No files matched your search

+6 -6
View File
@@ -23,26 +23,26 @@
"dependencies": { "dependencies": {
"@clusterio/lib": "workspace:*", "@clusterio/lib": "workspace:*",
"@sinclair/typebox": "catalog:", "@sinclair/typebox": "catalog:",
"set-blocking": "catalog:",
"fs-extra": "catalog:", "fs-extra": "catalog:",
"jimp": "^1.6.0",
"jszip": "catalog:", "jszip": "catalog:",
"winston": "catalog:",
"winston-daily-rotate-file": "catalog:",
"jimp": "^0.22.8",
"pidusage": "^3.0.2", "pidusage": "^3.0.2",
"rcon-client": "^4.2.5", "rcon-client": "^4.2.5",
"semver": "^7.7.1", "semver": "^7.7.1",
"set-blocking": "catalog:",
"winston": "catalog:",
"winston-daily-rotate-file": "catalog:",
"yargs": "^17.7.2" "yargs": "^17.7.2"
}, },
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "catalog:",
"@types/fs-extra": "catalog:", "@types/fs-extra": "catalog:",
"@types/set-blocking": "catalog:", "@types/node": "catalog:",
"@types/pidusage": "^2.0.2", "@types/pidusage": "^2.0.2",
"@types/semver": "^7.5.0", "@types/semver": "^7.5.0",
"@types/set-blocking": "catalog:",
"@types/yargs": "^17.0.33", "@types/yargs": "^17.0.33",
"typescript": "catalog:" "typescript": "catalog:"
} }
+14 -13
View File
@@ -1,7 +1,7 @@
// Export of item icons and locale // Export of item icons and locale
import fs from "fs-extra"; import fs from "fs-extra";
import path from "path"; import path from "path";
import Jimp from "jimp"; import { Jimp, JimpMime, type JimpInstance } from "jimp";
import JSZip from "jszip"; import JSZip from "jszip";
import * as lib from "@clusterio/lib"; import * as lib from "@clusterio/lib";
@@ -63,7 +63,7 @@ async function generateExportMod(server: FactorioServer) {
}); });
} }
let zipCache = new Map(); let zipCache = new Map<string, JSZip>();
async function loadZip(server: FactorioServer, modVersions: Map<string, string>, mod: string) { async function loadZip(server: FactorioServer, modVersions: Map<string, string>, mod: string) {
let modVersion = modVersions.get(mod); let modVersion = modVersions.get(mod);
if (!modVersion) { if (!modVersion) {
@@ -77,7 +77,7 @@ async function loadZip(server: FactorioServer, modVersions: Map<string, string>,
zipCache.set(zipPath, zip); zipCache.set(zipPath, zip);
} }
return zip.folder(lib.findRoot(zip)); return zip.folder(lib.findRoot(zip))!;
} }
/** /**
@@ -128,7 +128,8 @@ async function loadFile(server: FactorioServer, modVersions: Map<string, string>
return await file.async("nodebuffer"); return await file.async("nodebuffer");
} }
type IconCache = Map<string, Jimp | null>; type Image = JimpInstance;
type IconCache = Map<string, Image | null>;
async function loadIcon( async function loadIcon(
server: FactorioServer, server: FactorioServer,
modVersions: Map<string, string>, modVersions: Map<string, string>,
@@ -141,8 +142,8 @@ async function loadIcon(
if (icon === undefined) { if (icon === undefined) {
let fileContent = await loadFile(server, modVersions, iconPath); let fileContent = await loadFile(server, modVersions, iconPath);
if (fileContent) { if (fileContent) {
icon = await Jimp.read(fileContent); icon = await Jimp.fromBuffer(fileContent) as Image;
icon.crop(0, 0, iconSize, iconSize); icon.crop({ x: 0, y: 0, w: iconSize, h: iconSize });
iconCache.set(iconPath, icon); iconCache.set(iconPath, icon);
} else { } else {
icon = null; icon = null;
@@ -178,7 +179,7 @@ async function loadLayeredIcon(
iconCache: IconCache, iconCache: IconCache,
) { ) {
let baseLayerSize = (item.icons[0].icon_size || item.icon_size) ?? 64; let baseLayerSize = (item.icons[0].icon_size || item.icon_size) ?? 64;
let icon = await Jimp.create(size, size); let icon = new Jimp({ width: size, height: size });
// The scaling factor of the base layer // The scaling factor of the base layer
let baseLayerScale = item.icons[0].scale || 32 / baseLayerSize; let baseLayerScale = item.icons[0].scale || 32 / baseLayerSize;
@@ -328,7 +329,7 @@ function filterPrototypes(prototypes: lib.FactorioPrototypes, allowedTypes: Set<
/** Shared state for building a unified spritesheet across all categories. */ /** Shared state for building a unified spritesheet across all categories. */
interface SheetState { interface SheetState {
sheet: Jimp; sheet: Image;
metadata: Map<string, lib.ExportMetadataEntry>; metadata: Map<string, lib.ExportMetadataEntry>;
iconCache: IconCache; iconCache: IconCache;
simpleIcons: Map<string, number>; simpleIcons: Map<string, number>;
@@ -340,7 +341,7 @@ const SHEET_WIDTH = 1024;
async function createSheetState(): Promise<SheetState> { async function createSheetState(): Promise<SheetState> {
return { return {
sheet: await Jimp.create(SHEET_WIDTH, SHEET_ICON_SIZE), sheet: new Jimp({ width: SHEET_WIDTH, height: SHEET_ICON_SIZE }),
metadata: new Map(), metadata: new Map(),
iconCache: new Map(), iconCache: new Map(),
simpleIcons: new Map(), simpleIcons: new Map(),
@@ -353,7 +354,7 @@ async function growSheet(state: SheetState) {
const row = Math.floor(state.pos / (SHEET_WIDTH / SHEET_ICON_SIZE)); const row = Math.floor(state.pos / (SHEET_WIDTH / SHEET_ICON_SIZE));
const neededHeight = (row + 1) * SHEET_ICON_SIZE; const neededHeight = (row + 1) * SHEET_ICON_SIZE;
if (neededHeight > state.sheet.bitmap.height) { if (neededHeight > state.sheet.bitmap.height) {
const extended = await Jimp.create(SHEET_WIDTH, neededHeight); const extended = new Jimp({ width: SHEET_WIDTH, height: neededHeight });
extended.composite(state.sheet, 0, 0); extended.composite(state.sheet, 0, 0);
(state.sheet as any).bitmap = (extended as any).bitmap; (state.sheet as any).bitmap = (extended as any).bitmap;
} }
@@ -384,7 +385,7 @@ async function exportItems(
continue; continue;
} }
let icon: Jimp | null = null; let icon: Image | null = null;
let iconPos: number | undefined; let iconPos: number | undefined;
if (item.icons) { if (item.icons) {
icon = await loadLayeredIcon( icon = await loadLayeredIcon(
@@ -608,8 +609,8 @@ export async function exportData(server: FactorioServer) {
// Crop sheet to actual used height and write single spritesheet + metadata. // Crop sheet to actual used height and write single spritesheet + metadata.
const usedRows = Math.ceil(state.pos / (SHEET_WIDTH / SHEET_ICON_SIZE)); const usedRows = Math.ceil(state.pos / (SHEET_WIDTH / SHEET_ICON_SIZE));
state.sheet.crop(0, 0, SHEET_WIDTH, Math.max(usedRows * SHEET_ICON_SIZE, 1)); state.sheet.crop({ x: 0, y: 0, w: SHEET_WIDTH, h: Math.max(usedRows * SHEET_ICON_SIZE, 1) });
zip.file("export/spritesheet.png", await state.sheet.getBufferAsync(Jimp.MIME_PNG)); zip.file("export/spritesheet.png", await state.sheet.getBuffer(JimpMime.png));
zip.file("export/metadata.json", JSON.stringify([...state.metadata.entries()] satisfies lib.ExportMetadata)); zip.file("export/metadata.json", JSON.stringify([...state.metadata.entries()] satisfies lib.ExportMetadata));
server._logger.info(`Export complete: ${state.metadata.size} icons on ${usedRows} row(s)`); server._logger.info(`Export complete: ${state.metadata.size} icons on ${usedRows} row(s)`);