Skip to content

Commit

Permalink
Merge pull request #22 from Rezzo64/placeholder-sprites
Browse files Browse the repository at this point in the history
Feature: Placeholder Sprites part 2
  • Loading branch information
Rezzo64 authored Nov 20, 2023
2 parents c31a0c0 + 15cc47f commit 3017957
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 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
22 changes: 15 additions & 7 deletions play.pokemonshowdown.com/src/battle-dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,14 @@ const Dex = new class implements ModdedDex {
let resourcePrefix = Dex.resourcePrefix;
let spriteDir = 'sprites/';
let fakeSprite = false;
let modName = modSpecies.spriteid;
let id = toID(modName);
options.mod = this.getSpriteMod(options.mod, id, isFront ? 'front' : 'back', modSpecies.exists !== false);
let modSprite = modSpecies.spriteid;
let modSpriteId = toID(modSprite);
options.mod = this.getSpriteMod(options.mod, modSpriteId, isFront ? 'front' : 'back', modSpecies.exists);
if (options.mod) {
resourcePrefix = Dex.modResourcePrefix;
spriteDir = `${options.mod}/sprites/`;
fakeSprite = true;
if (this.getSpriteMod(options.mod, id, (isFront ? 'front' : 'back') + '-shiny', modSpecies.exists !== false) === '') options.shiny = false;
if (this.getSpriteMod(options.mod, modSpriteId, (isFront ? 'front' : 'back') + '-shiny', modSpecies.exists) === '') options.shiny = false;
}

const species = Dex.species.get(pokemon);
Expand Down Expand Up @@ -667,7 +667,7 @@ const Dex = new class implements ModdedDex {
}

let fakeAnim = false;
if (fakeSprite && window.ModSprites[id][options.mod].includes('ani' + facing)){
if (fakeSprite && window.ModSprites[modSpriteId][options.mod].includes('ani' + facing)){
fakeAnim = true;
animationData[facing] = {};
animationData[facing].w = 192;
Expand Down 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
// window.modsprites[modSpriteId]: checks if it has custom sprite data.
// window.BattlePokemonSprites[modSpriteId]: checks if it is a real Pokemon.
if (!window.ModSprites[modSpriteId] && !window.BattlePokemonSprites[modSpriteId] && pokemon !== 'substitute') {
spriteData = Dex.getSpriteData('substitute', spriteData.isFrontSprite, {
gen: options.gen,
mod: options.mod,
});
}
return spriteData;
}

Expand Down Expand Up @@ -1397,4 +1405,4 @@ if (typeof require === 'function') {
// in Node
(global as any).Dex = Dex;
(global as any).toID = toID;
}
}

0 comments on commit 3017957

Please sign in to comment.