mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 02:31:51 +00:00
Fix sprites not loading
This commit is contained in:
parent
497990905a
commit
de8afcedc9
@ -233,7 +233,6 @@ export class BackgroundResourcesLoader {
|
|||||||
this.numAssetsToLoadTotal = 0;
|
this.numAssetsToLoadTotal = 0;
|
||||||
this.numAssetsLoaded = 0;
|
this.numAssetsLoaded = 0;
|
||||||
})
|
})
|
||||||
.then(MODS.modInterface.injectSprites.bind(MODS.modInterface))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -169,6 +169,9 @@ class LoaderImpl {
|
|||||||
sprite = new AtlasSprite(spriteName);
|
sprite = new AtlasSprite(spriteName);
|
||||||
this.sprites.set(spriteName, sprite);
|
this.sprites.set(spriteName, sprite);
|
||||||
}
|
}
|
||||||
|
if (sprite.frozen) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const link = new SpriteAtlasLink({
|
const link = new SpriteAtlasLink({
|
||||||
packedX: frame.x,
|
packedX: frame.x,
|
||||||
@ -181,10 +184,7 @@ class LoaderImpl {
|
|||||||
w: sourceSize.w,
|
w: sourceSize.w,
|
||||||
h: sourceSize.h,
|
h: sourceSize.h,
|
||||||
});
|
});
|
||||||
if (sprite.linksByResolution[scale]) {
|
|
||||||
// Seems data is already present, might have been replaced by a mod
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
sprite.linksByResolution[scale] = link;
|
sprite.linksByResolution[scale] = link;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,6 +71,8 @@ export class AtlasSprite extends BaseSprite {
|
|||||||
/** @type {Object.<string, SpriteAtlasLink>} */
|
/** @type {Object.<string, SpriteAtlasLink>} */
|
||||||
this.linksByResolution = {};
|
this.linksByResolution = {};
|
||||||
this.spriteName = spriteName;
|
this.spriteName = spriteName;
|
||||||
|
|
||||||
|
this.frozen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
getRawTexture() {
|
getRawTexture() {
|
||||||
|
|||||||
@ -46,18 +46,30 @@ export class ModInterface {
|
|||||||
registerSprite(spriteId, base64string) {
|
registerSprite(spriteId, base64string) {
|
||||||
assert(base64string.startsWith("data:image"));
|
assert(base64string.startsWith("data:image"));
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.src = base64string;
|
|
||||||
|
|
||||||
const sprite = new AtlasSprite(spriteId);
|
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({
|
const link = new SpriteAtlasLink({
|
||||||
w: img.width,
|
w: 1,
|
||||||
h: img.height,
|
h: 1,
|
||||||
atlas: img,
|
atlas: img,
|
||||||
packOffsetX: 0,
|
packOffsetX: 0,
|
||||||
packOffsetY: 0,
|
packOffsetY: 0,
|
||||||
packedW: img.width,
|
packedW: 1,
|
||||||
packedH: img.height,
|
packedH: 1,
|
||||||
packedX: 0,
|
packedX: 0,
|
||||||
packedY: 0,
|
packedY: 0,
|
||||||
});
|
});
|
||||||
@ -66,18 +78,9 @@ export class ModInterface {
|
|||||||
sprite.linksByResolution["0.5"] = link;
|
sprite.linksByResolution["0.5"] = link;
|
||||||
sprite.linksByResolution["0.75"] = link;
|
sprite.linksByResolution["0.75"] = link;
|
||||||
|
|
||||||
this.lazySprites.set(spriteId, sprite);
|
|
||||||
Loader.sprites.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
|
* @param {object} param0
|
||||||
|
|||||||
@ -9,7 +9,6 @@ export const MOD_SIGNALS = {
|
|||||||
postInit: new Signal(),
|
postInit: new Signal(),
|
||||||
platformInstancesInitialized: new Signal(),
|
platformInstancesInitialized: new Signal(),
|
||||||
|
|
||||||
injectSprites: new Signal(),
|
|
||||||
preprocessTheme: /** @type {TypedSignal<[Object]>} */ (new Signal()),
|
preprocessTheme: /** @type {TypedSignal<[Object]>} */ (new Signal()),
|
||||||
modifyLevelDefinitions: /** @type {TypedSignal<[Array[Object]]>} */ (new Signal()),
|
modifyLevelDefinitions: /** @type {TypedSignal<[Array[Object]]>} */ (new Signal()),
|
||||||
modifyUpgrades: /** @type {TypedSignal<[Object]>} */ (new Signal()),
|
modifyUpgrades: /** @type {TypedSignal<[Object]>} */ (new Signal()),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user