Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow PP Ups to be edited #2222

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions play.pokemonshowdown.com/js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1374,10 +1374,10 @@
// moves
if (!set.moves) set.moves = [];
buf += '<div class="setcol setcol-moves"><div class="setcell"><label>Moves</label>';
buf += '<input type="text" name="move1" class="textbox chartinput" value="' + BattleLog.escapeHTML(set.moves[0]) + '" autocomplete="off" /></div>';
buf += '<div class="setcell"><input type="text" name="move2" class="textbox chartinput" value="' + BattleLog.escapeHTML(set.moves[1]) + '" autocomplete="off" /></div>';
buf += '<div class="setcell"><input type="text" name="move3" class="textbox chartinput" value="' + BattleLog.escapeHTML(set.moves[2]) + '" autocomplete="off" /></div>';
buf += '<div class="setcell"><input type="text" name="move4" class="textbox chartinput" value="' + BattleLog.escapeHTML(set.moves[3]) + '" autocomplete="off" /></div>';
for (var i = 0; i <= 3; i++) {
if (i > 0) buf += '<div class="setcell">';
buf += '<input type="text" name="move' + (i + 1) + '" class="textbox chartinput" value="' + BattleLog.escapeHTML(set.moves[i]) + '" autocomplete="off" /></div>';
}
buf += '</div>';

// stats
Expand Down Expand Up @@ -2926,6 +2926,19 @@
buf += '</div></div>';
}

for (var i = 0; i <= 3; i++) {
buf += '<div class="formrow"><label class="formlabel" title="Move ' + (i + 1) + ' PP Ups">Move ' + (i + 1) + ' PP Ups:</label><div>';
var defaultPPUps = toID(set.moves[i]) === 'trumpcard' ? 0 : 3;
var movePPUps = defaultPPUps;
if (set.movePPUps && !isNaN(set.movePPUps[i])) movePPUps = set.movePPUps[i];
buf += '<select name="move' + i + 'ppups" class="button">';
for (var j = 0; j <= 3; j++) {
buf += '<option value="' + j + '" ' + (movePPUps === j ? 'selected' : '') + '>' + j + '</option>';
}
buf += '</select>';
buf += '</div></div>';
}

buf += '</form>';
if (species.cosmeticFormes) {
buf += '<button class="altform button">Change sprite</button>';
Expand Down Expand Up @@ -3008,6 +3021,13 @@
delete set.teraType;
}

// PP Ups
for (var i = 0; i <= 3; i++) {
if (!set.movePPUps) set.movePPUps = [];
var PPUps = this.$chart.find('select[name=move' + i + 'ppups]').val();
set.movePPUps[i] = parseInt(PPUps);
}

