Skip to content

Commit

Permalink
Save wind and gravity and such in the snapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeto committed Jun 29, 2014
1 parent e8f35b2 commit 958e91f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions js/controller.js
Expand Up @@ -79,10 +79,10 @@ function Controller(particles) {
_this.particles.updateObstacles();
});
$('.controls .save').on('click', function() {
localStorage.obstacles = JSON.stringify(_this.save());
localStorage.snapshot = JSON.stringify(_this.save());
});
$('.controls .restore').on('click', function() {
_this.restore(JSON.parse(localStorage.obstacles));
_this.restore(JSON.parse(localStorage.snapshot));
updateCount();
});
}
Expand Down Expand Up @@ -138,6 +138,9 @@ Controller.prototype.adjust = function(factor) {
*/
Controller.prototype.save = function() {
var save = {
gravity: this.particles.gravity,
wind: this.particles.wind,
size: this.particles.size,
particles: this.particles.getCount(),
obstacles: []
};
Expand All @@ -163,6 +166,9 @@ Controller.prototype.restore = function(save) {
}
this.clear();
var ps = this.particles;
ps.size = save.size;
ps.gravity = save.gravity;
ps.wind = save.wind;
save.obstacles.forEach(function(o) {
ps.addObstacle(o.position, o.size);
});
Expand Down

0 comments on commit 958e91f

Please sign in to comment.