Implemented write
This commit is contained in:
parent
f72547b634
commit
7dbed87827
@ -1,10 +1,13 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
function Source (dotgrid) {
|
function Source (dotgrid) {
|
||||||
|
this.path = null
|
||||||
|
|
||||||
this.new = function () {
|
this.new = function () {
|
||||||
dotgrid.setZoom(1.0)
|
dotgrid.setZoom(1.0)
|
||||||
dotgrid.history.push(dotgrid.tool.layers)
|
dotgrid.history.push(dotgrid.tool.layers)
|
||||||
dotgrid.clear()
|
dotgrid.clear()
|
||||||
|
this.path = null
|
||||||
}
|
}
|
||||||
|
|
||||||
this.open = function () {
|
this.open = function () {
|
||||||
@ -23,13 +26,29 @@ function Source (dotgrid) {
|
|||||||
this.load = function (path, data) {
|
this.load = function (path, data) {
|
||||||
if (!path || isJson(data) === false) { return }
|
if (!path || isJson(data) === false) { return }
|
||||||
const parsed = JSON.parse(`${data}`)
|
const parsed = JSON.parse(`${data}`)
|
||||||
console.log(path)
|
|
||||||
dotgrid.tool.replace(parsed)
|
dotgrid.tool.replace(parsed)
|
||||||
|
this.path = path
|
||||||
}
|
}
|
||||||
|
|
||||||
this.save = function () {
|
this.save = function () {
|
||||||
if (dotgrid.tool.length() < 1) { console.warn('Nothing to save'); return }
|
if (dotgrid.tool.length() < 1) { console.warn('Nothing to save'); return }
|
||||||
dotgrid.manager.toGRID(grab)
|
|
||||||
|
if (this.canWrite() === true) {
|
||||||
|
this.write(this.path, dotgrid.tool.export())
|
||||||
|
} else {
|
||||||
|
dotgrid.manager.toGRID(grab)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.canWrite = function () {
|
||||||
|
return fs && fs.existsSync(this.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.write = function (path, data) {
|
||||||
|
console.log('Source', 'Writing ' + path)
|
||||||
|
fs.writeFile(path, data, (err) => {
|
||||||
|
if (err) { alert('An error ocurred updating the file' + err.message); console.warn(err) }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.export = function () {
|
this.export = function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user