Fixed issue with import

This commit is contained in:
Devine Lu Linvega 2018-02-08 09:34:17 +13:00
parent 7858abeca6
commit efd80ae869
2 changed files with 12 additions and 2 deletions

View File

@ -212,7 +212,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
fs.readFile(paths[0], 'utf-8', (err, data) => {
if(err){ alert("An error ocurred reading the file :" + err.message); return; }
dotgrid.tool.import(JSON.parse(data.toString().trim()));
dotgrid.tool.replace(JSON.parse(data.toString().trim()));
dotgrid.draw();
});
}
@ -468,7 +468,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
var reader = new FileReader();
reader.onload = function(e){
dotgrid.tool.import(JSON.parse(e.target.result.toString().trim()));
dotgrid.tool.replace(JSON.parse(e.target.result.toString().trim()));
dotgrid.draw();
};
reader.readAsText(file);

View File

@ -175,6 +175,16 @@ function Tool()
return JSON.stringify(copy(target), null, 2);
}
this.replace = function(layers)
{
if(layers.length != 3){ console.log("Incompatible"); return; }
this.layers = layers;
this.clear();
dotgrid.draw();
dotgrid.history.push(this.layers);
}
this.import = function(layer)
{
this.layers[this.index] = this.layers[this.index].concat(layer)