Add destroy method, major bugfixes on {observed}, successFn, failureFn

This commit is contained in:
Riley Shaw 2014-12-14 04:05:26 -05:00
parent a0c6b07d7d
commit 60a70b88e4
6 changed files with 27 additions and 9 deletions

View File

@ -168,8 +168,8 @@ var factory = (function () {
types[type].prototype[key] = value; types[type].prototype[key] = value;
}); });
types[type].prototype.successFn = types[type].wait; types[type].prototype.successFn = types[type].prototype.wait;
types[type].prototype.failureFn = types[type].wait; types[type].prototype.failureFn = types[type].prototype.wait;
types[type].prototype.energy = options.initialEnergy; types[type].prototype.energy = options.initialEnergy;
return true; return true;

View File

@ -131,7 +131,7 @@ Terrarium.prototype.step = function (steps) {
y: y, y: y,
creature: returnedCreature creature: returnedCreature
}); });
if (!self.hasChanged && returnedCreature.observed) self.hasChanged = true; if (!self.hasChanged && result.observed) self.hasChanged = true;
} else { } else {
if (result && !self.hasChanged) self.hasChanged = true; if (result && !self.hasChanged) self.hasChanged = true;
processLoser(creature); processLoser(creature);
@ -243,4 +243,13 @@ Terrarium.prototype.stop = function () {
this.nextFrame = false; this.nextFrame = false;
}; };
/**
* Stops any currently running animation and cleans up the DOM
*/
Terrarium.prototype.destroy = function () {
var canvas = this.canvas;
this.stop();
canvas.parentNode.removeChild(canvas);
};
module.exports = Terrarium; module.exports = Terrarium;

View File

@ -1,6 +1,6 @@
{ {
"name": "terra", "name": "terra",
"version": "1.4.0-beta", "version": "1.5.0-beta",
"homepage": "https://github.com/rileyjshaw/terra", "homepage": "https://github.com/rileyjshaw/terra",
"authors": [ "authors": [
"rileyjshaw <i@rileyjshaw.com>" "rileyjshaw <i@rileyjshaw.com>"

15
dist/terra.js vendored
View File

@ -179,8 +179,8 @@ var factory = (function () {
types[type].prototype[key] = value; types[type].prototype[key] = value;
}); });
types[type].prototype.successFn = types[type].wait; types[type].prototype.successFn = types[type].prototype.wait;
types[type].prototype.failureFn = types[type].wait; types[type].prototype.failureFn = types[type].prototype.wait;
types[type].prototype.energy = options.initialEnergy; types[type].prototype.energy = options.initialEnergy;
return true; return true;
@ -435,7 +435,7 @@ Terrarium.prototype.step = function (steps) {
y: y, y: y,
creature: returnedCreature creature: returnedCreature
}); });
if (!self.hasChanged && returnedCreature.observed) self.hasChanged = true; if (!self.hasChanged && result.observed) self.hasChanged = true;
} else { } else {
if (result && !self.hasChanged) self.hasChanged = true; if (result && !self.hasChanged) self.hasChanged = true;
processLoser(creature); processLoser(creature);
@ -547,6 +547,15 @@ Terrarium.prototype.stop = function () {
this.nextFrame = false; this.nextFrame = false;
}; };
/**
* Stops any currently running animation and cleans up the DOM
*/
Terrarium.prototype.destroy = function () {
var canvas = this.canvas;
this.stop();
canvas.parentNode.removeChild(canvas);
};
module.exports = Terrarium; module.exports = Terrarium;
},{"./creature.js":2,"./display.js":3,"./dom.js":4,"./util":6}],6:[function(require,module,exports){ },{"./creature.js":2,"./display.js":3,"./dom.js":4,"./util":6}],6:[function(require,module,exports){

2
dist/terra.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "terra", "name": "terra",
"version": "1.4.0-beta", "version": "1.5.0-beta",
"description": "A JavaScript library for simple biological simulations and cellular automata.", "description": "A JavaScript library for simple biological simulations and cellular automata.",
"main": "dist/terra.min.js", "main": "dist/terra.min.js",
"scripts": { "scripts": {