From 6a8ea3fb9beaf2996bbd89cecbdbdb3a848e0c81 Mon Sep 17 00:00:00 2001 From: sirDonovan Date: Tue, 5 May 2015 18:18:34 -0500 Subject: [PATCH] Add option to ignore opponents Ignores chat messages from an opponent and causes their Pokemon to display species instead of nicknames --- js/battle.js | 11 ++++++----- js/client-battle.js | 9 +++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/js/battle.js b/js/battle.js index 5807232b0..314bd0cbd 100644 --- a/js/battle.js +++ b/js/battle.js @@ -520,14 +520,14 @@ var Pokemon = (function () { if (this.side.n === 0) { return Tools.escapeHTML(this.name); } else { - return "The opposing " + Tools.escapeHTML(this.name); + return "The opposing " + (this.side.battle.ignoreOpponent ? this.species : Tools.escapeHTML(this.name)); } }; Pokemon.prototype.getLowerName = function () { if (this.side.n === 0) { return Tools.escapeHTML(this.name); } else { - return "the opposing " + Tools.escapeHTML(this.name); + return "the opposing " + (this.side.battle.ignoreOpponent ? this.species : Tools.escapeHTML(this.name)); } }; Pokemon.prototype.getTitle = function () { @@ -540,8 +540,8 @@ var Pokemon = (function () { return titlestring; }; Pokemon.prototype.getFullName = function (plaintext) { - var name = Tools.escapeHTML(this.name); - if (this.name !== this.species) { + var name = this.side.n && this.side.battle.ignoreOpponent ? this.species : Tools.escapeHTML(this.name); + if (name !== this.species) { if (plaintext) { name += ' (' + this.species + ')'; } else { @@ -1550,7 +1550,7 @@ var Side = (function () { var gender = ''; if (pokemon.gender === 'F') gender = ' ♀'; if (pokemon.gender === 'M') gender = ' ♂'; - return '
' + Tools.escapeHTML(pokemon.name) + gender + (pokemon.level === 100 ? '' : ' L' + pokemon.level + '') + '
'; + return '
' + (this.n && this.battle.ignoreOpponent ? pokemon.species : Tools.escapeHTML(pokemon.name)) + gender + (pokemon.level === 100 ? '' : ' L' + pokemon.level + '') + '
'; }; Side.prototype.switchIn = function (pokemon, slot) { if (slot === undefined) slot = pokemon.slot; @@ -5331,6 +5331,7 @@ var Battle = (function () { case 'c': name = args[1]; if (this.ignoreSpects && (name.charAt(0) === ' ' || name.charAt(0) === '+')) break; + if (this.ignoreOpponent && name.charAt(0) === '\u2605' && toUserid(name) !== app.user.get('userid')) break; if (window.app && app.ignore && app.ignore[toUserid(name)]) break; args.shift(); args.shift(); diff --git a/js/client-battle.js b/js/client-battle.js index f51c42cf1..f98d93724 100644 --- a/js/client-battle.js +++ b/js/client-battle.js @@ -22,7 +22,7 @@ this.$chat = this.$chatFrame.find('.inner'); - this.$options = this.battle.optionsElem.html('
'); + this.$options = this.battle.optionsElem.html('
'); this.battle.customCallback = _.bind(this.updateControls, this); this.battle.endCallback = _.bind(this.updateControls, this); @@ -32,7 +32,8 @@ this.battle.play(); }, events: { - 'change input[name=ignorespects]': 'toggleIgnoreSpects' + 'change input[name=ignorespects]': 'toggleIgnoreSpects', + 'change input[name=ignoreopp]': 'toggleIgnoreOpponent' }, battleEnded: false, join: function() { @@ -691,6 +692,10 @@ toggleIgnoreSpects: function(e) { this.battle.ignoreSpects = !!e.currentTarget.checked; }, + toggleIgnoreOpponent: function(e) { + this.battle.ignoreOpponent = !!e.currentTarget.checked; + this.battle.add('Opponent ' + (this.battle.ignoreOpponent ? '' : 'no longer ') + 'ignored.'); + }, forfeit: function() { this.send('/forfeit'); },