Skip to content

Commit c85c8c8

Browse files
committed
Added code support for forms
* Updated pokedex.csv to include a column for `form` as a string identifier * Changed data retrieval to get pokemon by species and form, not just species * Changed pokemon generation and species changes to include form * Updated image retrieval to includ form * Updated image source to static.dpsplus.app domain
1 parent a2a4f5b commit c85c8c8

File tree

8 files changed

+451
-436
lines changed

8 files changed

+451
-436
lines changed

src/app/home/home.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class HomeComponent implements OnInit {
187187
this.shadowDefenderInput = defender;
188188
}
189189
else { // no saved value, so creating new one
190-
this.shadowDefenderInput = new PokemonModel(381, this.dataService, input.code, input.name, false, false);
190+
this.shadowDefenderInput = new PokemonModel(381, null, this.dataService, input.code, input.name, false, false);
191191
this.shadowDefenderInput.level = 40;
192192
this.shadowDefenderInput.attackIv = 15;
193193
this.shadowDefenderInput.defenseIv = 15;
@@ -300,7 +300,7 @@ export class HomeComponent implements OnInit {
300300
private addPokemon(code: string, title: string, isRemovable: boolean, atIndex: number) {
301301
if (this.shadowPokemonInputs.length <= atIndex) { // we don't have a shadow pokemon in memory
302302
let defaultPokemon = atIndex == 0 ? 149 : (atIndex == 1 ? 384 : (Math.floor(Math.random() * 386) + 1));
303-
const newPokemon = new PokemonModel(defaultPokemon, this.dataService, code, title, isRemovable, false);
303+
const newPokemon = new PokemonModel(defaultPokemon, null, this.dataService, code, title, isRemovable, false);
304304
this.shadowPokemonInputs.push(newPokemon);
305305
}
306306
else { // we do have a shadow pokemon, and need to update the code and title

src/app/shared/components/pokemon-input/pokemon-input.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h2>{{ model.internalTitle }}</h2>
66
</button>
77
</div>
88
<div fxLayout fxLayoutGap="8px">
9-
<img class="pokemon-image" src="https://dpsplus-assets.firebaseapp.com/mon-icons/{{selectedSpecies}}.svg" alt="{{selectedName}} image" width="72" height="72" />
9+
<img class="pokemon-image" src="https://static.dpsplus.app/mon-icons/{{selectedSpecies + (selectedForm || '')}}.svg" alt="{{selectedName}} image" width="72" height="72" />
1010
<div fxLayout="column" fxLayoutAlign="start">
1111

1212
<mat-form-field class="pokemon-name-input">

src/app/shared/components/pokemon-input/pokemon-input.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class PokemonInputComponent implements OnInit {
3434
public pokemonForm: FormGroup;
3535
public filteredPokemon: Observable<any[]>;
3636
public selectedSpecies: number;
37+
public selectedForm: string;
3738
public selectedName: string;
3839

3940
private _id: string;
@@ -63,7 +64,8 @@ export class PokemonInputComponent implements OnInit {
6364
if (typeof value !== 'string') {
6465
this.selectedName = value[0];
6566
this.selectedSpecies = value[1] as number;
66-
this.model.species = this.selectedSpecies;
67+
this.selectedForm = value[2] as string;
68+
this.model.changeSpecies(this.selectedSpecies, this.selectedForm);
6769
}
6870
});
6971
this.pokemonForm.get('level').valueChanges.forEach((value: number) => this.model.level = value);
@@ -85,7 +87,7 @@ export class PokemonInputComponent implements OnInit {
8587

8688
public submitForm() {
8789
const formModel = this.pokemonForm.value;
88-
this.model.species = this.selectedSpecies;
90+
this.model.changeSpecies(this.selectedSpecies, this.selectedForm);
8991
this.model.level = formModel.level as number;
9092
this.model.attackIv = formModel.attackIv as number;
9193
this.model.defenseIv = formModel.defenseIv as number;
@@ -101,7 +103,7 @@ export class PokemonInputComponent implements OnInit {
101103

102104
private resetForm() {
103105
this.pokemonForm.reset({
104-
species: [this.model.name, this.model.species],
106+
species: [this.model.name, this.model.species, this.model.form],
105107
level: this.model.level,
106108
attackIv: this.model.attackIv,
107109
defenseIv: this.model.defenseIv,

src/app/shared/models/pokemon.model.ts

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DataService } from '../services/data.service';
33

44
export class PokemonModel {
55
private _species: number;
6+
private _form: string;
67
public name: string;
78
public type1: string;
89
public type2: string;
@@ -24,8 +25,8 @@ export class PokemonModel {
2425
public isRemovable: boolean;
2526
public canSelectMoves: boolean;
2627

27-
constructor(species: number, private dataService: DataService, internalId?: string, internalTitle?: string, isRemovable?: boolean, canSelectMoves?: boolean) {
28-
this.species = species;
28+
constructor(species: number, form: string, private dataService: DataService, internalId?: string, internalTitle?: string, isRemovable?: boolean, canSelectMoves?: boolean) {
29+
this.changeSpecies(species, form);
2930
this.level = 30;
3031
this.attackIv = 15;
3132
this.defenseIv = 15;
@@ -39,15 +40,48 @@ export class PokemonModel {
3940
this.canSelectMoves = canSelectMoves || false;
4041
}
4142

42-
set species(species: number) {
43+
get species(): number {
44+
return this._species;
45+
}
46+
47+
get form(): string {
48+
return this._form;
49+
}
50+
51+
get levelMultiplier(): number {
52+
return this.dataService.getLevelMultiplier(this.level);
53+
}
54+
55+
get attack(): number {
56+
return (this.attackBase + this.attackIv) * this.levelMultiplier;
57+
}
58+
59+
get defense(): number {
60+
return (this.defenseBase + this.defenseIv) * this.levelMultiplier;
61+
}
62+
63+
get stamina(): number {
64+
return (this.staminaBase + this.staminaIv) * this.levelMultiplier;
65+
}
66+
67+
get cp(): number {
68+
return Math.floor(Math.max((this.attack * Math.pow(this.defense, 0.5) * Math.pow(this.stamina, 0.5) * Math.pow(this.levelMultiplier, 2)) / 10, 10));
69+
}
70+
71+
get paddedNumber(): string {
72+
return (this.species < 10 ? '00' + this.species : (this.species < 100) ? '0' + this.species : '' + this.species);
73+
}
74+
75+
public changeSpecies(species: number, form: string) {
4376
this._species = species;
44-
let pokedexData = this.dataService.getPokemon(species);
77+
this._form = form;
78+
let pokedexData = this.dataService.getPokemon(species, form);
4579
this.name = pokedexData[0];
46-
this.type1 = pokedexData[2];
47-
this.type2 = (pokedexData[3] && pokedexData[3] != 'N/A') ? pokedexData[3] : null;
48-
this.attackBase = parseInt(pokedexData[4]);
49-
this.defenseBase = parseInt(pokedexData[5]);
50-
this.staminaBase = parseInt(pokedexData[6]);
80+
this.type1 = pokedexData[3];
81+
this.type2 = (pokedexData[4] && pokedexData[4] != 'N/A') ? pokedexData[4] : null;
82+
this.attackBase = parseInt(pokedexData[5]);
83+
this.defenseBase = parseInt(pokedexData[6]);
84+
this.staminaBase = parseInt(pokedexData[7]);
5185

5286
if (this._species == 151) { // darn you mew. y u break all the things.
5387
const mewQuick = [ "c",
@@ -98,41 +132,15 @@ export class PokemonModel {
98132
this.parseMoves(mewCharge, false); // parse charge moves
99133
}
100134
else {
101-
this.parseMoves(pokedexData.slice(7, 21), true); // parse quick moves
102-
this.parseMoves(pokedexData.slice(21, 37), false); // parse charge moves
135+
this.parseMoves(pokedexData.slice(8, 22), true); // parse quick moves
136+
this.parseMoves(pokedexData.slice(22, 38), false); // parse charge moves
103137
}
104138
}
105-
get species(): number {
106-
return this._species;
107-
}
108-
109-
get levelMultiplier(): number {
110-
return this.dataService.getLevelMultiplier(this.level);
111-
}
112-
113-
get attack(): number {
114-
return (this.attackBase + this.attackIv) * this.levelMultiplier;
115-
}
116-
117-
get defense(): number {
118-
return (this.defenseBase + this.defenseIv) * this.levelMultiplier;
119-
}
120-
121-
get stamina(): number {
122-
return (this.staminaBase + this.staminaIv) * this.levelMultiplier;
123-
}
124-
125-
get cp(): number {
126-
return Math.floor(Math.max((this.attack * Math.pow(this.defense, 0.5) * Math.pow(this.stamina, 0.5) * Math.pow(this.levelMultiplier, 2)) / 10, 10));
127-
}
128-
129-
get paddedNumber(): string {
130-
return (this.species < 10 ? '00' + this.species : (this.species < 100) ? '0' + this.species : '' + this.species);
131-
}
132139

133140
public serialize() {
134141
return JSON.stringify({
135142
species: this.species,
143+
form: this.form,
136144
level: this.level,
137145
attackIv: this.attackIv,
138146
defenseIv: this.defenseIv,
@@ -149,7 +157,9 @@ export class PokemonModel {
149157

150158
public deserialize(source: string) {
151159
const sourceObj: any = JSON.parse(source);
152-
if (sourceObj.species) this.species = sourceObj.species;
160+
if (sourceObj.species) {
161+
this.changeSpecies(sourceObj.species, sourceObj.form);
162+
}
153163
if (sourceObj.level) this.level = sourceObj.level;
154164
if (sourceObj.attackIv) this.attackIv = sourceObj.attackIv;
155165
if (sourceObj.defenseIv) this.defenseIv = sourceObj.defenseIv;

src/app/shared/services/data.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ export class DataService {
6363
return this._PokedexAlpha.slice();
6464
}
6565

66-
getPokemon(index: number): any[] {
67-
return this._Pokedex[index];
66+
getPokemon(species: number, form: string): any[] {
67+
for (let pokemon of this._Pokedex)
68+
if (pokemon[1] == species && (!form || pokemon[2] == form))
69+
return pokemon;
70+
return null;
6871
}
6972

7073
getLevelMultiplier(level: number): number {

src/app/shared/services/dpsplus.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export class DpsPlusService {
384384
}
385385
else {
386386
for (let pokemon of this.dataService.getPokedex()) {
387-
let selectedPokemon = new PokemonModel(pokemon[1], this.dataService);
387+
let selectedPokemon = new PokemonModel(pokemon[1], pokemon[2], this.dataService);
388388
selectedPokemon.level = 30;
389389
selectedPokemon.attackIv = 15;
390390
selectedPokemon.defenseIv = 15;

src/app/shared/services/storage.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class StorageService {
105105
if (!pokemonSerialized)
106106
return null;
107107
const pokemon: any = JSON.parse(pokemonSerialized);
108-
const result = new PokemonModel(pokemon.species, this.dataService);
108+
const result = new PokemonModel(pokemon.species, pokemon.form, this.dataService);
109109
result.deserialize(pokemonSerialized);
110110
return result;
111111
}

0 commit comments

Comments
 (0)