Allow export of the 'uncategorized' format folder (#976)

This commit is contained in:
asgdf 2017-08-03 02:29:18 +02:00 committed by Guangcong Luo
parent ae57df76da
commit 8eb42e83b3
3 changed files with 12 additions and 7 deletions

View File

@ -706,11 +706,11 @@
this.edit(0);
},
createTeam: function () {
var format = this.curFolder;
var format = this.curFolder || 'gen7';
var folder = '';
if (format && format.charAt(format.length - 1) === '/') {
folder = format.slice(0, -1);
format = '';
format = 'gen7';
}
var newTeam = {
name: 'Untitled ' + (teams.length + 1),
@ -1030,9 +1030,14 @@
this.curSetList.splice(this.curSetList.length - 1, 1);
}
var isGenericFormat = function (formatName) {
if (!formatName) return true;
if (/^gen\d+$/.test(formatName)) return true;
return false;
};
if (exports.BattleFormats) {
buf += '<li class="format-select">';
buf += '<label class="label">Format:</label><button class="select formatselect teambuilderformatselect" name="format" value="' + this.curTeam.format + '">' + (Tools.escapeFormat(this.curTeam.format) || '<em>Select a format</em>') + '</button>';
buf += '<label class="label">Format:</label><button class="select formatselect teambuilderformatselect" name="format" value="' + this.curTeam.format + '">' + (isGenericFormat(this.curTeam.format) ? '<em>Select a format</em>' : Tools.escapeFormat(this.curTeam.format)) + '</button>';
var btnClass = 'button' + (!this.curSetList.length ? ' disabled' : '');
buf += ' <button name="validate" class="' + btnClass + '"><i class="fa fa-check"></i> Validate</button></li>';
}

View File

@ -542,7 +542,7 @@ Storage.unpackAllTeams = function (buffer) {
if (buffer.charAt(0) === '[' && $.trim(buffer).indexOf('\n') < 0) {
// old format
return JSON.parse(buffer).map(function (oldTeam) {
var format = oldTeam.format || '';
var format = oldTeam.format || 'gen7';
if (format && format.slice(0, 3) !== 'gen') format = 'gen6' + format;
return {
name: oldTeam.name || '',
@ -561,7 +561,7 @@ Storage.unpackAllTeams = function (buffer) {
if (bracketIndex > pipeIndex) bracketIndex = -1;
var slashIndex = line.lastIndexOf('/', pipeIndex);
if (slashIndex < 0) slashIndex = bracketIndex; // line.slice(slashIndex + 1, pipeIndex) will be ''
var format = bracketIndex > 0 ? line.slice(0, bracketIndex) : '';
var format = bracketIndex > 0 ? line.slice(0, bracketIndex) : 'gen7';
if (format && format.slice(0, 3) !== 'gen') format = 'gen6' + format;
return {
name: line.slice(slashIndex + 1, pipeIndex),
@ -987,7 +987,7 @@ Storage.importTeam = function (text, teams) {
} else if (line.substr(0, 3) === '===' && teams) {
team = [];
line = $.trim(line.substr(3, line.length - 6));
var format = '';
var format = 'gen7';
var bracketIndex = line.indexOf(']');
if (bracketIndex >= 0) {
format = line.substr(1, bracketIndex - 1);

View File

@ -15,7 +15,7 @@ fixture('Pokemon Showdown')
})
.beforeEach(t => t.maximizeWindow());
const expectedTeam = `=== Untitled 1 ===
const expectedTeam = `=== [gen7] Untitled 1 ===
Abomasnow-Mega @ Abomasite\x20\x20
Ability: Snow Warning`;