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
31 changes: 27 additions & 4 deletions play.pokemonshowdown.com/js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'change select[name=ivspread]': 'ivSpreadChange',
'change .evslider': 'statSlided',
'input .evslider': 'statSlide',
'change .movepp': 'movePPChange',

// teambuilder events
'click .utilichart a': 'chartClick',
Expand Down Expand Up @@ -1339,12 +1340,20 @@
buf += '</div></div>';

// moves
console.log(set);
dot-Comfey marked this conversation as resolved.
Show resolved Hide resolved
if (!set.moves) set.moves = [];
if (!set.movePPUps) set.movePPUps = [3, 3, 3, 3];
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" />';
buf += '<select name="move' + (i + 1) + 'pp" class="textbox movepp">'
for (var j = 0; j <= 3; j++) {
var movePPUps = isNaN(set.movePPUps[i]) ? 3 : set.movePPUps[i];
buf += '<option value="' + j + '" ' + (movePPUps === j ? 'selected' : '') + '>' + j + '</option>'
}
buf += '</select></div>'
}
buf += '</div>';

// stats
Expand Down Expand Up @@ -2681,6 +2690,20 @@
this.save();
this.updateStatGraph();
},
movePPChange: function (e) {
var set = this.curSet;
if (!set) set = this.curSetList[e.currentTarget.offsetParent.value];

var movePPUps = parseInt(e.currentTarget.value);
console.log(movePPUps);
if (!set.movePPUps) set.movePPUps = [3, 3, 3, 3];
var boxName = e.currentTarget.name;
set.movePPUps[parseInt(boxName.charAt(4)) - 1] = movePPUps;
console.log(set.movePPUps);

this.save();
this.updateStatGraph();
},

/*********************************************************
* Set details form
Expand Down
42 changes: 38 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,14 @@ Storage.importTeam = function (buffer, teams) {
if (line === 'Frustration' && curSet.happiness === undefined) {
curSet.happiness = 0;
}
curSet.moves.push(line);
var [move, movePPUps] = line.split(';', 2);
curSet.moves.push(move);
if (!curSet.movePPUps) curSet.movePPUps = [];
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 +1525,9 @@ 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] < 3) text += ";" + curSet.movePPUps[j];
text += " \n";
}
}
text += "\n";
Expand Down
23 changes: 15 additions & 8 deletions play.pokemonshowdown.com/style/client.css
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ a.ilink.yours {
background: #CBD6E1;
border-radius: 5px;
padding: 1px 0 0 0;
width: 110px;
width: 100px;

box-shadow: inset 1px 1px 0 rgba(255,255,255,.6);
}
Expand All @@ -2360,14 +2360,14 @@ a.ilink.yours {
}
.setcol {
height: 127px;
width: 112px;
width: 102px;
float: left;
}
.setcol-icon {
background: transparent none no-repeat scroll center top;
}
.setcol-details {
width: 234px;
width: 209px;
}
.setcell {
float: left;
Expand Down Expand Up @@ -2425,7 +2425,7 @@ a.ilink.yours {
margin-bottom: -1px;
}
.setcol-moves {
width: 137px;
width: 172px;
}
.setcol-stats {
width: 142px;
Expand Down Expand Up @@ -2466,7 +2466,7 @@ a.ilink.yours {
outline: 0 none;
}
.setdetails {
width: 230px;
width: 205px;
height: 34px;
}
.setdetails:focus,.setdetails:active {
Expand Down Expand Up @@ -2556,12 +2556,13 @@ a.ilink.yours {
display: block;
}
.setchart input,
.setchart select,
.setchart-nickname input,
.statform input.inputform {
display: block;
padding: 1px;
margin: 2px 3px 1px 1px;
width: 104px;
width: 94px;
height: 20px;
}
.setchart input.incomplete {
Expand All @@ -2572,14 +2573,20 @@ a.ilink.yours {
width: 216px;
}
.setchart .setcell-item input {
width: 114px;
width: 99px;
margin-right: 0px;
}
.setchart .setcell-ability input {
margin-left: 0px;
}
.setchart .setcol-moves input {
width: 129px;
width: 109px;
display: inline-block;
}
.setchart .setcol-moves select {
width: 50px;
height: 23.6px;
display: inline-block;
}

.teambuilder-clipboard-container {
Expand Down