Constellations/js/Grid/IO.js

36 lines
714 B
JavaScript
Raw Normal View History

import * as File from WTK.File;
import * as Async from UnitJS.Async;
import Grid;
import Grid.Color;
import Mode;
return {
init: init
}
function init() {
document.getElementById('load').addEventListener('click', load);
document.getElementById('save').addEventListener('click', save);
}
function load() {
Async.run(
Async.bind(
File.pick({accept: 'text/json,.json'}),
function(input) {
2022-07-31 16:34:49 +02:00
Grid.clear();
Mode.setEnabled(false, ['play', 'solve']);
return File.load(input.files[0]);
},
function(data) {
2022-08-10 21:12:39 +02:00
Grid.Color.setColors(JSON.parse(data));
return Async.wrap();
}
)
);
}
function save() {
File.save('data:text/json,' + JSON.stringify(Grid.get().colors), "grid.json");
}