From 574a9d9d253feeb4a095a2758da0f31e51e96780 Mon Sep 17 00:00:00 2001 From: tobspr Date: Fri, 17 Jun 2022 16:21:32 +0200 Subject: [PATCH] More verbose errors --- src/js/core/sprites.js | 50 +++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/js/core/sprites.js b/src/js/core/sprites.js index d568f994..4caa599c 100644 --- a/src/js/core/sprites.js +++ b/src/js/core/sprites.js @@ -91,14 +91,17 @@ export class AtlasSprite extends BaseSprite { const link = this.linksByResolution[ORIGINAL_SPRITE_SCALE]; - assert( - link, - "Link not known: " + - ORIGINAL_SPRITE_SCALE + - " (having " + - Object.keys(this.linksByResolution) + - ")" - ); + if (!link) { + throw new Error( + "draw: Link for " + + this.spriteName + + " not known: " + + ORIGINAL_SPRITE_SCALE + + " (having " + + Object.keys(this.linksByResolution) + + ")" + ); + } const width = w || link.w; const height = h || link.h; @@ -166,7 +169,15 @@ export class AtlasSprite extends BaseSprite { const link = this.linksByResolution[scale]; if (!link) { - assert(false, `Link not known: ${scale} (having ${Object.keys(this.linksByResolution)})`); + throw new Error( + "drawCached: Link for " + + this.spriteName + + " at scale " + + scale + + " not known (having " + + Object.keys(this.linksByResolution) + + ")" + ); } const scaleW = w / link.w; @@ -244,7 +255,15 @@ export class AtlasSprite extends BaseSprite { const link = this.linksByResolution[scale]; if (!link) { - assert(false, `Link not known: ${scale} (having ${Object.keys(this.linksByResolution)})`); + throw new Error( + "drawCachedWithClipRect: Link for " + + this.spriteName + + " at scale " + + scale + + " not known (having " + + Object.keys(this.linksByResolution) + + ")" + ); } const scaleW = w / link.w; @@ -298,6 +317,17 @@ export class AtlasSprite extends BaseSprite { getAsHTML(w, h) { const link = this.linksByResolution["0.5"]; + if (!link) { + throw new Error( + "getAsHTML: Link for " + + this.spriteName + + " at scale 0.5" + + " not known (having " + + Object.keys(this.linksByResolution) + + ")" + ); + } + // Find out how much we have to scale it so that it fits const scaleX = w / link.w; const scaleY = h / link.h;