Implementing source.load()
This commit is contained in:
@@ -16,10 +16,17 @@ function Source (dotgrid) {
|
||||
|
||||
fs.readFile(paths[0], 'utf-8', (err, data) => {
|
||||
if (err) { alert('An error ocurred reading the file :' + err.message); return }
|
||||
dotgrid.tool.replace(JSON.parse(data.toString().trim()))
|
||||
this.load(paths[0], data)
|
||||
})
|
||||
}
|
||||
|
||||
this.load = function (path, data) {
|
||||
if (!path || isJson(data) === false) { return }
|
||||
const parsed = JSON.parse(`${data}`)
|
||||
console.log(path)
|
||||
dotgrid.tool.replace(parsed)
|
||||
}
|
||||
|
||||
this.save = function () {
|
||||
if (dotgrid.tool.length() < 1) { console.warn('Nothing to save'); return }
|
||||
dotgrid.manager.toGRID(grab)
|
||||
@@ -41,4 +48,6 @@ function Source (dotgrid) {
|
||||
link.setAttribute('download', name)
|
||||
link.dispatchEvent(new MouseEvent(`click`, { bubbles: true, cancelable: true, view: window }))
|
||||
}
|
||||
|
||||
function isJson (text) { try { JSON.parse(text); return true } catch (error) { return false } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user