Skip to content

Commit

Permalink
Merge branch 'placeholder-sprites' of https://github.com/Rezzo64/dh2-…
Browse files Browse the repository at this point in the history
…client into placeholder-sprites
  • Loading branch information
Rezzo64 committed Nov 19, 2023
2 parents 1ac9ed5 + 9267500 commit 7f98e2e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion play.pokemonshowdown.com/src/battle-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,11 @@ export class BattleScene implements BattleSceneStub {
if (textBuf) textBuf += ' / ';
textBuf += pokemon.speciesForme;
let url = spriteData.url;
var placeholderSprite = spriteData.isFrontSprite // Pet Mods placeholder sprites
? "https://play.pokemonshowdown.com/sprites/gen5/substitute.png"
: "https://play.pokemonshowdown.com/sprites/gen5-back/substitute.png";
// if (this.paused) url.replace('/xyani', '/xy').replace('.gif', '.png');
buf += '<img src="' + url + '" width="' + spriteData.w + '" height="' + spriteData.h + '" style="position:absolute;top:' + Math.floor(y - spriteData.h / 2) + 'px;left:' + Math.floor(x - spriteData.w / 2) + 'px" />';
buf += '<img src="' + url + '" width="' + spriteData.w + '" height="' + spriteData.h + '" style="position:absolute;top:' + Math.floor(y - spriteData.h / 2) + 'px;left:' + Math.floor(x - spriteData.w / 2) + 'px" onerror="this.src=\'' + placeholderSprite + '\'"/>';
buf2 += '<div style="position:absolute;top:' + (y + 45) + 'px;left:' + (x - 40) + 'px;width:80px;font-size:10px;text-align:center;color:#FFF;">';
const gender = pokemon.gender;
if (gender === 'M' || gender === 'F') {
Expand Down
23 changes: 22 additions & 1 deletion play.pokemonshowdown.com/src/battle-dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,15 @@ const Dex = new class implements ModdedDex {
spriteData.h *= 1.5;
spriteData.y += -11;
}

// Placeholder sprites for Pet Mods Fakemons with no sprite data
checkSpriteExists(spriteData.url, function(exists: any) {
if (!exists) {
spriteData = Dex.getSpriteData('substitute', spriteData.isFrontSprite, {
gen: options.gen,
mod: options.mod,
})
}
});
return spriteData;
}

Expand Down Expand Up @@ -1398,3 +1406,16 @@ if (typeof require === 'function') {
(global as any).Dex = Dex;
(global as any).toID = toID;
}

function checkSpriteExists(url: string, callback: any) {
var img = new Image();
img.onload = function() {
// The image exists
callback(true);
};
img.onerror = function() {
// The image does not exist or could not be loaded
callback(false);
};
img.src = url;
}

0 comments on commit 7f98e2e

Please sign in to comment.