Skip to content

Commit

Permalink
Fixed a bug with loading storage
Browse files Browse the repository at this point in the history
Also made all thrown objects Errors rather than strings, better for
debugging.
  • Loading branch information
varkor committed Dec 25, 2015
1 parent 2cc9ec9 commit 9a4e1c4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions battle/scripts/functions/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function _ (_object, _path, _newValue) {
var checkForProperty = path.slice(-1) === "?", setNew = arguments.length >= 3, baseKey = null;
if (setNew) {
if (checkForProperty) {
throw "You can't both check for the existence of a property and set it at the same time.";
throw new Error("You can't both check for the existence of a property and set it at the same time.");
} else {
baseKey = path.split(/ ?[~\-=]> ?/g).last();
path = path.replace(/(.*) ?[~\-=]> ?.*?$/, "$1").trim();
Expand All @@ -63,7 +63,7 @@ function _ (_object, _path, _newValue) {
} else {
if (object.object.hasOwnProperty(specialCase[1]))
return respond(object.object[specialCase[1]]);
else throw "That object has no property with the path: " + path;
else throw new Error("That object has no property with the path: " + path);
}
}
var oSpecialCase = path.split(/ ?[~\-]> ?/g);
Expand All @@ -79,7 +79,7 @@ function _ (_object, _path, _newValue) {
if (checkForProperty)
return false;
else
throw "That object has no property with the path: " + path;
throw new Error("That object has no property with the path: " + path);
}
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ function _ (_object, _path, _newValue) {
if (checkForProperty)
return false;
else
throw "That object has no property with the path: " + path;
throw new Error("That object has no property with the path: " + path);
}

function _method (object) {
Expand Down
2 changes: 1 addition & 1 deletion battle/scripts/functions/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ DataObject = {
if (!object.hasOwnProperty(key))
object[key] = methods[key];
else
throw "That object already has a property with the name: " + key;
throw new Error("That object already has a property with the name: " + key);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion battle/scripts/objects/general/BattleContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ function BattleContext (client) {
battleContext.begin();
}
} else
throw "You've tried to start a battle when one is already in progress!";
throw new Error("You've tried to start a battle when one is already in progress!");
},
begin : function () {
battleContext.state = {
Expand Down
2 changes: 1 addition & 1 deletion battle/scripts/objects/general/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function pokemon (data, validate) {

setProperty("species", "Missingno. (Nintendo)");
if (!Pokedex._(self.species + "?")) {
throw "There exists no Pokémon in the Pokédex object with the species name \"" + self.species + "\".";
throw new Error("There exists no Pokémon in the Pokédex object with the species name \"" + self.species + "\".");
}
var species = function (property) {
if (self["form(e)"] === null)
Expand Down
4 changes: 2 additions & 2 deletions battle/scripts/objects/general/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function storage (initial) {

if (arguments.length > 0)
foreach(initial, function (box) {
var newBox = self.addBox(box.name);
var newBox = self.addBox(box.box);
foreach(box.contents, function (poke) {
newBox.slots[poke.slot] = new pokemon(poke);
newBox.slots[poke.slot] = new pokemon(poke.pokemon);
});
});

Expand Down
6 changes: 3 additions & 3 deletions battle/scripts/objects/unique/Display.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Display = {
else
state = Display.states[state];
if (state === null)
throw "You've tried to find a Pokémon in a state that no longer exists!";
throw new Error("You've tried to find a Pokémon in a state that no longer exists!");
var match = null;
foreach([].concat(state.allies, state.opponents), function (compare) {
if (poke.hasOwnProperty("original") ? poke.original === compare.original : poke === compare.original)
Expand Down Expand Up @@ -132,15 +132,15 @@ Display = {
for (var i = 0; i < state; ++ i)
self.states[i] = null;
if (self.states[state] === null)
throw "You've tried to load an older state than the current one! (State " + state + ")";
throw new Error("You've tried to load an older state than the current one! (State " + state + ")");
self.state.current = self.states[state];
self.refreshWidgetsFromState(self.state.current);
Battle.cache = null;
},
transition : function (state, track, original) {
var self = Display, from = self.state.current, to = self.states[state], fromAll, toAll, originalAll, completed = true;
if (to === null)
throw "You've tried to transition to an older state than the current one! (State " + state + ")";
throw new Error("You've tried to transition to an older state than the current one! (State " + state + ")");
if (arguments.length < 2) {
track = {
completed : false
Expand Down

0 comments on commit 9a4e1c4

Please sign in to comment.