mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 02:31:51 +00:00
Add support for loading atlases via mods
This commit is contained in:
parent
81da328f5a
commit
99e49d5abb
File diff suppressed because one or more lines are too long
@ -81,6 +81,41 @@ export class ModInterface {
|
|||||||
Loader.sprites.set(spriteId, sprite);
|
Loader.sprites.set(spriteId, sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} imageBase64
|
||||||
|
* @param {string} jsonTextData
|
||||||
|
*/
|
||||||
|
registerAtlas(imageBase64, jsonTextData) {
|
||||||
|
const atlasData = JSON.parse(jsonTextData);
|
||||||
|
const img = new Image();
|
||||||
|
img.src = imageBase64;
|
||||||
|
|
||||||
|
const sourceData = atlasData.frames;
|
||||||
|
for (const spriteName in sourceData) {
|
||||||
|
const { frame, sourceSize, spriteSourceSize } = sourceData[spriteName];
|
||||||
|
|
||||||
|
const sprite = new AtlasSprite(spriteName);
|
||||||
|
Loader.sprites.set(spriteName, sprite);
|
||||||
|
sprite.frozen = true;
|
||||||
|
|
||||||
|
const link = new SpriteAtlasLink({
|
||||||
|
packedX: frame.x,
|
||||||
|
packedY: frame.y,
|
||||||
|
packedW: frame.w,
|
||||||
|
packedH: frame.h,
|
||||||
|
packOffsetX: spriteSourceSize.x,
|
||||||
|
packOffsetY: spriteSourceSize.y,
|
||||||
|
atlas: img,
|
||||||
|
w: sourceSize.w,
|
||||||
|
h: sourceSize.h,
|
||||||
|
});
|
||||||
|
sprite.linksByResolution["0.25"] = link;
|
||||||
|
sprite.linksByResolution["0.5"] = link;
|
||||||
|
sprite.linksByResolution["0.75"] = link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user