Skip to content

Commit

Permalink
Enforced use of JavaScript strict mode
Browse files Browse the repository at this point in the history
This allows the use of more advanced JavaScript features as well as
potentially catching bugs earlier. There are probably some rough edges
after this transition, so expect more commits fixing those problems.
  • Loading branch information
varkor committed Feb 27, 2016
1 parent 5cb836b commit 5183fd9
Show file tree
Hide file tree
Showing 45 changed files with 158 additions and 68 deletions.
6 changes: 4 additions & 2 deletions battle/battle.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@
<ul id="team" class="zebra"></ul>
<ul id="users"></ul>
<script>
Battle = null;
"use strict";

Interface = {
let Battle = null;

const Interface = {
random : new srandom(172),
initialise : function () {
document.querySelector("#connect").addEventListener("mousedown", function (event) {
Expand Down
2 changes: 2 additions & 0 deletions battle/imports.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var paths = [
"scripts/functions/objects.js",
"scripts/functions/random.js",
Expand Down
4 changes: 3 additions & 1 deletion battle/scripts/data/Abilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Abilities = {
"use strict";

const Abilities = {
"Intimidate" : {
effects : [
{
Expand Down
4 changes: 3 additions & 1 deletion battle/scripts/data/Classes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Classes = {
"use strict";

const Classes = {
"Ace Trainer" : {
"payout" : 100
},
Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/data/Clauses.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

Clauses = {
"Baton Pass" : {
description : "Only one Pokémon in each party may know Baton Pass.",
Expand Down
4 changes: 3 additions & 1 deletion battle/scripts/data/Events.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Events = [
"use strict";

const Events = [
];
4 changes: 3 additions & 1 deletion battle/scripts/data/Items.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Items = {
"use strict";

const Items = {
"Medicines" : {
standard : {
use : "healing",
Expand Down
4 changes: 3 additions & 1 deletion battle/scripts/data/Moves.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Moves = {
"use strict";

const Moves = {
Confused : {
type : "Typeless",
category : Move.category.physical,
Expand Down
4 changes: 3 additions & 1 deletion battle/scripts/data/Pokedex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Pokedex = {
"use strict";

const Pokedex = {
"Missingno. (Nintendo)" : {
"types" : ["Bird", "Normal"],
"experience" : "fast",
Expand Down
6 changes: 4 additions & 2 deletions battle/scripts/data/accessories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Badges = {
"use strict";

const Badges = {
"Boulder" : {
enabled : [HMs.indexOf(Moves.Flash)],
obediance : null
Expand All @@ -10,6 +12,6 @@ Badges = {
};
_method(Badges);

Ribbons = {
const Ribbons = {
};
_method(Ribbons);
48 changes: 25 additions & 23 deletions battle/scripts/data/constants.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"use strict";

var q;

Stats = {
const Stats = {
permanent : ["health", "attack", "defence", "special attack", "special defence", "speed"],
transient : ["accuracy", "evasion", "critical"],
};
Stats.all = [].concat(Stats.permanent, Stats.transient);

Experiences = ["erratic", "fast", "medium fast", "medium slow", "slow", "fluctuating"];
const Experiences = ["erratic", "fast", "medium fast", "medium slow", "slow", "fluctuating"];

Evolution = {
const Evolution = {
// Ways to trigger an evolution
methods : [
"level", // Triggered when the Pokémon levels up (often used in conjunction with other properties)
Expand All @@ -23,7 +25,7 @@ Evolution = {
]
};

Natures = {
const Natures = {
"Hardy" : {
},
"Docile" : {
Expand Down Expand Up @@ -116,11 +118,11 @@ Natures = {
}
};

Weathers = ["clear skies", "intense sunlight", "extremely harsh sunlight", "rain", "heavy rain", "sandstorm", "hail", "diamond dust", "shadowy aura", "fog", "strong winds"];
const Weathers = ["clear skies", "intense sunlight", "extremely harsh sunlight", "rain", "heavy rain", "sandstorm", "hail", "diamond dust", "shadowy aura", "fog", "strong winds"];

Development = ["complete", "incomplete", "unstarted"];
const Development = ["complete", "incomplete", "unstarted"];

Statuses = ["none", "burned", "frozen", "paralysed", "poisoned", "badly poisoned", "asleep"];
const Statuses = ["none", "burned", "frozen", "paralysed", "poisoned", "badly poisoned", "asleep"];
Statuses.Volatile = ["confused", "infatuated"];

/*
Expand All @@ -130,7 +132,7 @@ Statuses.Volatile = ["confused", "infatuated"];
data:
oneself : Whether the Pokémon that triggered the event is itself
*/
Triggers = {
const Triggers = {
/*
Triggered when the Pokémon is sent out.
*/
Expand Down Expand Up @@ -209,9 +211,9 @@ Triggers = {
status : ++ q
};

Genders = ["male", "female", "neuter"];
const Genders = ["male", "female", "neuter"];

Time = {
const Time = {
framerate : Settings._("framerate"),
speed : Settings._("speed"),
millisecond : 1,
Expand All @@ -221,9 +223,9 @@ Time = {
};
Time.refresh = Time.second / Time.framerate;

Nationalities = ["British"];
const Nationalities = ["British"];

Item = {
const Item = {
use : [
"healing", // Restore health
"curing", // Cure a status effect
Expand All @@ -233,7 +235,7 @@ Item = {
]
};

Battles = {
const Battles = {
style : ["normal", "double", "sky"],
side : {
// These are empty objects simply so they're unique from one another. They even conserve uniqueness after being transformed to JSON and back, which is rather handy. They do ~not~, however, need to be identified after being transferred by JSON — just distinguished, because getPokemonInPlace does not actually use the `side` parameter — it just checks for it.
Expand All @@ -255,15 +257,15 @@ Battles = {
}
};

Trainers = {
const Trainers = {
type : {
NPC : q = 0,
local : ++ q,
online : ++ q
}
};

Directions = {
const Directions = {
up : q = 0,
right : ++ q,
down : ++ q,
Expand All @@ -278,13 +280,13 @@ Scenes.addData({
"Forest Trail" : {}
});

Creators = {
const Creators = {
"Nintendo" : {
"games" : ["RSE"]
}
};

Games = {
const Games = {
"RSE" : {
"constituents" : ["Ruby", "Sapphire", "Emerald"],
"region" : "Hoenn",
Expand All @@ -305,18 +307,18 @@ Games = {
}
};

Regions = ["Hoenn", "Kanto"];
const Regions = ["Hoenn", "Kanto"];

Pokerus = ["uninfected", "infected", "immune"];
const Pokerus = ["uninfected", "infected", "immune"];

Tiles = ["grass", "long grass", "dark grass", "seaweed"];
const Tiles = ["grass", "long grass", "dark grass", "seaweed"];

NoPokemon = {};
const NoPokemon = {};

onlyPokemon = function (poke) {
const onlyPokemon = function (poke) {
return poke !== NoPokemon;
};

onlyNoPokemon = function (poke) {
const onlyNoPokemon = function (poke) {
return poke === NoPokemon;
};
6 changes: 4 additions & 2 deletions battle/scripts/data/machines.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
TMs = [
"use strict";

const TMs = [
];

HMs = [
const HMs = [
"Flash",
"Cut"
];
6 changes: 4 additions & 2 deletions battle/scripts/functions/File.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
File = {
"use strict";

const File = {
loadFileOfType : function (_store, object, loadEvent, dataForFile, directory, filetype, _paths, uponLoad, uponError, _redirectedPaths) {
var store = _store;
if (!Files.hasOwnProperty(store))
Expand Down Expand Up @@ -84,6 +86,6 @@ File = {
}
}
};
Files = {
const Files = {
nonexistent : []
};
4 changes: 3 additions & 1 deletion battle/scripts/functions/Font.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Font = {
"use strict";

const Font = {
load : function (size, weight, style, typeface) {
size *= window.devicePixelRatio;
if (!["px", "pt", "em", "rem"].contains(("" + size).substr(-2)))
Expand Down
4 changes: 3 additions & 1 deletion battle/scripts/functions/Sound.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Sound = {
"use strict";

const Sound = {
load : function (_paths, uponLoad, uponError, filetype, playImmediately) {
var paths = wrapArray(_paths).slice(0), filetype = arguments.length >= 4 && typeof _filetype !== "undefined" ? _filetype : null;
if (filetype === null) {
Expand Down
4 changes: 3 additions & 1 deletion battle/scripts/functions/Sprite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Sprite = FunctionObject.new({
"use strict";

const Sprite = FunctionObject.new({
canvases : [],
load : function (_paths, uponLoad, uponError, _filetype) {
var paths = wrapArray(_paths).slice(0), filetype = arguments.length >= 4 && typeof _filetype !== "undefined" ? _filetype : null;
Expand Down
6 changes: 4 additions & 2 deletions battle/scripts/functions/functions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function foreach (array, fn) {
var deletion = [], i, broke = false;
for (i = 0; i < array.length; ++ i) {
Expand Down Expand Up @@ -401,15 +403,15 @@ function quantityWord (times) {
return numberword(times) + " times";
}

Vector = function (vector) {
const Vector = function (vector) {
var self = this;
if (arguments.length)
self.vector = vector;
else
self.vector = [0, 0];
};

Matrix = function (matrix) {
const Matrix = function (matrix) {
/*
Matrices in <canvas> contexts are represented by:
[a c e]
Expand Down
6 changes: 4 additions & 2 deletions battle/scripts/functions/objects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
DataObject = {
"use strict";

const DataObject = {
new : function () {
var object = {
data : {},
Expand Down Expand Up @@ -46,7 +48,7 @@ DataObject = {
}
};

FunctionObject = {
const FunctionObject = {
objects : [],
initialised : false,
new : function (object, details) {
Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/functions/random.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function srandom (seed) {
var self = this;

Expand Down
3 changes: 2 additions & 1 deletion battle/scripts/objects/general/BattleContext.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function BattleContext (client) {
if (arguments.length < 1)
client = false;
Expand Down Expand Up @@ -666,7 +668,6 @@ function BattleContext (client) {
},
beginOnline : function (seed, alliedTrainers, opposingTrainers, settings, callback) {
battleContext.random.seed = seed;
settings.flags.pushIfNotAlreadyContained("competitive");
battleContext.initiate(alliedTrainers, opposingTrainers, settings, callback);
},
beginWildBattle : function (alliedTrainers, pokes, settings, callback) {
Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/objects/general/bag.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function bag (items) {
var self = this;

Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/objects/general/battler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

battler.resetDisplay = function (self) {
self.display = {
transition : 1,
Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/objects/general/dex.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function dex (data) {
var self = this;

Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/objects/general/party.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function party (initial) {
var self = this;

Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/objects/general/pokemon.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function pokemon (data, validate) {
var self = this;

Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/objects/general/storage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function storage (initial) {
var self = this;

Expand Down
2 changes: 2 additions & 0 deletions battle/scripts/objects/general/trainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

function trainer (data) {
var self = this;

Expand Down
Loading

0 comments on commit 5183fd9

Please sign in to comment.