Cleanup in progress
This commit is contained in:
45
desktop/sources/scripts/source.js
Normal file
45
desktop/sources/scripts/source.js
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict'
|
||||
|
||||
function Source (dotgrid) {
|
||||
this.new = function () {
|
||||
dotgrid.setZoom(1.0)
|
||||
dotgrid.history.push(dotgrid.tool.layers)
|
||||
dotgrid.clear()
|
||||
}
|
||||
|
||||
this.open = function () {
|
||||
if (!dialog) { return }
|
||||
|
||||
const paths = dialog.showOpenDialog({ properties: ['openFile'], filters: [{ name: 'Dotgrid Image', extensions: ['dot', 'grid'] }] })
|
||||
|
||||
if (!paths) { console.warn('Nothing to load'); return }
|
||||
|
||||
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()))
|
||||
dotgrid.renderer.update()
|
||||
})
|
||||
}
|
||||
|
||||
this.save = function () {
|
||||
if (dotgrid.tool.length() < 1) { console.warn('Nothing to save'); return }
|
||||
dotgrid.manager.toGRID(grab)
|
||||
}
|
||||
|
||||
this.export = function () {
|
||||
if (dotgrid.tool.length() < 1) { console.warn('Nothing to export'); return }
|
||||
dotgrid.manager.toSVG(grab)
|
||||
}
|
||||
|
||||
this.render = function () {
|
||||
if (dotgrid.tool.length() < 1) { console.warn('Nothing to render'); return }
|
||||
dotgrid.manager.toPNG({ width: dotgrid.tool.settings.size.width * 2, height: dotgrid.tool.settings.size.height * 2 }, grab)
|
||||
}
|
||||
|
||||
function grab (base64, name) {
|
||||
const link = document.createElement('a')
|
||||
link.setAttribute('href', base64)
|
||||
link.setAttribute('download', name)
|
||||
link.dispatchEvent(new MouseEvent(`click`, { bubbles: true, cancelable: true, view: window }))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user