33 lines
972 B
JavaScript
33 lines
972 B
JavaScript
/**
|
|
* JSON import/export for Scenar Creator v3.
|
|
*/
|
|
|
|
function exportJson() {
|
|
const doc = App.getDocument();
|
|
if (!doc) {
|
|
App.toast('Žádný scénář k exportu', 'error');
|
|
return;
|
|
}
|
|
const json = JSON.stringify(doc, null, 2);
|
|
const blob = new Blob([json], { type: 'application/json' });
|
|
API.downloadBlob(blob, App.buildFilename('json'));
|
|
App.toast('JSON exportován', 'success');
|
|
}
|
|
|
|
function importJson(file) {
|
|
const reader = new FileReader();
|
|
reader.onload = function (e) {
|
|
try {
|
|
const doc = JSON.parse(e.target.result);
|
|
if (!doc.event || !doc.blocks || !doc.program_types) {
|
|
throw new Error('Neplatný formát ScenarioDocument');
|
|
}
|
|
App.loadDocument(doc);
|
|
App.toast('JSON importován', 'success');
|
|
} catch (err) {
|
|
App.toast('Chyba importu: ' + err.message, 'error');
|
|
}
|
|
};
|
|
reader.readAsText(file);
|
|
}
|