diff --git a/sources/scripts/dotgrid.js b/sources/scripts/dotgrid.js index a27674b..9e63829 100644 --- a/sources/scripts/dotgrid.js +++ b/sources/scripts/dotgrid.js @@ -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); diff --git a/sources/scripts/tool.js b/sources/scripts/tool.js index e3ca831..909b91a 100644 --- a/sources/scripts/tool.js +++ b/sources/scripts/tool.js @@ -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)