// update details cell
var buf = '';
var GenderChart = {
Expand Down Expand Up @@ -3354,13 +3374,15 @@
this.unChooseMove(this.curSet.moves[0]);
this.curSet.moves[0] = val;
this.chooseMove(val);
this.setPPUps(val, 0);
if (selectNext) this.$('input[name=move2]').select();
break;
case 'move2':
if (!this.curSet.moves[0]) this.curSet.moves[0] = '';
this.unChooseMove(this.curSet.moves[1]);
this.curSet.moves[1] = val;
this.chooseMove(val);
this.setPPUps(val, 1);
if (selectNext) this.$('input[name=move3]').select();
break;
case 'move3':
Expand All @@ -3369,6 +3391,7 @@
this.unChooseMove(this.curSet.moves[2]);
this.curSet.moves[2] = val;
this.chooseMove(val);
this.setPPUps(val, 2);
if (selectNext) this.$('input[name=move4]').select();
break;
case 'move4':
Expand All @@ -3378,6 +3401,7 @@
this.unChooseMove(this.curSet.moves[3]);
this.curSet.moves[3] = val;
this.chooseMove(val);
this.setPPUps(val, 3);
if (selectNext) {
this.stats();
this.$('button.setstats').focus();
Expand Down Expand Up @@ -3571,6 +3595,15 @@
this.updateSetTop();
if (selectNext) this.$(set.item || !this.$('input[name=item]').length ? (this.$('input[name=ability]').length ? 'input[name=ability]' : 'input[name=move1]') : 'input[name=item]').select();
},
setPPUps: function (move, slot) {
var set = this.curSet;
if (!set.movePPUps) set.movePPUps = [];
if (toID(move) === 'trumpcard') {
set.movePPUps[slot] = 0;
} else {
set.movePPUps[slot] = 3;
}
},

/*********************************************************
* Utility functions
Expand Down
76 changes: 70 additions & 6 deletions play.pokemonshowdown.com/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,20 @@ Storage.packTeam = function (team) {
if (moveid.substr(0, 11) === 'hiddenpower' && moveid.length > 11) hasHP = true;
}

// move PP ups
if (set.movePPUps) {
var PPUps = '';
var showPPUps = false;
for (var j = 0; j < set.movePPUps.length; j++) {
if (j) PPUps += ',';
if (set.movePPUps[j] < 3) {
PPUps += set.movePPUps[j];
showPPUps = true;
}
}
if (showPPUps) buf += ';' + PPUps;
}

// nature
buf += '|' + (set.nature || '');

Expand Down Expand Up @@ -882,7 +896,7 @@ Storage.fastUnpackTeam = function (buf) {
if (!buf) return [];

var team = [];
var i = 0, j = 0;
var i = 0, j = 0, k = 0;

while (true) {
var set = {};
Expand Down Expand Up @@ -912,10 +926,27 @@ Storage.fastUnpackTeam = function (buf) {
i = j + 1;

// moves
j = buf.indexOf('|', i);
j = buf.indexOf(';', i);
k = buf.indexOf('|', i);
if (j < 0 || j > k) j = k;
set.moves = buf.substring(i, j).split(',');
i = j + 1;

// move PP ups
if (buf.charAt(j) === ';') {
j = buf.indexOf('|', i);
set.movePPUps = buf.substring(i, j).split(',');
for (var index = 0; index < set.movePPUps.length; index++) {
set.movePPUps[index] = parseInt(set.movePPUps[index], 10);
if (!set.movePPUps[index]) set.movePPUps[index] = 3;
}
i = j + 1;
} else {
for (var index = 0; index < set.moves.length; index++) {
set.movePPUps[index] = 3;
}
}

// nature
j = buf.indexOf('|', i);
set.nature = buf.substring(i, j);
Expand Down Expand Up @@ -999,7 +1030,7 @@ Storage.unpackTeam = function (buf) {
if (!buf) return [];

var team = [];
var i = 0, j = 0;
var i = 0, j = 0, k = 0;

while (true) {
var set = {};
Expand Down Expand Up @@ -1028,12 +1059,33 @@ Storage.unpackTeam = function (buf) {
i = j + 1;

// moves
j = buf.indexOf('|', i);
j = buf.indexOf(';', i);
k = buf.indexOf('|', i);
if (j < 0 || j > k) {
j = k;
if (j < 0) return null;
}
set.moves = buf.substring(i, j).split(',').map(function (moveid) {
return Dex.moves.get(moveid).name;
});
i = j + 1;

// move PP ups
if (buf.charAt(j) === ';') {
j = buf.indexOf('|', i);
if (j < 0) return null;
set.movePPUps = buf.substring(i, j).split(',');
for (var index = 0; index < set.movePPUps.length; index++) {
set.movePPUps[index] = parseInt(set.movePPUps[index], 10);
if (isNaN(set.movePPUps[index])) set.movePPUps[index] = 3;
}
i = j + 1;
} else {
for (var index = 0; index < set.moves.length; index++) {
set.movePPUps[index] = 3;
}
}

// nature
j = buf.indexOf('|', i);
set.nature = buf.substring(i, j);
Expand Down Expand Up @@ -1343,7 +1395,15 @@ Storage.importTeam = function (buffer, teams) {
if (line === 'Frustration' && curSet.happiness === undefined) {
curSet.happiness = 0;
}
curSet.moves.push(line);
var moveAndPPUps = line.split(' (PP Ups: ', 2);
curSet.moves.push(moveAndPPUps[0]);
if (!curSet.movePPUps) curSet.movePPUps = [];
if (moveAndPPUps[1]) moveAndPPUps[1] = moveAndPPUps[1].charAt(0);
if (isNaN(moveAndPPUps[1])) {
curSet.movePPUps.push(3);
} else {
curSet.movePPUps.push(parseInt(moveAndPPUps[1], 10));
}
}
}
if (teams && teams.length && typeof teams[teams.length - 1].team !== 'string') {
Expand Down Expand Up @@ -1492,7 +1552,11 @@ Storage.exportTeam = function (team, gen, hidestats) {
move = move.substr(0, 13) + '[' + move.substr(13) + ']';
}
if (move) {
text += '- ' + move + " \n";
text += '- ' + move;
if (curSet.movePPUps && !isNaN(curSet.movePPUps[j]) && curSet.movePPUps[j] < 3) {
text += " (PP Ups: " + curSet.movePPUps[j] + ")";
}
text += " \n";
}
}
text += "\n";
Expand Down
2 changes: 2 additions & 0 deletions play.pokemonshowdown.com/src/battle-dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export declare namespace Dex {
/** Defaults to no ability (error in Gen 3+) */
ability?: string;
moves: string[];
/** Defaults to 3 */
movePPUps?: number[];
/** Defaults to no nature (error in Gen 3+) */
nature?: NatureName;
/** Defaults to random legal gender, NOT subject to gender ratios */
Expand Down
36 changes: 29 additions & 7 deletions play.pokemonshowdown.com/src/panel-teamdropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export class PSTeambuilder {
}
}

