Improved new file/history

This commit is contained in:
Devine Lu Linvega 2018-02-05 10:09:46 +13:00
parent a440752f73
commit e98978249c
2 changed files with 9 additions and 4 deletions

View File

@ -193,9 +193,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.new = function() this.new = function()
{ {
dotgrid.segments = []; dotgrid.clear();
dotgrid.history.push(dotgrid.segments)
dotgrid.draw();
} }
this.save = function() this.save = function()
@ -663,6 +661,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.clear = function() this.clear = function()
{ {
this.history.clear();
this.reset(); this.reset();
this.segments = []; this.segments = [];
this.thickness = 10 this.thickness = 10

View File

@ -3,6 +3,12 @@ function History()
this.index = 0; this.index = 0;
this.a = []; this.a = [];
this.clear = function()
{
this.a = [];
this.index = 0;
}
this.push = function(data) this.push = function(data)
{ {
if(this.index < this.a.length-1){ if(this.index < this.a.length-1){
@ -35,6 +41,6 @@ function History()
return copy(this.a[this.index]); return copy(this.a[this.index]);
} }
function copy(data){ return data.slice(0); } function copy(data){ return data ? data.slice(0) : []; }
function clamp(v, min, max) { return v < min ? min : v > max ? max : v; } function clamp(v, min, max) { return v < min ? min : v > max ? max : v; }
} }