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

Fixing variable scoping error #2143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@
self.$('.teamnameedit').val(title).change();
}

Storage.activeSetList = self.curSetList = Storage.importTeam(data.paste);
Storage.activeSetList = self.curSetList = Storage.importTeam(data.paste, undefined, format.id);
} else {
Storage.activeSetList = self.curSetList = Storage.importTeam(data);
}
Expand Down
35 changes: 12 additions & 23 deletions js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,10 +1180,13 @@ Storage.getPackedTeam = function (team) {
return team.team;
};

Storage.importTeam = function (buffer, teams) {
Storage.importTeam = function (buffer, teams, format) {
var text = buffer.split("\n");
var team = teams ? null : [];
var curSet = null;
if (!format) {
format = 'gen9';
}
if (teams === true) {
Storage.teams = [];
teams = Storage.teams;
Expand All @@ -1197,7 +1200,7 @@ Storage.importTeam = function (buffer, teams) {
} else if (line.substr(0, 3) === '===' && teams) {
team = [];
line = $.trim(line.substr(3, line.length - 6));
var format = 'gen9';
format = 'gen9';
var capacity = 6;
var bracketIndex = line.indexOf(']');
if (bracketIndex >= 0) {
Expand Down Expand Up @@ -1326,11 +1329,13 @@ Storage.importTeam = function (buffer, teams) {
if (line.substr(0, 14) === 'Hidden Power [') {
var hptype = line.substr(14, line.length - 15);
line = 'Hidden Power ' + hptype;
var type = Dex.types.get(hptype);
if (!curSet.ivs && type) {
curSet.ivs = {};
for (var stat in type.HPivs) {
curSet.ivs[stat] = type.HPivs[stat];
if ((parseInt(format[3], 10) || 6) < 7) { // update IVs to match hidden power if format is gen 6 or earlier
var type = Dex.types.get(hptype);
if (!curSet.ivs && type) {
curSet.ivs = {};
for (var stat in type.HPivs) {
curSet.ivs[stat] = type.HPivs[stat];
}
}
}
}
Expand Down Expand Up @@ -1439,22 +1444,6 @@ Storage.exportTeam = function (team, gen, hidestats) {
if (curSet.ivs) {
var defaultIvs = true;
var hpType = false;
for (var j = 0; j < curSet.moves.length; j++) {
var move = curSet.moves[j];
if (move.substr(0, 13) === 'Hidden Power ' && move.substr(0, 14) !== 'Hidden Power [') {
hpType = move.substr(13);
if (!Dex.types.isName(hpType)) {
alert(move + " is not a valid Hidden Power type.");
continue;
}
for (var stat in BattleStatNames) {
if ((curSet.ivs[stat] === undefined ? 31 : curSet.ivs[stat]) !== (Dex.types.get(hpType).HPivs[stat] || 31)) {
defaultIvs = false;
break;
}
}
}
}
if (defaultIvs && !hpType) {
for (var stat in BattleStatNames) {
if (curSet.ivs[stat] !== 31 && curSet.ivs[stat] !== undefined) {
Expand Down
20 changes: 12 additions & 8 deletions src/panel-teamdropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ class PSTeambuilder {
if (delimIndex < 0) return [buffer, ''];
return [buffer.slice(0, delimIndex), buffer.slice(delimIndex + delimiter.length)];
}
static parseExportedTeamLine(line: string, isFirstLine: boolean, set: PokemonSet) {
static parseExportedTeamLine(
line: string, isFirstLine: boolean, set: PokemonSet, format: string | undefined = undefined
) {
if (isFirstLine) {
let item;
[line, item] = line.split(' @ ');
Expand Down Expand Up @@ -398,11 +400,13 @@ class PSTeambuilder {
if (line.startsWith('Hidden Power [')) {
const hpType = line.slice(14, -1) as TypeName;
line = '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 || {};
for (let stat in hpIVs) {
set.ivs[stat as StatName] = hpIVs[stat as StatName]!;
if (format && (parseInt(format[3], 10) || 6) < 7) {
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 || {};
for (let stat in hpIVs) {
set.ivs[stat as StatName] = hpIVs[stat as StatName]!;
}
}
}
}
Expand Down Expand Up @@ -504,9 +508,9 @@ class PSTeambuilder {
moves: [],
};
sets.push(curSet);
this.parseExportedTeamLine(line, true, curSet);
this.parseExportedTeamLine(line, true, curSet, curTeam?.format);
} else {
this.parseExportedTeamLine(line, false, curSet);
this.parseExportedTeamLine(line, false, curSet, curTeam?.format);
}
}
if (curTeam) {
Expand Down
Loading