if (set.movePPUps?.some(n => n < 3)) {
buf += ';' + set.movePPUps.map(
n => n === 3 ? '' : `${n}`
).join(',');
}

// nature
buf += `|${set.nature || ''}`;

Expand Down Expand Up @@ -133,11 +139,19 @@ export class PSTeambuilder {
species.abilities[parts[3] as '0' || '0'] || (parts[3] === '' ? '' : '!!!ERROR!!!') :
Dex.abilities.get(parts[3]).name;

// moves
set.moves = parts[4].split(',').map(moveid =>
// moves and PP ups
const [moves, PPUps] = parts[4].split(';', 2);
set.moves = moves.split(',').map(moveid =>
Dex.moves.get(moveid).name
);

if (PPUps) {
set.movePPUps = PPUps.split(',').map(n => {
if (!n) return 3;
return parseInt(n, 10);
});
}

// nature
set.nature = parts[5] as Dex.NatureName;
if (set.nature as any === 'undefined') set.nature = undefined;
Expand Down Expand Up @@ -217,14 +231,19 @@ export class PSTeambuilder {
text += `Ability: ${set.ability} \n`;
}
if (set.moves) {
for (let move of set.moves) {
for (let i = 0; i < set.moves.length; i++) {
let move = set.moves[i];
let PPUps = ``;
if (move.substr(0, 13) === 'Hidden Power ') {
const hpType = move.slice(13);
move = move.slice(0, 13);
move = `${move}[${hpType}]`;
}
if (set.movePPUps && !isNaN(set.movePPUps[i]) && set.movePPUps[i] < 3) {
PPUps = ` (PP Ups: ${set.movePPUps[i]})`;
}
if (move) {
text += `- ${move} \n`;
text += `- ${move}${PPUps} \n`;
}
}
}
Expand Down Expand Up @@ -388,9 +407,10 @@ export class PSTeambuilder {
if (line !== 'undefined') set.nature = line as Dex.NatureName;
} else if (line.startsWith('-') || line.startsWith('~')) {
line = line.slice(line.charAt(1) === ' ' ? 2 : 1);
if (line.startsWith('Hidden Power [')) {
const hpType = line.slice(14, -1) as Dex.TypeName;
line = 'Hidden Power ' + hpType;
let [move, PPUps] = line.split(' (PP Ups: ');
if (move.startsWith('Hidden Power [')) {
const hpType = move.slice(14, -1) as Dex.TypeName;
move = 'Hidden Power ' + hpType;
if (!set.ivs && Dex.types.isName(hpType)) {
set.ivs = { hp: 31, atk: 31, def: 31, spa: 31, spd: 31, spe: 31 };
const hpIVs = Dex.types.get(hpType).HPivs || {};
Expand All @@ -399,6 +419,8 @@ export class PSTeambuilder {
}
}
}
if (!set.movePPUps) set.movePPUps = [];
set.movePPUps.push(parseInt(PPUps?.charAt(0), 10) || 3);
if (line === 'Frustration' && set.happiness === undefined) {
set.happiness = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions play.pokemonshowdown.com/style/client.css
Original file line number Diff line number Diff line change
Expand Up @@ -2859,12 +2859,12 @@ a.ilink.yours {
}

.detailsform .formrow {
padding-left: 100px;
padding-left: 150px;
}
.detailsform .formrow .formlabel {
float: left;
margin-left: -100px;
width: 110px;
margin-left: -150px;
width: 165px;
text-align: right;
}
.changeform i {
Expand Down