1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-13 18:21:51 +00:00

Fix sprites not loading

This commit is contained in:
tobspr 2022-01-14 16:38:25 +01:00
parent 497990905a
commit de8afcedc9
5 changed files with 23 additions and 20 deletions

View File

@ -233,7 +233,6 @@ export class BackgroundResourcesLoader {
this.numAssetsToLoadTotal = 0;
this.numAssetsLoaded = 0;
})
.then(MODS.modInterface.injectSprites.bind(MODS.modInterface))
);
}
}

View File

@ -169,6 +169,9 @@ class LoaderImpl {
sprite = new AtlasSprite(spriteName);
this.sprites.set(spriteName, sprite);
}
if (sprite.frozen) {
continue;
}
const link = new SpriteAtlasLink({
packedX: frame.x,
@ -181,10 +184,7 @@ class LoaderImpl {
w: sourceSize.w,
h: sourceSize.h,
});
if (sprite.linksByResolution[scale]) {
// Seems data is already present, might have been replaced by a mod
continue;
}
sprite.linksByResolution[scale] = link;
}
}

View File

@ -71,6 +71,8 @@ export class AtlasSprite extends BaseSprite {
/** @type {Object.<string, SpriteAtlasLink>} */
this.linksByResolution = {};
this.spriteName = spriteName;
this.frozen = false;
}
getRawTexture() {

View File

@ -46,18 +46,30 @@ export class ModInterface {
registerSprite(spriteId, base64string) {
assert(base64string.startsWith("data:image"));
const img = new Image();
img.src = base64string;
const sprite = new AtlasSprite(spriteId);
sprite.frozen = true;
img.addEventListener("load", () => {
for (const resolution in sprite.linksByResolution) {
const link = sprite.linksByResolution[resolution];
link.w = img.width;
link.h = img.height;
link.packedW = img.width;
link.packedH = img.height;
}
});
img.src = base64string;
const link = new SpriteAtlasLink({
w: img.width,
h: img.height,
w: 1,
h: 1,
atlas: img,
packOffsetX: 0,
packOffsetY: 0,
packedW: img.width,
packedH: img.height,
packedW: 1,
packedH: 1,
packedX: 0,
packedY: 0,
});
@ -66,18 +78,9 @@ export class ModInterface {
sprite.linksByResolution["0.5"] = link;
sprite.linksByResolution["0.75"] = link;
this.lazySprites.set(spriteId, sprite);
Loader.sprites.set(spriteId, sprite);
}
injectSprites() {
LOG.log("inject sprites");
this.lazySprites.forEach((sprite, key) => {
Loader.sprites.set(key, sprite);
console.log("override", key);
});
}
/**
*
* @param {object} param0

View File

@ -9,7 +9,6 @@ export const MOD_SIGNALS = {
postInit: new Signal(),
platformInstancesInitialized: new Signal(),
injectSprites: new Signal(),
preprocessTheme: /** @type {TypedSignal<[Object]>} */ (new Signal()),
modifyLevelDefinitions: /** @type {TypedSignal<[Array[Object]]>} */ (new Signal()),
modifyUpgrades: /** @type {TypedSignal<[Object]>} */ (new Signal()),