mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Local pokemon box images
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const request = require('node-superfetch');
|
||||
const { createCanvas } = require('canvas');
|
||||
const path = require('path');
|
||||
const { removeDuplicates, firstUpperCase, delay } = require('../../util/Util');
|
||||
const missingno = require('../../assets/json/missingno');
|
||||
@@ -133,20 +134,6 @@ module.exports = class Pokemon {
|
||||
return `https://serebii.net/pokemon/art/${this.displayID}${name ? `-${name}` : ''}.png`;
|
||||
}
|
||||
|
||||
get boxImageURL() {
|
||||
if (this.missingno) return missingno.box;
|
||||
return `https://www.serebii.net/pokedex-sv/icon/${this.displayID}.png`;
|
||||
}
|
||||
|
||||
formBoxImageURL(variety) {
|
||||
if (this.missingno) return missingno.box;
|
||||
const found = this.varieties.find(vrity => variety ? vrity.id === variety.toLowerCase() : vrity.default);
|
||||
const name = found.default ? '' : found.mega
|
||||
? found.name.toLowerCase().split(' ').map(n => n.charAt(0)).join('')
|
||||
: found.name.toLowerCase().charAt(0);
|
||||
return `https://www.serebii.net/pokedex-sv/icon/${this.displayID}${name ? `-${name}` : ''}.png`;
|
||||
}
|
||||
|
||||
get serebiiURL() {
|
||||
if (this.missingno) return missingno.url;
|
||||
return `https://www.serebii.net/pokedex-sv/${this.displayID}.shtml`;
|
||||
@@ -157,6 +144,16 @@ module.exports = class Pokemon {
|
||||
return `https://www.smogon.com/dex/${gen.toLowerCase()}/pokemon/${this.slug}/`;
|
||||
}
|
||||
|
||||
async generateBoxImage() {
|
||||
if (!this.store.sprites) await this.store.loadSprites();
|
||||
const canvas = createCanvas(40, 30);
|
||||
const ctx = canvas.getContext('2d');
|
||||
const x = 40 * (this.id % 12);
|
||||
const y = Math.floor(this.id / 12) * 30;
|
||||
ctx.drawImage(this.store.sprites, x, y, 40, 30, 0, 0, 40, 30);
|
||||
return canvas.toBuffer();
|
||||
}
|
||||
|
||||
async fetchSmogonTiers(...gens) {
|
||||
for (const gen of gens) {
|
||||
if (!this.store.smogonData[gen.toLowerCase()]) await this.store.fetchSmogonData(gen.toLowerCase());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const request = require('node-superfetch');
|
||||
const { loadImage } = require('canvas');
|
||||
const path = require('path');
|
||||
const Pokemon = require('./Pokemon');
|
||||
const MoveStore = require('./MoveStore');
|
||||
const AbilityStore = require('./AbilityStore');
|
||||
@@ -16,6 +18,14 @@ module.exports = class PokemonStore extends Collection {
|
||||
this.moves = new MoveStore();
|
||||
this.abilities = new AbilityStore();
|
||||
this.items = new ItemStore();
|
||||
this.sprites = null;
|
||||
}
|
||||
|
||||
async loadSprites() {
|
||||
if (this.sprites) return this.sprites;
|
||||
const sprites = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'pokedex', 'sprites.png'));
|
||||
this.sprites = sprites;
|
||||
return this.sprites;
|
||||
}
|
||||
|
||||
async fetch(query) {
|
||||
|
||||
Reference in New Issue
Block a user