@pkmn/data
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,3 +0,2 @@ | ||
import {GenerationNum, StatsTable, Dex as DexT, ItemName} from '@pkmn/dex-types'; | ||
import {Generations} from './index'; | ||
import {GenerationNum, Generations, StatsTable, Dex as DexT, ItemName} from './index'; | ||
@@ -21,6 +20,15 @@ import {calculate, Pokemon, Move} from '@smogon/calc/adaptable'; | ||
// FIXME test exists override! | ||
describe('exists', () => { | ||
const gens2 = new Generations(Dex, e => !!e.exists && (!('num' in e) || e.num < 10)); | ||
expect(gens2.get(5).species.get('Bulbasaur')).toBeDefined(); | ||
expect(gens2.get(5).species.get('Gengar')).toBeUndefined(); | ||
expect(gens2.get(1).species.get('Chikorita')).toBeUndefined(); | ||
expect(gens2.get(4).abilities.get('Foo')).toBeUndefined(); | ||
expect(gens2.get(5).abilities.get('Stench')).toBeDefined(); | ||
expect(gens2.get(5).abilities.get('Adaptability')).toBeUndefined(); | ||
}); | ||
describe('Abilities', () => { | ||
it('#get', () => { | ||
expect(Gen(1).abilities.get('No Ability')).toBeUndefined(); | ||
expect(Gen(7).abilities.get('foo')).toBeUndefined(); | ||
@@ -27,0 +35,0 @@ expect(Gen(7).abilities.get('Illuminate')!.effectType).toBe('Ability'); |
47
index.ts
import { | ||
AbilityName, | ||
Condition, | ||
Data, | ||
Dex, | ||
Effect, | ||
EggGroup, | ||
@@ -27,5 +27,7 @@ EvoType, | ||
const DEFAULT_EXISTS = (e: Effect | DexSpecies) => { | ||
if (!e.exists || e.isNonstandard || e.id === 'noability') return false; | ||
return !('tier' in e && ['Illegal', 'Unreleased'].includes(e.tier)); | ||
const DEFAULT_EXISTS = (d: Data) => { | ||
if (!d.exists) return false; | ||
if ('isNonstandard' in d && d.isNonstandard) return false; | ||
if (d.kind === 'Ability' && d.id === 'noability') return false; | ||
return !('tier' in d && ['Illegal', 'Unreleased'].includes(d.tier)); | ||
}; | ||
@@ -49,5 +51,5 @@ | ||
const GENERATIONS = Object.create(null) as {[num: number]: Generation}; | ||
export class Generations { | ||
private readonly cache = Object.create(null) as {[num: number]: Generation}; | ||
export class Generations { | ||
private readonly dex: Dex; | ||
@@ -62,4 +64,4 @@ private readonly exists: ExistsFn; | ||
get(gen: GenerationNum) { | ||
if (GENERATIONS[gen]) return GENERATIONS[gen]; | ||
return (GENERATIONS[gen] = new Generation(this.dex.forGen(gen), this.exists)); | ||
if (this.cache[gen]) return this.cache[gen]; | ||
return (this.cache[gen] = new Generation(this.dex.forGen(gen), this.exists)); | ||
} | ||
@@ -97,5 +99,5 @@ | ||
this.species = new Species(this.dex, this.exists); | ||
this.natures = new Natures(this.dex); | ||
this.types = new Types(this.dex); | ||
this.learnsets = new Learnsets(this.dex); | ||
this.natures = new Natures(this.dex, this.exists); | ||
this.types = new Types(this.dex, this.exists); | ||
this.learnsets = new Learnsets(this.dex, this.exists); | ||
this.effects = new Effects(this.dex, this.exists); | ||
@@ -325,5 +327,7 @@ this.stats = new Stats(this.dex); | ||
private readonly dex: Dex; | ||
private readonly exists: ExistsFn; | ||
constructor(dex: Dex) { | ||
constructor(dex: Dex, exists: ExistsFn) { | ||
this.dex = dex; | ||
this.exists = exists; | ||
} | ||
@@ -334,3 +338,3 @@ | ||
const nature = this.dex.getNature(name); | ||
return nature.exists ? nature : undefined; | ||
return this.exists(nature) ? nature : undefined; | ||
} | ||
@@ -361,4 +365,7 @@ | ||
private readonly dex: Dex; | ||
constructor(dex: Dex) { | ||
private readonly exists: ExistsFn; | ||
constructor(dex: Dex, exists: ExistsFn) { | ||
this.dex = dex; | ||
this.exists = exists; | ||
// PS doesn't contain data for the '???' type | ||
@@ -385,3 +392,3 @@ this.unknown = new Type({ | ||
const type = this.dex.getType(name); | ||
if (!type.exists) return undefined; | ||
if (!this.exists(type)) return undefined; | ||
const cached = this.cache[type.id]; | ||
@@ -459,4 +466,7 @@ if (cached) return cached; | ||
private readonly dex: Dex; | ||
constructor(dex: Dex) { | ||
private readonly exists: ExistsFn; | ||
constructor(dex: Dex, exists: ExistsFn) { | ||
this.dex = dex; | ||
this.exists = exists; | ||
} | ||
@@ -466,3 +476,3 @@ | ||
const learnset = await this.dex.getLearnset(toID(name)); | ||
return learnset.exists ? learnset : undefined; | ||
return this.exists(learnset) ? learnset : undefined; | ||
} | ||
@@ -625,4 +635,5 @@ | ||
EffectType, | ||
Effect, | ||
DataKind, | ||
Effect, | ||
Data, | ||
EffectData, | ||
@@ -629,0 +640,0 @@ HitEffect, |
{ | ||
"name": "@pkmn/data", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "build/index.js", | ||
@@ -13,7 +13,7 @@ "types": "build/index.d.ts", | ||
"dependencies": { | ||
"@pkmn/dex-types": "^0.1.1" | ||
"@pkmn/dex-types": "^0.1.2" | ||
}, | ||
"devDependencies": { | ||
"@pkmn/dex": "^0.1.1", | ||
"@pkmn/sim": "^0.1.1", | ||
"@pkmn/dex": "^0.1.2", | ||
"@pkmn/sim": "^0.1.2", | ||
"@smogon/calc": "^0.4.4" | ||
@@ -20,0 +20,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
432667
2336
Updated@pkmn/dex-types@^0.1.2