diff --git a/js/client-teambuilder.js b/js/client-teambuilder.js index e03e6102f..9335b2b8d 100644 --- a/js/client-teambuilder.js +++ b/js/client-teambuilder.js @@ -19,7 +19,9 @@ }, events: { // teambuilder events - 'keydown .chartinput': 'chartKeydown' + 'keydown .chartinput': 'chartKeydown', + 'focus .chartinput': 'chartFocus', + 'change .chartinput': 'chartChange' }, dispatchClick: function(e) { e.preventDefault(); @@ -323,7 +325,7 @@ this.curSet = newPokemon; this.curSetLoc = this.curTeam.team.length-1; this.update(); - // selfR.teamBuilderElem.find('.setcell-pokemon input').select(); + this.$('input[name=pokemon]').select(); }, /********************************************************* @@ -368,6 +370,170 @@ buf += '
'; this.$el.html(buf); + this.$chart = this.$('.teambuilder-results'); + }, + curChartType: '', + curChartName: '', + updateChart: function() { + var type = this.curChartType; + if (type === 'stats') { + this.updateStatForm(); + return; + } + if (type === 'details') { + this.updateDetailsForm(); + return; + } + this.$chart.html('Loading '+this.curChartType+'...'); + }, + setStatFormGuesses: function() { + this.updateStatForm(true); + }, + updateStatForm: function(setGuessed) { + var buf = ''; + var set = this.curSet; + buf += '

EVs

'; + buf += '
'; + var role = this.guessRole(); + + var guessedEVs = {}; + var guessedPlus = ''; + var guessedMinus = ''; + buf += '

Suggested spread:'; + if (role === '?') { + buf += '
(Please choose 4 moves to get a suggested spread)

'; + } else { + guessedEVs = this.guessEVs(role); + guessedPlus = guessedEVs.plusStat; delete guessedEVs.plusStat; + guessedMinus = guessedEVs.minusStat; delete guessedEVs.minusStat; + buf += '
'; + buf += '
('+role+' | bulk: phys '+Math.round(this.moveCount.physicalBulk/1000)+' + spec '+Math.round(this.moveCount.specialBulk/1000)+' = '+Math.round(this.moveCount.bulk/1000)+')

'; + } + + if (setGuessed) { + set.evs = guessedEVs; + this.plus = guessedPlus; + this.minus = guessedMinus; + this.updateNature(); + } + + var stats = {hp:'',atk:'',def:'',spa:'',spd:'',spe:''}; + if (!set) return; + var nature = BattleNatures[set.nature || 'Serious']; + if (!nature) nature = {}; + + // label column + buf += '
'; + buf += '
'; + buf += '
'; + + buf += '
'; + for (var i in stats) { + stats[i] = this.getStat(i); + buf += '
'+stats[i]+'
'; + } + buf += '
'; + + buf += '
'; + for (var i in stats) { + var width = stats[i]*200/504; + if (i=='hp') width = Math.floor(stats[i]*200/704); + if (width > 199) width = 199; + var color = Math.floor(stats[i]*180/714); + if (color>360) color = 360; + buf += '
'; + } + buf += '
Remaining:
'; + buf += '
'; + + buf += '
EVs
'; + var totalev = 0; + this.plus = ''; + this.minus = ''; + for (var i in stats) { + var width = stats[i]*200/504; + if (i=='hp') width = stats[i]*200/704; + if (width > 200) width = 200; + var val = ''+(set.evs[i]||''); + if (nature.plus === i) { + val += '+'; + this.plus = i; + } + if (nature.minus === i) { + val += '-'; + this.minus = i; + } + buf += '
'; + totalev += (set.evs[i]||0); + } + if (totalev <= 510) { + buf += '
'+(totalev>508?0:508-totalev)+'
'; + } else { + buf += '
'+(510-totalev)+'
'; + } + buf += '
'; + + buf += '
IVs
'; + var totalev = 0; + if (!set.ivs) set.ivs = {}; + for (var i in stats) { + if (typeof set.ivs[i] === 'undefined') set.ivs[i] = 31; + var val = ''+(set.ivs[i]); + buf += '
'; + } + //buf += '
'+''+'
'; + buf += '
'; + + buf += '

Nature:

'; + + buf += '

Protip: You can also set natures by typing "+" and "-" next to a stat.

'; + + buf += '
'; + this.$chart.html(buf); + }, + updateDetailsForm: function() { + var buf = ''; + var set = this.curSet; + var template = Tools.getTemplate(set.species); + if (!set) return; + buf += '

Details

'; + buf += '
'; + + buf += '
'; + + buf += '
'; + if (template.gender) { + var genderTable = {'M': "Male", 'F': "Female", 'N': "Genderless"}; + buf += genderTable[template.gender]; + } else { + buf += ' '; + buf += ' '; + buf += ''; + } + buf += '
'; + + buf += '
'; + + buf += '
'; + buf += ' '; + buf += ''; + buf += '
'; + + buf += '
'; + this.$chart.html(buf); }, arrangeCallback: { @@ -431,14 +597,108 @@ } }, stats: function(i, button) { - this.selectPokemon($(button).closest('li').val()); + if (!this.curSet) this.selectPokemon($(button).closest('li').val()); + this.curChartType = 'stats'; + this.updateStatForm(); }, details: function(i, button) { - this.selectPokemon($(button).closest('li').val()); + if (!this.curSet) this.selectPokemon($(button).closest('li').val()); + this.curChartType = 'details'; + this.updateDetailsForm(); + }, + chartTypes: { + pokemon: 'pokemon', + item: 'item', + ability: 'ability', + move1: 'move', + move2: 'move', + move3: 'move', + move4: 'move', + stats: 'stats', + details: 'details' }, chartKeydown: function() { // }, + chartFocus: function(e) { + var $target = $(e.currentTarget); + var name = e.currentTarget.name; + var type = this.chartTypes[name]; + + if (!this.curSet) { + var i = +$target.closest('li').prop('value'); + this.curSet = this.curTeam.team[i]; + this.curSetLoc = i; + this.update(); + if (type === 'stats' || type === 'details') { + this.$('button[name='+name+']').click(); + } else { + this.$('input[name='+name+']').select(); + } + return; + } + + this.curChartName = name; + this.curChartType = type; + this.updateChart(); + }, + chartChange: function(e) { + var name = e.currentTarget.name; + var type = this.chartTypes[name]; + var val = Chart.firstResult; + var id = toId(e.currentTarget.value); + if (toId(val) !== id) { + $(e.currentTarget).addClass('incomplete'); + return; + } + e.currentTarget.value = val; + switch (name) { + case 'pokemon': + // selfR.formChangePokemon(val); + break; + case 'item': + if (val || e.currentTarget.value === '') { + this.curSet.item = val; + // selfR.updatePokemonSprite(); + } + break; + case 'ability': + if (val) { + this.curSet.ability = val; + } + break; + case 'move1': + if (val || e.currentTarget.value === '') { + this.curSet.moves[0] = val; + // selfR.formChooseMove(val); + } + break; + case 'move2': + if (!this.curSet.moves[0]) this.curSet.moves[0] = ''; + if (val || e.currentTarget.value === '') { + this.curSet.moves[1] = val; + // selfR.formChooseMove(val); + } + break; + case 'move3': + if (!this.curSet.moves[0]) this.curSet.moves[0] = ''; + if (!this.curSet.moves[1]) this.curSet.moves[1] = ''; + if (val || e.currentTarget.value === '') { + this.curSet.moves[2] = val; + // selfR.formChooseMove(val); + } + break; + case 'move4': + if (!this.curSet.moves[0]) this.curSet.moves[0] = ''; + if (!this.curSet.moves[1]) this.curSet.moves[1] = ''; + if (!this.curSet.moves[2]) this.curSet.moves[2] = ''; + if (val || e.currentTarget.value === '') { + this.curSet.moves[3] = val; + // selfR.formChooseMove(val); + } + break; + } + }, /********************************************************* * Utility functions