Skip to content

Commit

Permalink
More style fixes and Gulpfile updates
Browse files Browse the repository at this point in the history
JSHint is now a fair bit stricter, and is now correctly checking
files in `mods/`.

The code has been fixed to match the new stricter standards.

JSHint has now caught its second actual bug: Gen 5 Pinap Berry
was Ice instead of Grass.
  • Loading branch information
Zarel committed Aug 11, 2014
1 parent 12b673b commit af20264
Show file tree
Hide file tree
Showing 32 changed files with 327 additions and 340 deletions.
49 changes: 18 additions & 31 deletions battle-engine.js
Expand Up @@ -66,6 +66,8 @@ global.string = function (str) {

global.Tools = require('./tools.js');

var Battle, BattleSide, BattlePokemon;

var Battles = {};

// Receive and process a message sent using Simulator.prototype.send in
Expand Down Expand Up @@ -136,7 +138,7 @@ process.on('message', function (message) {
}
});

var BattlePokemon = (function () {
BattlePokemon = (function () {
function BattlePokemon(set, side) {
this.side = side;
this.battle = side.battle;
Expand Down Expand Up @@ -568,7 +570,7 @@ var BattlePokemon = (function () {
}
return boosts;
};
BattlePokemon.prototype.boostBy = function (boost, source, effect) {
BattlePokemon.prototype.boostBy = function (boost) {
var changed = false;
for (var i in boost) {
var delta = boost[i];
Expand Down Expand Up @@ -1210,7 +1212,7 @@ var BattlePokemon = (function () {
return BattlePokemon;
})();

var BattleSide = (function () {
BattleSide = (function () {
function BattleSide(name, battle, n, team) {
this.battle = battle;
this.n = n;
Expand Down Expand Up @@ -1257,12 +1259,6 @@ var BattleSide = (function () {
id: this.id,
pokemon: []
};
function annotateHiddenPower(move) {
if (move === 'hiddenpower') {
return move + toId(pokemon.hpType) + (pokemon.hpPower === 70 ? '' : pokemon.hpPower);
}
return move;
}
for (var i = 0; i < this.pokemon.length; i++) {
var pokemon = this.pokemon[i];
data.pokemon.push({
Expand All @@ -1277,7 +1273,12 @@ var BattleSide = (function () {
spd: pokemon.baseStats['spd'],
spe: pokemon.baseStats['spe']
},
moves: pokemon.moves.map(annotateHiddenPower),
moves: pokemon.moves.map(function (move) {
if (move === 'hiddenpower') {
return move + toId(pokemon.hpType) + (pokemon.hpPower === 70 ? '' : pokemon.hpPower);
}
return move;
}),
baseAbility: pokemon.baseAbility,
item: pokemon.item,
pokeball: pokemon.pokeball,
Expand Down Expand Up @@ -1366,7 +1367,7 @@ var BattleSide = (function () {
return BattleSide;
})();

var Battle = (function () {
Battle = (function () {
var Battle = {};

Battle.construct = (function () {
Expand Down Expand Up @@ -2097,7 +2098,7 @@ var Battle = (function () {
if (status.thing && status.thing.getStat) status.speed = status.thing.speed;
};
// bubbles up to parents
Battle.prototype.getRelevantEffects = function (thing, callbackType, foeCallbackType, foeThing, checkChildren) {
Battle.prototype.getRelevantEffects = function (thing, callbackType, foeCallbackType, foeThing) {
var statuses = this.getRelevantEffectsInner(thing, callbackType, foeCallbackType, foeThing, true, false);
statuses.sort(Battle.comparePriority);
//if (statuses[0]) this.debug('match ' + callbackType + ': ' + statuses[0].status.id);
Expand Down Expand Up @@ -3062,17 +3063,15 @@ var Battle = (function () {
return pokemon.side.foe.randomActive() || pokemon.side.foe.active[0];
};
Battle.prototype.checkFainted = function () {
function isFainted(a) {
if (!a) return false;
function check(a) {
if (!a) return;
if (a.fainted) {
a.switchFlag = true;
return true;
}
return false;
}
// make sure these don't get short-circuited out; all switch flags need to be set
var p1fainted = this.p1.active.map(isFainted);
var p2fainted = this.p2.active.map(isFainted);

this.p1.active.forEach(check);
this.p2.active.forEach(check);
};
Battle.prototype.faintMessages = function (lastFirst) {
if (this.ended) return;
Expand Down Expand Up @@ -3443,26 +3442,15 @@ var Battle = (function () {
}
this.addQueue(null);

var currentPriority = 6;

while (this.queue.length) {
var decision = this.queue.shift();

/* while (decision.priority < currentPriority && currentPriority > -6) {
this.eachEvent('Priority', null, currentPriority);
currentPriority--;
} */

this.runDecision(decision);

if (this.currentRequest) {
return;
}

// if (!this.queue.length || this.queue[0].choice === 'runSwitch') {
// if (this.faintMessages()) return;
// }

if (this.ended) return;
}

Expand Down Expand Up @@ -3618,7 +3606,6 @@ var Battle = (function () {
return false;
}

var decision = null;
switch (choice) {
case 'team':
decisions.push({
Expand Down
8 changes: 5 additions & 3 deletions cidr.js
Expand Up @@ -36,9 +36,11 @@ var getPattern = exports.getPattern = function (cidr) {
* passed IP is in the range.
*/
var checker = exports.checker = function (cidr) {
if (!cidr || !cidr.length) return function () {
return false;
};
if (!cidr || !cidr.length) {
return function () {
return false;
};
}

var patterns;
if (Array.isArray(cidr)) {
Expand Down
41 changes: 21 additions & 20 deletions command-parser.js
Expand Up @@ -30,9 +30,29 @@ const MESSAGE_COOLDOWN = 5 * 60 * 1000;

const MAX_PARSE_RECURSION = 10;

var crypto = require('crypto');
var fs = require('fs');

/*********************************************************
* Load command files
*********************************************************/

var commands = exports.commands = require('./commands.js').commands;

var customCommands = require('./config/commands.js');
if (customCommands && customCommands.commands) {
Object.merge(commands, customCommands.commands);
}

// Install plug-in commands

fs.readdirSync('./chat-plugins').forEach(function (file) {
if (file.substr(-3) === '.js') Object.merge(commands, require('./chat-plugins/' + file).commands);
});

/*********************************************************
* Parser
*********************************************************/

var modlog = exports.modlog = {lobby: fs.createWriteStream('logs/modlog/modlog_lobby.txt', {flags:'a+'}), battle: fs.createWriteStream('logs/modlog/modlog_battle.txt', {flags:'a+'})};

/**
Expand Down Expand Up @@ -383,22 +403,3 @@ exports.uncacheTree = function (root) {
uncache = newuncache;
} while (uncache.length > 0);
};

/*********************************************************
* Commands
*********************************************************/

var commands = exports.commands = require('./commands.js').commands;

var customCommands = require('./config/commands.js');
if (customCommands && customCommands.commands) {
Object.merge(commands, customCommands.commands);
}

/*********************************************************
* Install plug-in commands
*********************************************************/

fs.readdirSync('./chat-plugins').forEach(function (file) {
if (file.substr(-3) === '.js') Object.merge(commands, require('./chat-plugins/' + file).commands);
});
27 changes: 13 additions & 14 deletions commands.js
Expand Up @@ -250,7 +250,6 @@ var commands = exports.commands = {
roomintro: function (target, room, user) {
if (!target) {
if (!this.canBroadcast()) return;
var re = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/g;
if (!room.introMessage) return this.sendReply("This room does not have an introduction set.");
this.sendReplyBox(room.introMessage);
if (!this.broadcasting && user.can('declare', null, room)) {
Expand Down Expand Up @@ -792,7 +791,7 @@ var commands = exports.commands = {
*********************************************************/

mn: 'modnote',
modnote: function (target, room, user, connection, cmd) {
modnote: function (target, room, user, connection) {
if (!target) return this.parse('/help modnote');
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply("The note is too long. It cannot exceed " + MAX_REASON_LENGTH + " characters.");
Expand Down Expand Up @@ -1030,7 +1029,6 @@ var commands = exports.commands = {
filename = 'logs/modlog/modlog_' + roomId + '.txt';
}

var roomLogs = {};
// Seek for all input rooms for the lines or text
command = 'tail -' + lines + ' ' + filename;
var grepLimit = 100;
Expand Down Expand Up @@ -1146,7 +1144,7 @@ var commands = exports.commands = {

savelearnsets: function (target, room, user) {
if (!this.can('hotpatch')) return false;
fs.writeFile('data/learnsets.js', 'exports.BattleLearnsets = ' + JSON.stringify(BattleLearnsets) + ";\n");
fs.writeFile('data/learnsets.js', 'exports.BattleLearnsets = ' + JSON.stringify(Tools.data.Learnsets) + ";\n");
this.sendReply("learnsets.js saved.");
},

Expand Down Expand Up @@ -1364,39 +1362,40 @@ var commands = exports.commands = {
if (target === 'all') {
this.sendReply("Loading memory usage, this might take a while.");
}
var roomSize, configSize, rmSize, cpSize, simSize, usersSize, toolsSize;
if (target === 'all' || target === 'rooms' || target === 'room') {
this.sendReply("Calculating Room size...");
var roomSize = ResourceMonitor.sizeOfObject(Rooms);
roomSize = ResourceMonitor.sizeOfObject(Rooms);
this.sendReply("Rooms are using " + roomSize + " bytes of memory.");
}
if (target === 'all' || target === 'config') {
this.sendReply("Calculating config size...");
var configSize = ResourceMonitor.sizeOfObject(Config);
configSize = ResourceMonitor.sizeOfObject(Config);
this.sendReply("Config is using " + configSize + " bytes of memory.");
}
if (target === 'all' || target === 'resourcemonitor' || target === 'rm') {
this.sendReply("Calculating Resource Monitor size...");
var rmSize = ResourceMonitor.sizeOfObject(ResourceMonitor);
rmSize = ResourceMonitor.sizeOfObject(ResourceMonitor);
this.sendReply("The Resource Monitor is using " + rmSize + " bytes of memory.");
}
if (target === 'all' || target === 'cmdp' || target === 'cp' || target === 'commandparser') {
this.sendReply("Calculating Command Parser size...");
var cpSize = ResourceMonitor.sizeOfObject(CommandParser);
cpSize = ResourceMonitor.sizeOfObject(CommandParser);
this.sendReply("Command Parser is using " + cpSize + " bytes of memory.");
}
if (target === 'all' || target === 'sim' || target === 'simulator') {
this.sendReply("Calculating Simulator size...");
var simSize = ResourceMonitor.sizeOfObject(Simulator);
simSize = ResourceMonitor.sizeOfObject(Simulator);
this.sendReply("Simulator is using " + simSize + " bytes of memory.");
}
if (target === 'all' || target === 'users') {
this.sendReply("Calculating Users size...");
var usersSize = ResourceMonitor.sizeOfObject(Users);
usersSize = ResourceMonitor.sizeOfObject(Users);
this.sendReply("Users is using " + usersSize + " bytes of memory.");
}
if (target === 'all' || target === 'tools') {
this.sendReply("Calculating Tools size...");
var toolsSize = ResourceMonitor.sizeOfObject(Tools);
toolsSize = ResourceMonitor.sizeOfObject(Tools);
this.sendReply("Tools are using " + toolsSize + " bytes of memory.");
}
if (target === 'all' || target === 'v8') {
Expand All @@ -1409,7 +1408,7 @@ var commands = exports.commands = {
}
if (target === 'all') {
this.sendReply("Calculating Total size...");
var total = (roomSize + configSize + rmSize + cpSize + simSize + toolsSize + usersSize) || 0;
var total = (roomSize + configSize + rmSize + cpSize + simSize + usersSize + toolsSize) || 0;
var units = ["bytes", "K", "M", "G"];
var converted = total;
var unit = 0;
Expand All @@ -1434,7 +1433,7 @@ var commands = exports.commands = {
});
},

eval: function (target, room, user, connection, cmd, message) {
eval: function (target, room, user, connection) {
if (!user.hasConsoleAccess(connection)) {
return this.sendReply("/eval - Access denied.");
}
Expand All @@ -1452,7 +1451,7 @@ var commands = exports.commands = {
}
},

evalbattle: function (target, room, user, connection, cmd, message) {
evalbattle: function (target, room, user, connection) {
if (!user.hasConsoleAccess(connection)) {
return this.sendReply("/evalbattle - Access denied.");
}
Expand Down

0 comments on commit af20264

Please sign in to comment.