export multi-scene projects

snap7
jmoenig 2021-04-16 12:30:45 +02:00
rodzic b65b941a39
commit a74779f39b
4 zmienionych plików z 62 dodań i 4 usunięć

Wyświetl plik

@ -11,6 +11,7 @@
### 2021-04-16
* scenes, store, gui: remember last edited sprite in a scene / project
* scenes: removed Project class
* scenes, store, gui: export multi-scene projects
### 2021-04-14
* scenes: new Project class

Wyświetl plik

@ -67,7 +67,7 @@
*/
/*global modules, Morph, SpriteMorph, SyntaxElementMorph, Color, Cloud, Audio,
ListWatcherMorph, TextMorph, newCanvas, useBlurredShadows, Sound, Scene,
ListWatcherMorph, TextMorph, newCanvas, useBlurredShadows, Sound, Scene, Note,
StringMorph, Point, MenuMorph, morphicVersion, DialogBoxMorph, normalizeCanvas,
ToggleButtonMorph, contains, ScrollFrameMorph, StageMorph, PushButtonMorph, sb,
InputFieldMorph, FrameMorph, Process, nop, SnapSerializer, ListMorph, detect,
@ -79,7 +79,7 @@ CommandBlockMorph, BooleanSlotMorph, RingReporterSlotMorph, ScriptFocusMorph,
BlockLabelPlaceHolderMorph, SpeechBubbleMorph, XML_Element, WatcherMorph, WHITE,
BlockRemovalDialogMorph,TableMorph, isSnapObject, isRetinaEnabled, SliderMorph,
disableRetinaSupport, enableRetinaSupport, isRetinaSupported, MediaRecorder,
Animation, BoxMorph, BlockEditorMorph, BlockDialogMorph, Note, ZERO, BLACK*/
Animation, BoxMorph, BlockEditorMorph, BlockDialogMorph, Project, ZERO, BLACK*/
// Global stuff ////////////////////////////////////////////////////////
@ -4710,6 +4710,11 @@ IDE_Morph.prototype.exportProject = function (name, plain) {
// newWindow requests displaying the project in a new tab.
var menu, str, dataPrefix;
if (this.scenes.length() > 1) { // +++
this.exportScenes(this.scenes.at(1).name, plain);
return;
}
if (name) {
this.setProjectName(name);
dataPrefix = 'data:text/' + plain ? 'plain,' : 'xml,';
@ -4731,6 +4736,32 @@ IDE_Morph.prototype.exportProject = function (name, plain) {
}
};
IDE_Morph.prototype.exportScenes = function (name, plain) { // +++
// experimental export of multi-scene project - under construction
var menu, str, dataPrefix;
if (name) {
this.setProjectName(name);
dataPrefix = 'data:text/' + plain ? 'plain,' : 'xml,';
try {
menu = this.showMessage('Exporting');
str = this.serializer.serialize(new Project(this.scenes));
this.setURL('#open:' + dataPrefix + encodeURIComponent(str));
this.saveXMLAs(str, name);
menu.destroy();
this.recordSavedChanges();
this.showMessage('Exported!', 1);
} catch (err) {
if (Process.prototype.isCatchingErrors) {
this.showMessage('Export failed: ' + err);
} else {
throw err;
}
}
}
};
IDE_Morph.prototype.exportGlobalBlocks = function () {
if (this.stage.globalBlocks.length > 0) {
new BlockExportDialogMorph(

Wyświetl plik

@ -34,6 +34,7 @@
the following list shows the order in which all constructors are
defined. Use this list to locate code in this document:
Project
Scene
credits
@ -51,6 +52,23 @@
modules.scenes = '2021-April-16';
// Projecct /////////////////////////////////////////////////////////
// I am a container for a set of one or more Snap! scenes,
// the IDE operates on an instance of me
// Project instance creation:
function Project(scenes) {
this.name = '';
this.notes = '';
this.scenes = scenes || new List();
// for undeleting scenes - do not persist
this.trash = [];
}
// Scene /////////////////////////////////////////////////////////
// I am a container for a Snap! stage, scene-global variables

Wyświetl plik

@ -56,7 +56,8 @@ Color, List, newCanvas, Costume, Audio, IDE_Morph, ScriptsMorph, ArgLabelMorph,
BlockMorph, ArgMorph, InputSlotMorph, TemplateSlotMorph, CommandSlotMorph,
FunctionSlotMorph, MultiArgMorph, ColorSlotMorph, nop, CommentMorph, isNil,
localize, SVG_Costume, MorphicPreferences, Process, isSnapObject, Variable,
SyntaxElementMorph, BooleanSlotMorph, normalizeCanvas, contains, Scene*/
SyntaxElementMorph, BooleanSlotMorph, normalizeCanvas, contains, Scene,
Project*/
// Global stuff ////////////////////////////////////////////////////////
@ -1622,7 +1623,14 @@ Array.prototype.toXML = function (serializer) {
);
};
// Scenes
// Scenes & multi-scene projects
Project.prototype.toXML = function (serializer) {
return serializer.format(
'<scenes>%</scenes>',
serializer.store(this.scenes.itemsArray())
);
};
Scene.prototype.toXML = function (serializer) {
var tmp = new Scene(),