diff --git a/packages/host/package.json b/packages/host/package.json index 80f839c6..b552445f 100644 --- a/packages/host/package.json +++ b/packages/host/package.json @@ -38,8 +38,12 @@ "dependencies": { "@clusterio/lib": "workspace:^", + "@jimp/core": "^1.6.1", + "@jimp/js-png": "^1.6.1", + "@jimp/plugin-crop": "^1.6.1", + "@jimp/plugin-resize": "^1.6.1", + "@jimp/types": "^1.6.1", "@sinclair/typebox": "catalog:", - "jimp": "^1.6.1", "pidusage": "^4.1.0", "rcon-client": "^4.2.5", "semver": "catalog:", diff --git a/packages/host/src/export.ts b/packages/host/src/export.ts index cb7f73d5..5df9d1df 100644 --- a/packages/host/src/export.ts +++ b/packages/host/src/export.ts @@ -1,7 +1,11 @@ // Export of item icons and locale import fs from "node:fs/promises"; import path from "path"; -import { Jimp, JimpMime, type JimpInstance } from "jimp"; +import { createJimp } from "@jimp/core"; +import png from "@jimp/js-png"; +import * as crop from "@jimp/plugin-crop"; +import * as resize from "@jimp/plugin-resize"; +import type {} from "@jimp/types"; // needed to name jimp types in export.d.ts import yazl from "yazl"; import * as lib from "@clusterio/lib"; @@ -147,7 +151,9 @@ async function loadFile( return await modZip.zip.readFile(path.posix.join(modZip.root, filePath)); } -type Image = JimpInstance; +// Only the parts of jimp the export uses +const Jimp = createJimp({ formats: [png], plugins: [crop.methods, resize.methods] }); +type Image = InstanceType; type IconCache = Map; async function loadIcon( server: FactorioServer, @@ -618,7 +624,7 @@ async function buildExport(server: FactorioServer, zipCache: ZipCache) { // Crop sheet to actual used height and write single spritesheet + metadata. const usedRows = Math.ceil(state.pos / (SHEET_WIDTH / SHEET_ICON_SIZE)); state.sheet.crop({ x: 0, y: 0, w: SHEET_WIDTH, h: Math.max(usedRows * SHEET_ICON_SIZE, 1) }); - zip.addBuffer(await state.sheet.getBuffer(JimpMime.png), "export/spritesheet.png"); + zip.addBuffer(await state.sheet.getBuffer("image/png"), "export/spritesheet.png"); addJson("export/metadata.json", state.metadata satisfies lib.ExportMetadata); zip.end();