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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions play.pokemonshowdown.com/js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,10 +1375,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
45 changes: 41 additions & 4 deletions play.pokemonshowdown.com/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,11 @@ Storage.packTeam = function (team) {
if (moveid.substr(0, 11) === 'hiddenpower' && moveid.length > 11) hasHP = true;
}

// move PP ups
if (set.movePPUps) {
buf += ';' + set.movePPUps.join(',');
}

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

Expand Down Expand Up @@ -913,10 +918,18 @@ Storage.fastUnpackTeam = function (buf) {
i = j + 1;

// moves
j = buf.indexOf('|', i);
j = buf.indexOf(';', i);
if (j < 0) j = buf.indexOf('|', i);
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(',').map(number => parseInt(number));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set.movePPUps = buf.substring(i, j).split(',').map(number => parseInt(number));
for (var q = 0; q < buf.substring(i, j).split(',').length; q++) {
var ppUpsUsed = parseInt(buf.substring(i, j).split(',')[q]);
set.movePPUps[q] = ppUpsUsed;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to pull buf.substring(i,j).split(,) into a variable outside the for loop. Also set.movePPUps needs to be initialized w/ an array before writing to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing the array with the values as strings and converting them to numbers works without crashing or upsetting Linter, so I've done that.

i = j + 1;
}

// nature
j = buf.indexOf('|', i);
set.nature = buf.substring(i, j);
Expand Down Expand Up @@ -1029,12 +1042,24 @@ Storage.unpackTeam = function (buf) {
i = j + 1;

// moves
j = buf.indexOf('|', i);
j = buf.indexOf(';', i);
if (j < 0) {
j = buf.indexOf('|', i);
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(',').map(number => parseInt(number));
i = j + 1;
}

// nature
j = buf.indexOf('|', i);
set.nature = buf.substring(i, j);
Expand Down Expand Up @@ -1344,7 +1369,15 @@ Storage.importTeam = function (buffer, teams) {
if (line === 'Frustration' && curSet.happiness === undefined) {
curSet.happiness = 0;
}
curSet.moves.push(line);
var [move, movePPUps] = line.split(' (PP Ups: ', 2);
curSet.moves.push(move);
if (!curSet.movePPUps) curSet.movePPUps = [];
if (movePPUps && movePPUps.length > 1) movePPUps = movePPUps.charAt(0);
if (isNaN(movePPUps)) {
curSet.movePPUps.push(3);
} else {
curSet.movePPUps.push(parseInt(movePPUps));
}
}
}
if (teams && teams.length && typeof teams[teams.length - 1].team !== 'string') {
Expand Down Expand Up @@ -1493,7 +1526,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 && curSet.movePPUps[j] && curSet.movePPUps[j] < 3) {
text += " (PP Ups: " + curSet.movePPUps[j] + ")";
}
text += " \n";
}
}
text += "\n";
Expand Down
Loading