mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-10-01 07:10:46 -05:00
Implement HP Type and Pokeball selector in Teambuilder UI (#1335)
This commit is contained in:
committed by
Guangcong Luo
parent
635c09d7ea
commit
d564debfb3
@@ -37,6 +37,7 @@
|
||||
|
||||
// details
|
||||
'change .detailsform input': 'detailsChange',
|
||||
'change .detailsform select': 'detailsChange',
|
||||
'click .changeform' : 'altForm',
|
||||
'click .altform' : 'altForm',
|
||||
|
||||
@@ -2392,6 +2393,26 @@
|
||||
buf += '</div></div>';
|
||||
}
|
||||
|
||||
if (this.curTeam.gen > 2) {
|
||||
buf += '<div class="formrow"><label class="formlabel">Pokeball</label><div><select name="pokeball">';
|
||||
buf += '<option value=""' + (!set.pokeball ? ' selected="selected"' : '') + '></option>'; // unset
|
||||
var balls = Dex.forGen(this.curTeam.gen).getPokeballs();
|
||||
for (var i = 0; i < balls.length; i++) {
|
||||
var id = toID(balls[i]);
|
||||
buf += '<option value="' + id + '"' + (set.pokeball === id ? ' selected="selected"' : '') + '>' + balls[i] + '</option>';
|
||||
}
|
||||
buf += '</select></div></div>';
|
||||
}
|
||||
|
||||
if (this.curTeam.gen > 6) {
|
||||
buf += '<div class="formrow"><label class="formlabel">HP Type:</label><div><select name="hptype">';
|
||||
buf += '<option value=""' + (!set.hpType ? ' selected="selected"' : '') + '></option>'; // unset
|
||||
for (var type in exports.BattleTypeChart) {
|
||||
buf += '<option value="' + type + '"' + (set.hpType === type ? ' selected="selected"' : '') + '>' + type + '</option>';
|
||||
}
|
||||
buf += '</select></div></div>';
|
||||
}
|
||||
|
||||
buf += '</form>';
|
||||
if (template.otherForms && template.baseSpecies !== 'Unown') {
|
||||
buf += '<button class="altform">Change sprite</button>';
|
||||
@@ -2424,6 +2445,7 @@
|
||||
delete set.shiny;
|
||||
}
|
||||
|
||||
// gender
|
||||
var gender = this.$chart.find('input[name=gender]:checked').val();
|
||||
if (gender === 'M' || gender === 'F') {
|
||||
set.gender = gender;
|
||||
@@ -2431,6 +2453,22 @@
|
||||
delete set.gender;
|
||||
}
|
||||
|
||||
// pokeball
|
||||
var pokeball = this.$chart.find('select[name=pokeball]').val();
|
||||
if (pokeball && Dex.forGen(this.curTeam.gen).getItem(pokeball).isPokeball) {
|
||||
set.pokeball = pokeball;
|
||||
} else {
|
||||
delete set.pokeball;
|
||||
}
|
||||
|
||||
// HP type
|
||||
var hpType = this.$chart.find('select[name=hptype]').val();
|
||||
if (hpType && exports.BattleTypeChart[hpType]) {
|
||||
set.hpType = hpType;
|
||||
} else {
|
||||
delete set.hpType;
|
||||
}
|
||||
|
||||
// update details cell
|
||||
var buf = '';
|
||||
var GenderChart = {
|
||||
|
||||
@@ -940,6 +940,7 @@ class Item implements Effect {
|
||||
readonly onDrive: TypeName;
|
||||
readonly fling: any;
|
||||
readonly naturalGift: any;
|
||||
readonly isPokeball: boolean;
|
||||
|
||||
constructor(id: ID, name: string, data: any) {
|
||||
if (!data || typeof data !== 'object') data = {};
|
||||
@@ -965,6 +966,7 @@ class Item implements Effect {
|
||||
this.onDrive = data.onDrive || '';
|
||||
this.fling = data.fling || null;
|
||||
this.naturalGift = data.naturalGift || null;
|
||||
this.isPokeball = !!data.isPokeball;
|
||||
|
||||
if (!this.gen) {
|
||||
if (this.num >= 577) {
|
||||
|
||||
@@ -215,6 +215,8 @@ const Dex = new class implements ModdedDex {
|
||||
readonly statNames: ReadonlyArray<StatName> = ['hp', 'atk', 'def', 'spa', 'spd', 'spe'];
|
||||
readonly statNamesExceptHP: ReadonlyArray<StatNameExceptHP> = ['atk', 'def', 'spa', 'spd', 'spe'];
|
||||
|
||||
pokeballs: string[] | null = null;
|
||||
|
||||
resourcePrefix = (() => {
|
||||
let prefix = '';
|
||||
if (!window.document || !document.location || document.location.protocol !== 'http:') prefix = 'https:';
|
||||
@@ -755,6 +757,17 @@ const Dex = new class implements ModdedDex {
|
||||
let sanitizedType = type.replace(/\?/g, '%3f');
|
||||
return '<img src="' + Dex.resourcePrefix + 'sprites/types/' + sanitizedType + '.png" alt="' + type + '" height="14" width="32"' + (b ? ' class="b"' : '') + ' />';
|
||||
}
|
||||
|
||||
getPokeballs() {
|
||||
if (this.pokeballs) return this.pokeballs;
|
||||
this.pokeballs = [];
|
||||
if (!window.BattleItems) window.BattleItems = {};
|
||||
for (const data of Object.values(window.BattleItems) as AnyObject[]) {
|
||||
if (!data.isPokeball) continue;
|
||||
this.pokeballs.push(data.name);
|
||||
}
|
||||
return this.pokeballs;
|
||||
}
|
||||
};
|
||||
|
||||
class ModdedDex {
|
||||
@@ -765,6 +778,7 @@ class ModdedDex {
|
||||
Items: {} as any as {[k: string]: Item},
|
||||
Templates: {} as any as {[k: string]: Template},
|
||||
};
|
||||
pokeballs: string[] | null = null;
|
||||
getAbility: (nameOrAbility: string | Ability | null | undefined) => Ability = Dex.getAbility;
|
||||
constructor(modid: ID) {
|
||||
this.modid = modid;
|
||||
@@ -869,6 +883,18 @@ class ModdedDex {
|
||||
this.cache.Templates[id] = template;
|
||||
return template;
|
||||
}
|
||||
|
||||
getPokeballs() {
|
||||
if (this.pokeballs) return this.pokeballs;
|
||||
this.pokeballs = [];
|
||||
if (!window.BattleItems) window.BattleItems = {};
|
||||
for (const data of Object.values(window.BattleItems) as AnyObject[]) {
|
||||
if (data.gen && data.gen > this.gen) continue;
|
||||
if (!data.isPokeball) continue;
|
||||
this.pokeballs.push(data.name);
|
||||
}
|
||||
return this.pokeballs;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof require === 'function') {
|
||||
|
||||
Reference in New Issue
Block a user