mc-assets 0.2.24 → 0.2.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/atlasParser.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare class AtlasParser {
|
|
|
43
43
|
imageType: "latest" | "legacy";
|
|
44
44
|
version: string;
|
|
45
45
|
} | undefined;
|
|
46
|
-
makeNewAtlas(version: string, getCustomImage?: (itemName: string) => DataUrl | HTMLImageElement | boolean | void,
|
|
46
|
+
makeNewAtlas(version: string, getCustomImage?: (itemName: string) => DataUrl | HTMLImageElement | boolean | void, _unusedTileSize?: number, getTextureSortRankOrTopTextures?: string[] | ((key: string) => number), addTextures?: string[]): Promise<{
|
|
47
47
|
canvas: HTMLCanvasElement;
|
|
48
48
|
atlas: import("./atlasCreator").JsonAtlas;
|
|
49
49
|
readonly newAtlasParser: AtlasParser;
|
package/dist/atlasParser.js
CHANGED
|
@@ -45,12 +45,12 @@ export class AtlasParser {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
async makeNewAtlas(version, getCustomImage,
|
|
48
|
+
async makeNewAtlas(version, getCustomImage, _unusedTileSize = this.atlas.latest.tileSize, getTextureSortRankOrTopTextures, addTextures = []) {
|
|
49
49
|
const itemsAtlases = this.atlasJson;
|
|
50
50
|
const newTextures = {};
|
|
51
51
|
const legacyImg = this.atlasHasLegacyImage ? await getLoadedImage(this.legacyImage) : null;
|
|
52
52
|
const latestImg = await getLoadedImage(this.latestImage);
|
|
53
|
-
for (const
|
|
53
|
+
for (const itemName of new Set([...Object.keys(itemsAtlases.latest.textures), ...addTextures])) {
|
|
54
54
|
const customImage = getCustomImage?.(itemName);
|
|
55
55
|
if (customImage === false)
|
|
56
56
|
continue;
|
|
@@ -67,7 +67,7 @@ export class AtlasParser {
|
|
|
67
67
|
}
|
|
68
68
|
const info = this.getTextureInfo(itemName, version);
|
|
69
69
|
if (!info)
|
|
70
|
-
throw new Error(`Missing texture info for ${itemName}`);
|
|
70
|
+
throw new Error(`Missing texture info from the provided atlas for ${itemName} and not custom data is provided`);
|
|
71
71
|
const { u, v, su, sv } = info;
|
|
72
72
|
const atlas = info.version === 'latest' ? itemsAtlases.latest : itemsAtlases.legacy;
|
|
73
73
|
const image = info.imageType === 'latest' ? latestImg : legacyImg;
|
|
@@ -81,8 +81,13 @@ export class AtlasParser {
|
|
|
81
81
|
img: image
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
const newTexturesKeys = Object.keys(newTextures);
|
|
85
|
+
if (getTextureSortRankOrTopTextures) {
|
|
86
|
+
const getRankFn = typeof getTextureSortRankOrTopTextures === 'function' ? getTextureSortRankOrTopTextures : (key) => getTextureSortRankOrTopTextures.includes(key) ? 1 : -1;
|
|
87
|
+
newTexturesKeys.sort((a, b) => getRankFn(b) - getRankFn(a));
|
|
88
|
+
}
|
|
84
89
|
const { json, canvas } = makeTextureAtlas({
|
|
85
|
-
input:
|
|
90
|
+
input: newTexturesKeys,
|
|
86
91
|
getLoadedImage: (name) => {
|
|
87
92
|
const texture = newTextures[name];
|
|
88
93
|
const image = texture.img;
|