From d7d2acb7d560da7f6a4c26dc1e1984c1020f6c2b Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sat, 10 Feb 2024 17:11:26 -0800 Subject: [PATCH 01/15] Allow PP Ups to be edited Client-side change. I'm not a web developer so a lot of the HTML/CSS may be messy. However, it seems like the general interface works; PP ups can be edited, and they are able to properly import/export as well as pack/unpack. --- .../js/client-teambuilder.js | 37 ++++++++++++++-- play.pokemonshowdown.com/js/storage.js | 42 +++++++++++++++++-- play.pokemonshowdown.com/style/client.css | 11 ++++- 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js index d0766df685..9cc4eea233 100644 --- a/play.pokemonshowdown.com/js/client-teambuilder.js +++ b/play.pokemonshowdown.com/js/client-teambuilder.js @@ -62,6 +62,7 @@ 'change select[name=ivspread]': 'ivSpreadChange', 'change .evslider': 'statSlided', 'input .evslider': 'statSlide', + 'change .movepp': 'movePPChange', // teambuilder events 'click .utilichart a': 'chartClick', @@ -1339,12 +1340,26 @@ buf += ''; // moves + console.log(set); if (!set.moves) set.moves = []; + if (!set.movePPUps) set.movePPUps = [3, 3, 3, 3]; buf += '
'; - buf += '
'; - buf += '
'; - buf += '
'; - buf += '
'; + for (var i = 0; i <= 3; i++) { + if (i > 0) buf += '
'; + buf += '
'; + } + buf += '
'; + + buf += '
'; + for (var i = 0; i <= 3; i++) { + if (i > 0) buf += '
'; + buf += '
' + } buf += '
'; // stats @@ -2681,6 +2696,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 diff --git a/play.pokemonshowdown.com/js/storage.js b/play.pokemonshowdown.com/js/storage.js index 3eeaa4e332..81ea8e5111 100644 --- a/play.pokemonshowdown.com/js/storage.js +++ b/play.pokemonshowdown.com/js/storage.js @@ -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 || ''); @@ -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)); + i = j + 1; + } + // nature j = buf.indexOf('|', i); set.nature = buf.substring(i, j); @@ -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); @@ -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') { @@ -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"; diff --git a/play.pokemonshowdown.com/style/client.css b/play.pokemonshowdown.com/style/client.css index 80ed47b035..9460551202 100644 --- a/play.pokemonshowdown.com/style/client.css +++ b/play.pokemonshowdown.com/style/client.css @@ -2378,6 +2378,9 @@ a.ilink.yours { .setcell-ability { float: right; } +.setcell-movepp { + display: block; +} .setcol-details .itemicon { display: block; width: 24px; @@ -2409,6 +2412,9 @@ a.ilink.yours { .setcol-moves .setcell { padding-bottom: 1px; } +.setcol-movepp .setcell { + padding-bottom: 1px; +} .setchart label, .setchart-nickname label { display: block; @@ -2425,7 +2431,10 @@ a.ilink.yours { margin-bottom: -1px; } .setcol-moves { - width: 137px; + width: 107px; +} +.setcol-movepp { + width: 30px; } .setcol-stats { width: 142px; From 1c898cd22294a520a670e122eee8fe8e912435ad Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sat, 10 Feb 2024 23:00:38 -0800 Subject: [PATCH 02/15] Less ugly CSS --- .../js/client-teambuilder.js | 2 +- play.pokemonshowdown.com/style/client.css | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js index 9cc4eea233..1f972f5afb 100644 --- a/play.pokemonshowdown.com/js/client-teambuilder.js +++ b/play.pokemonshowdown.com/js/client-teambuilder.js @@ -1353,7 +1353,7 @@ buf += '
'; for (var i = 0; i <= 3; i++) { if (i > 0) buf += '
'; - buf += '' for (var j = 0; j <= 3; j++) { var movePPUps = isNaN(set.movePPUps[i]) ? 3 : set.movePPUps[i]; buf += '' diff --git a/play.pokemonshowdown.com/style/client.css b/play.pokemonshowdown.com/style/client.css index 9460551202..382e8a1fc3 100644 --- a/play.pokemonshowdown.com/style/client.css +++ b/play.pokemonshowdown.com/style/client.css @@ -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); } @@ -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; @@ -2378,9 +2378,6 @@ a.ilink.yours { .setcell-ability { float: right; } -.setcell-movepp { - display: block; -} .setcol-details .itemicon { display: block; width: 24px; @@ -2431,10 +2428,10 @@ a.ilink.yours { margin-bottom: -1px; } .setcol-moves { - width: 107px; + width: 117px; } .setcol-movepp { - width: 30px; + width: 55px; } .setcol-stats { width: 142px; @@ -2475,7 +2472,7 @@ a.ilink.yours { outline: 0 none; } .setdetails { - width: 230px; + width: 205px; height: 34px; } .setdetails:focus,.setdetails:active { @@ -2565,12 +2562,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 { @@ -2581,14 +2579,18 @@ 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; +} +.setchart .setcol-movepp select { + width: 50px; + height: 23.6px; } .teambuilder-clipboard-container { From d05cf8c7161142bf0700dd82b762c64713bd910c Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sun, 11 Feb 2024 17:14:51 -0800 Subject: [PATCH 03/15] Moves and PP Ups on the same line --- play.pokemonshowdown.com/js/client-teambuilder.js | 8 +------- play.pokemonshowdown.com/style/client.css | 12 ++++-------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js index 1f972f5afb..85f5eff66d 100644 --- a/play.pokemonshowdown.com/js/client-teambuilder.js +++ b/play.pokemonshowdown.com/js/client-teambuilder.js @@ -1346,13 +1346,7 @@ buf += '
'; for (var i = 0; i <= 3; i++) { if (i > 0) buf += '
'; - buf += '
'; - } - buf += '
'; - - buf += '
'; - for (var i = 0; i <= 3; i++) { - if (i > 0) buf += '
'; + buf += ''; buf += ''; buf += '
' } @@ -2974,6 +2982,7 @@ this.$('input[name=move' + Math.min(moves.length + 1, 4) + ']').focus(); this.curSet.moves = moves; this.search.find(''); + this.updateMovePP(); return; } } @@ -3216,6 +3225,7 @@ this.unChooseMove(this.curSet.moves[0]); this.curSet.moves[0] = val; this.chooseMove(val); + this.updateMovePP(); if (selectNext) this.$('input[name=move2]').select(); break; case 'move2': @@ -3223,6 +3233,7 @@ this.unChooseMove(this.curSet.moves[1]); this.curSet.moves[1] = val; this.chooseMove(val); + this.updateMovePP(); if (selectNext) this.$('input[name=move3]').select(); break; case 'move3': @@ -3231,6 +3242,7 @@ this.unChooseMove(this.curSet.moves[2]); this.curSet.moves[2] = val; this.chooseMove(val); + this.updateMovePP(); if (selectNext) this.$('input[name=move4]').select(); break; case 'move4': @@ -3240,6 +3252,7 @@ this.unChooseMove(this.curSet.moves[3]); this.curSet.moves[3] = val; this.chooseMove(val); + this.updateMovePP(); if (selectNext) { this.stats(); this.$('button.setstats').focus(); @@ -3248,6 +3261,24 @@ } this.save(); }, + updateMovePP: function () { + if (!this.curSet) return; + for (var i = 0; i <= 3; i++) { + var buf = ''; + var move = Dex.moves.get(this.curSet.moves[i]); + if (!move.exists) { + buf += ''; + } else if (!move.isZ && !move.noPPBoosts) { + for (var j = 0; j <= 3; j++) { + var movePP = (move.pp / 5) * (5 + j); + buf += ''; + } + } else { + buf += ''; + } + this.$('select[name=move' + (i + 1) + 'pp]').html(buf); + } + }, unChooseMove: function (moveName) { var set = this.curSet; if (!moveName || !set || this.curTeam.format === 'gen7hiddentype') return; From ab6c6dee4022a4d8f7e93a7233a7b8a265b12897 Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Fri, 16 Feb 2024 00:01:11 -0800 Subject: [PATCH 06/15] Update client-teambuilder.js --- play.pokemonshowdown.com/js/client-teambuilder.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js index 33cfc21306..5387e424bc 100644 --- a/play.pokemonshowdown.com/js/client-teambuilder.js +++ b/play.pokemonshowdown.com/js/client-teambuilder.js @@ -2965,6 +2965,7 @@ if (this.curChartType === 'move' && e.currentTarget.className === 'cur') { // clicked a move, remove it if we already have it var moves = []; + var movePPUps = []; for (var i = 0; i < this.curSet.moves.length; i++) { var curVal = this.curSet.moves[i]; if (curVal === val) { @@ -2972,6 +2973,7 @@ delete this.search.cur[toID(val)]; } else if (curVal) { moves.push(curVal); + movePPUps.push(this.curSet.movePPUps[i]); } } if (moves.length < this.curSet.moves.length) { @@ -2981,6 +2983,7 @@ this.$('input[name=move4]').val(moves[3] || ''); this.$('input[name=move' + Math.min(moves.length + 1, 4) + ']').focus(); this.curSet.moves = moves; + this.curSet.movePPUps = movePPUps; this.search.find(''); this.updateMovePP(); return; @@ -3270,8 +3273,9 @@ buf += ''; } else if (!move.isZ && !move.noPPBoosts) { for (var j = 0; j <= 3; j++) { + var movePPUps = isNaN(this.curSet.movePPUps[i]) ? 3 : this.curSet.movePPUps[i]; var movePP = (move.pp / 5) * (5 + j); - buf += ''; + buf += ''; } } else { buf += ''; From 65137bf679f24983a7322b67fbd9528ded5d7eb6 Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Fri, 16 Feb 2024 08:41:53 -0800 Subject: [PATCH 07/15] Remove UI Only editable in the import/export interface now, which can be done by adding ';2', ';1', or ';0' after a move. --- .../js/client-teambuilder.js | 57 +------------------ play.pokemonshowdown.com/style/client.css | 23 +++----- 2 files changed, 9 insertions(+), 71 deletions(-) diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js index 5387e424bc..4a6d733fc8 100644 --- a/play.pokemonshowdown.com/js/client-teambuilder.js +++ b/play.pokemonshowdown.com/js/client-teambuilder.js @@ -62,7 +62,6 @@ 'change select[name=ivspread]': 'ivSpreadChange', 'change .evslider': 'statSlided', 'input .evslider': 'statSlide', - 'change .movepp': 'movePPChange', // teambuilder events 'click .utilichart a': 'chartClick', @@ -1341,25 +1340,10 @@ // moves if (!set.moves) set.moves = []; - if (!set.movePPUps) set.movePPUps = [3, 3, 3, 3]; buf += '
'; for (var i = 0; i <= 3; i++) { - var move = Dex.moves.get(set.moves[i]); if (i > 0) buf += '
'; - buf += ''; - buf += '
' + buf += '
'; } buf += '
'; @@ -2697,18 +2681,6 @@ 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); - if (!set.movePPUps) set.movePPUps = [3, 3, 3, 3]; - var boxName = e.currentTarget.name; - set.movePPUps[parseInt(boxName.charAt(4)) - 1] = movePPUps; - - this.save(); - this.updateStatGraph(); - }, /********************************************************* * Set details form @@ -2965,7 +2937,6 @@ if (this.curChartType === 'move' && e.currentTarget.className === 'cur') { // clicked a move, remove it if we already have it var moves = []; - var movePPUps = []; for (var i = 0; i < this.curSet.moves.length; i++) { var curVal = this.curSet.moves[i]; if (curVal === val) { @@ -2973,7 +2944,6 @@ delete this.search.cur[toID(val)]; } else if (curVal) { moves.push(curVal); - movePPUps.push(this.curSet.movePPUps[i]); } } if (moves.length < this.curSet.moves.length) { @@ -2983,9 +2953,7 @@ this.$('input[name=move4]').val(moves[3] || ''); this.$('input[name=move' + Math.min(moves.length + 1, 4) + ']').focus(); this.curSet.moves = moves; - this.curSet.movePPUps = movePPUps; this.search.find(''); - this.updateMovePP(); return; } } @@ -3228,7 +3196,6 @@ this.unChooseMove(this.curSet.moves[0]); this.curSet.moves[0] = val; this.chooseMove(val); - this.updateMovePP(); if (selectNext) this.$('input[name=move2]').select(); break; case 'move2': @@ -3236,7 +3203,6 @@ this.unChooseMove(this.curSet.moves[1]); this.curSet.moves[1] = val; this.chooseMove(val); - this.updateMovePP(); if (selectNext) this.$('input[name=move3]').select(); break; case 'move3': @@ -3245,7 +3211,6 @@ this.unChooseMove(this.curSet.moves[2]); this.curSet.moves[2] = val; this.chooseMove(val); - this.updateMovePP(); if (selectNext) this.$('input[name=move4]').select(); break; case 'move4': @@ -3255,7 +3220,6 @@ this.unChooseMove(this.curSet.moves[3]); this.curSet.moves[3] = val; this.chooseMove(val); - this.updateMovePP(); if (selectNext) { this.stats(); this.$('button.setstats').focus(); @@ -3264,25 +3228,6 @@ } this.save(); }, - updateMovePP: function () { - if (!this.curSet) return; - for (var i = 0; i <= 3; i++) { - var buf = ''; - var move = Dex.moves.get(this.curSet.moves[i]); - if (!move.exists) { - buf += ''; - } else if (!move.isZ && !move.noPPBoosts) { - for (var j = 0; j <= 3; j++) { - var movePPUps = isNaN(this.curSet.movePPUps[i]) ? 3 : this.curSet.movePPUps[i]; - var movePP = (move.pp / 5) * (5 + j); - buf += ''; - } - } else { - buf += ''; - } - this.$('select[name=move' + (i + 1) + 'pp]').html(buf); - } - }, unChooseMove: function (moveName) { var set = this.curSet; if (!moveName || !set || this.curTeam.format === 'gen7hiddentype') return; diff --git a/play.pokemonshowdown.com/style/client.css b/play.pokemonshowdown.com/style/client.css index d5df284994..80ed47b035 100644 --- a/play.pokemonshowdown.com/style/client.css +++ b/play.pokemonshowdown.com/style/client.css @@ -2343,7 +2343,7 @@ a.ilink.yours { background: #CBD6E1; border-radius: 5px; padding: 1px 0 0 0; - width: 100px; + width: 110px; box-shadow: inset 1px 1px 0 rgba(255,255,255,.6); } @@ -2360,14 +2360,14 @@ a.ilink.yours { } .setcol { height: 127px; - width: 102px; + width: 112px; float: left; } .setcol-icon { background: transparent none no-repeat scroll center top; } .setcol-details { - width: 209px; + width: 234px; } .setcell { float: left; @@ -2425,7 +2425,7 @@ a.ilink.yours { margin-bottom: -1px; } .setcol-moves { - width: 172px; + width: 137px; } .setcol-stats { width: 142px; @@ -2466,7 +2466,7 @@ a.ilink.yours { outline: 0 none; } .setdetails { - width: 205px; + width: 230px; height: 34px; } .setdetails:focus,.setdetails:active { @@ -2556,13 +2556,12 @@ 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: 94px; + width: 104px; height: 20px; } .setchart input.incomplete { @@ -2573,20 +2572,14 @@ a.ilink.yours { width: 216px; } .setchart .setcell-item input { - width: 99px; + width: 114px; margin-right: 0px; } .setchart .setcell-ability input { margin-left: 0px; } .setchart .setcol-moves input { - width: 109px; - display: inline-block; -} -.setchart .setcol-moves select { - width: 50px; - height: 23.6px; - display: inline-block; + width: 129px; } .teambuilder-clipboard-container { From c815bbc655c32a0aa353cf271758244dc7811788 Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sat, 12 Oct 2024 00:11:00 -0700 Subject: [PATCH 08/15] A little less ugly export formatting Given that the original thread that suggested PP Up editing is still getting likes to this day, it's still a relevant suggestion and I wanted to revive this PR by making the export look less ugly. Not sure if we still want to have a UI in the teambuilder, as the PR thread suggests starting with changing the export format: https://www.smogon.com/forums/threads/editing-pp-on-showdown.3735890/ I'd also like to see if this works for server-side team storage, but I haven't figured out a way to test that. --- play.pokemonshowdown.com/js/storage.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/play.pokemonshowdown.com/js/storage.js b/play.pokemonshowdown.com/js/storage.js index fecea8eb26..b70098d46d 100644 --- a/play.pokemonshowdown.com/js/storage.js +++ b/play.pokemonshowdown.com/js/storage.js @@ -1369,9 +1369,10 @@ Storage.importTeam = function (buffer, teams) { if (line === 'Frustration' && curSet.happiness === undefined) { curSet.happiness = 0; } - var [move, movePPUps] = line.split(';', 2); + 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 { @@ -1526,7 +1527,7 @@ Storage.exportTeam = function (team, gen, hidestats) { } if (move) { text += '- ' + move; - if (curSet.movePPUps && curSet.movePPUps[j] < 3) text += ";" + curSet.movePPUps[j]; + if (curSet.movePPUps && curSet.movePPUps[j] < 3) text += " (PP Ups: " + curSet.movePPUps[j] + ")"; text += " \n"; } } From b696d2d9b8da1f181799a928d53acda7936e2dad Mon Sep 17 00:00:00 2001 From: Kris Johnson <11083252+KrisXV@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:41:47 -0600 Subject: [PATCH 09/15] Update play.pokemonshowdown.com/js/storage.js --- play.pokemonshowdown.com/js/storage.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/play.pokemonshowdown.com/js/storage.js b/play.pokemonshowdown.com/js/storage.js index b70098d46d..14de6b1858 100644 --- a/play.pokemonshowdown.com/js/storage.js +++ b/play.pokemonshowdown.com/js/storage.js @@ -1527,7 +1527,9 @@ Storage.exportTeam = function (team, gen, hidestats) { } if (move) { text += '- ' + move; - if (curSet.movePPUps && curSet.movePPUps[j] < 3) text += " (PP Ups: " + curSet.movePPUps[j] + ")"; + if (curSet.movePPUps && curSet.movePPUps[j] && curSet.movePPUps[j] < 3) { + text += " (PP Ups: " + curSet.movePPUps[j] + ")"; + } text += " \n"; } } From 06dcea9dbe614839a88c3dd0f8a4b4c432e098fe Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:33:16 -0700 Subject: [PATCH 10/15] Update storage.js --- play.pokemonshowdown.com/js/storage.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/play.pokemonshowdown.com/js/storage.js b/play.pokemonshowdown.com/js/storage.js index 14de6b1858..b29b5a7134 100644 --- a/play.pokemonshowdown.com/js/storage.js +++ b/play.pokemonshowdown.com/js/storage.js @@ -926,7 +926,10 @@ Storage.fastUnpackTeam = function (buf) { // move PP ups if (buf.charAt(j) === ';') { j = buf.indexOf('|', i); - set.movePPUps = buf.substring(i, j).split(',').map(number => parseInt(number)); + set.movePPUps = buf.substring(i, j).split(','); + for (var index = 0; index < set.movePPUps.length; index++) { + set.movePPUps[index] = parseInt(set.movePPUps[index], 10); + } i = j + 1; } @@ -1056,7 +1059,10 @@ Storage.unpackTeam = function (buf) { if (buf.charAt(j) === ';') { j = buf.indexOf('|', i); if (j < 0) return null; - set.movePPUps = buf.substring(i, j).split(',').map(number => parseInt(number)); + set.movePPUps = buf.substring(i, j).split(','); + for (var index = 0; index < set.movePPUps.length; index++) { + set.movePPUps[index] = parseInt(set.movePPUps[index], 10); + } i = j + 1; } @@ -1369,14 +1375,14 @@ Storage.importTeam = function (buffer, teams) { if (line === 'Frustration' && curSet.happiness === undefined) { curSet.happiness = 0; } - var [move, movePPUps] = line.split(' (PP Ups: ', 2); - curSet.moves.push(move); + var moveAndPPUps = line.split(' (PP Ups: ', 2); + curSet.moves.push(moveAndPPUps[0]); if (!curSet.movePPUps) curSet.movePPUps = []; - if (movePPUps && movePPUps.length > 1) movePPUps = movePPUps.charAt(0); - if (isNaN(movePPUps)) { + if (moveAndPPUps[1] && moveAndPPUps[1].length > 1) moveAndPPUps[1] = moveAndPPUps[1].charAt(0); + if (isNaN(moveAndPPUps[1])) { curSet.movePPUps.push(3); } else { - curSet.movePPUps.push(parseInt(movePPUps)); + curSet.movePPUps.push(parseInt(moveAndPPUps[1], 10)); } } } From b3615d7b2c5a2ecb8716c7b179e1fef90a9de218 Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:12:02 -0700 Subject: [PATCH 11/15] Fix unpacking This should hopefully cover everything needed to implement PP Ups. --- play.pokemonshowdown.com/js/storage.js | 12 ++++--- .../src/battle-tooltips.ts | 2 ++ .../src/panel-teamdropdown.tsx | 31 ++++++++++++++----- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/play.pokemonshowdown.com/js/storage.js b/play.pokemonshowdown.com/js/storage.js index b29b5a7134..e3ea5e8f9c 100644 --- a/play.pokemonshowdown.com/js/storage.js +++ b/play.pokemonshowdown.com/js/storage.js @@ -888,7 +888,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 = {}; @@ -919,7 +919,8 @@ Storage.fastUnpackTeam = function (buf) { // moves j = buf.indexOf(';', i); - if (j < 0) 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; @@ -1016,7 +1017,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 = {}; @@ -1046,8 +1047,9 @@ Storage.unpackTeam = function (buf) { // moves j = buf.indexOf(';', i); - if (j < 0) { - 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) { diff --git a/play.pokemonshowdown.com/src/battle-tooltips.ts b/play.pokemonshowdown.com/src/battle-tooltips.ts index ebeb171361..4e8a748dc7 100644 --- a/play.pokemonshowdown.com/src/battle-tooltips.ts +++ b/play.pokemonshowdown.com/src/battle-tooltips.ts @@ -2517,6 +2517,8 @@ interface PokemonSet { /** 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 */ diff --git a/play.pokemonshowdown.com/src/panel-teamdropdown.tsx b/play.pokemonshowdown.com/src/panel-teamdropdown.tsx index 0794f16cab..0885a7f807 100644 --- a/play.pokemonshowdown.com/src/panel-teamdropdown.tsx +++ b/play.pokemonshowdown.com/src/panel-teamdropdown.tsx @@ -41,6 +41,10 @@ class PSTeambuilder { } } + if (set.movePPUps) { + buf += ';' + set.movePPUps.join(','); + } + // nature buf += '|' + (set.nature || ''); @@ -140,11 +144,16 @@ 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(number => parseInt(number)); + } + // nature set.nature = parts[5] as NatureName; if (set.nature as any === 'undefined') set.nature = undefined; @@ -224,14 +233,19 @@ 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`; } } } @@ -395,9 +409,10 @@ class PSTeambuilder { if (line !== 'undefined') set.nature = line as NatureName; } else if (line.charAt(0) === '-' || line.charAt(0) === '~') { line = line.slice(line.charAt(1) === ' ' ? 2 : 1); - if (line.startsWith('Hidden Power [')) { - const hpType = line.slice(14, -1) as TypeName; - line = 'Hidden Power ' + hpType; + let [move, PPUps] = line.split(' (PP Ups: '); + if (move.startsWith('Hidden Power [')) { + const hpType = move.slice(14, -1) as 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 || {}; @@ -406,6 +421,8 @@ class PSTeambuilder { } } } + if (!set.movePPUps) set.movePPUps = []; + set.movePPUps.push(parseInt(PPUps?.charAt(0)) || 3); if (line === 'Frustration' && set.happiness === undefined) { set.happiness = 0; } From 8feea82dd91562c49b0321e483a966961f7286c0 Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:15:19 -0700 Subject: [PATCH 12/15] Update panel-teamdropdown.tsx --- play.pokemonshowdown.com/src/panel-teamdropdown.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/play.pokemonshowdown.com/src/panel-teamdropdown.tsx b/play.pokemonshowdown.com/src/panel-teamdropdown.tsx index 0885a7f807..4235c864b3 100644 --- a/play.pokemonshowdown.com/src/panel-teamdropdown.tsx +++ b/play.pokemonshowdown.com/src/panel-teamdropdown.tsx @@ -151,7 +151,7 @@ class PSTeambuilder { ); if (PPUps) { - set.movePPUps = PPUps.split(',').map(number => parseInt(number)); + set.movePPUps = PPUps.split(',').map(n => parseInt(n, 10)); } // nature @@ -422,7 +422,7 @@ class PSTeambuilder { } } if (!set.movePPUps) set.movePPUps = []; - set.movePPUps.push(parseInt(PPUps?.charAt(0)) || 3); + set.movePPUps.push(parseInt(PPUps?.charAt(0), 10) || 3); if (line === 'Frustration' && set.happiness === undefined) { set.happiness = 0; } From 2aa94bbec83c87962ad5de85b410845f2a00929b Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:40:27 -0700 Subject: [PATCH 13/15] Change PP Ups display in packed format PP Ups values that are 3 will now be shown as empty in the packed format, and if every value would be empty, PP Ups do not get displayed. I made this change to be consistent with how EVs and IVs are handled. --- play.pokemonshowdown.com/js/storage.js | 17 ++++++++++++++--- .../src/panel-teamdropdown.tsx | 13 ++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/play.pokemonshowdown.com/js/storage.js b/play.pokemonshowdown.com/js/storage.js index e3ea5e8f9c..be5d7adb0b 100644 --- a/play.pokemonshowdown.com/js/storage.js +++ b/play.pokemonshowdown.com/js/storage.js @@ -814,7 +814,16 @@ Storage.packTeam = function (team) { // move PP ups if (set.movePPUps) { - buf += ';' + set.movePPUps.join(','); + 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 @@ -930,6 +939,7 @@ Storage.fastUnpackTeam = function (buf) { 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; } @@ -1064,6 +1074,7 @@ Storage.unpackTeam = function (buf) { 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; } @@ -1380,7 +1391,7 @@ Storage.importTeam = function (buffer, teams) { var moveAndPPUps = line.split(' (PP Ups: ', 2); curSet.moves.push(moveAndPPUps[0]); if (!curSet.movePPUps) curSet.movePPUps = []; - if (moveAndPPUps[1] && moveAndPPUps[1].length > 1) moveAndPPUps[1] = moveAndPPUps[1].charAt(0); + if (moveAndPPUps[1]) moveAndPPUps[1] = moveAndPPUps[1].charAt(0); if (isNaN(moveAndPPUps[1])) { curSet.movePPUps.push(3); } else { @@ -1535,7 +1546,7 @@ Storage.exportTeam = function (team, gen, hidestats) { } if (move) { text += '- ' + move; - if (curSet.movePPUps && curSet.movePPUps[j] && curSet.movePPUps[j] < 3) { + if (curSet.movePPUps && !isNaN(curSet.movePPUps[j]) && curSet.movePPUps[j] < 3) { text += " (PP Ups: " + curSet.movePPUps[j] + ")"; } text += " \n"; diff --git a/play.pokemonshowdown.com/src/panel-teamdropdown.tsx b/play.pokemonshowdown.com/src/panel-teamdropdown.tsx index 4235c864b3..df48b9335e 100644 --- a/play.pokemonshowdown.com/src/panel-teamdropdown.tsx +++ b/play.pokemonshowdown.com/src/panel-teamdropdown.tsx @@ -41,8 +41,12 @@ class PSTeambuilder { } } - if (set.movePPUps) { - buf += ';' + set.movePPUps.join(','); + if (set.movePPUps && set.movePPUps.some(n => n < 3)) { + const PPUps = set.movePPUps.map(n => { + if (n === 3) return ''; + return n.toString(); + }) + buf += ';' + PPUps.join(','); } // nature @@ -151,7 +155,10 @@ class PSTeambuilder { ); if (PPUps) { - set.movePPUps = PPUps.split(',').map(n => parseInt(n, 10)); + set.movePPUps = PPUps.split(',').map(n => { + if (!n) return 3; + return parseInt(n, 10); + }); } // nature From bf8f4e4f38cd569794cf15e44d9688f921064949 Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:47:34 -0700 Subject: [PATCH 14/15] Format errors --- play.pokemonshowdown.com/js/storage.js | 6 +++--- play.pokemonshowdown.com/src/panel-teamdropdown.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/play.pokemonshowdown.com/js/storage.js b/play.pokemonshowdown.com/js/storage.js index be5d7adb0b..a4a35c1391 100644 --- a/play.pokemonshowdown.com/js/storage.js +++ b/play.pokemonshowdown.com/js/storage.js @@ -817,7 +817,7 @@ Storage.packTeam = function (team) { var PPUps = ''; var showPPUps = false; for (var j = 0; j < set.movePPUps.length; j++) { - if (j) PPUps += ',' + if (j) PPUps += ','; if (set.movePPUps[j] < 3) { PPUps += set.movePPUps[j]; showPPUps = true; @@ -939,7 +939,7 @@ Storage.fastUnpackTeam = function (buf) { 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; + if (!set.movePPUps[index]) set.movePPUps[index] = 3; } i = j + 1; } @@ -1074,7 +1074,7 @@ Storage.unpackTeam = function (buf) { 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; + if (!set.movePPUps[index]) set.movePPUps[index] = 3; } i = j + 1; } diff --git a/play.pokemonshowdown.com/src/panel-teamdropdown.tsx b/play.pokemonshowdown.com/src/panel-teamdropdown.tsx index df48b9335e..e343bc2674 100644 --- a/play.pokemonshowdown.com/src/panel-teamdropdown.tsx +++ b/play.pokemonshowdown.com/src/panel-teamdropdown.tsx @@ -45,7 +45,7 @@ class PSTeambuilder { const PPUps = set.movePPUps.map(n => { if (n === 3) return ''; return n.toString(); - }) + }); buf += ';' + PPUps.join(','); } From 243b92f3fd8cb51f8cf587ba5a4483afff9416ad Mon Sep 17 00:00:00 2001 From: dot-Comfey <84290266+dot-Comfey@users.noreply.github.com> Date: Mon, 14 Oct 2024 22:35:29 -0700 Subject: [PATCH 15/15] Update storage.js --- play.pokemonshowdown.com/js/storage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/play.pokemonshowdown.com/js/storage.js b/play.pokemonshowdown.com/js/storage.js index a4a35c1391..e0f02a3529 100644 --- a/play.pokemonshowdown.com/js/storage.js +++ b/play.pokemonshowdown.com/js/storage.js @@ -1074,7 +1074,7 @@ Storage.unpackTeam = function (buf) { 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; + if (isNaN(set.movePPUps[index])) set.movePPUps[index] = 3; } i = j + 1; }