diff --git a/HISTORY.md b/HISTORY.md
index 540fbc94..bd9df2ce 100755
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -6,6 +6,7 @@
* export / import sprite-local custom block definitions
* added "combinations" primitive to the palette
* **Notable Changes:**
+ * exporting / importing a sprite includes all block dependencies (global custom blocks and palette categories)
* moved "append", "reshape", "combinations" blocks down one group in the palette
* **Notable Fixes:**
* fixed an edge case for slot type inferral
@@ -19,6 +20,7 @@
* gui: refactored palette serialization for scripts
* byob, blocks, gui: refactored blocksLibraryXML()
* gui: new format for exporting sprites, under construction
+* gui: store: import sprites with dependencies
### 2022-03-16
* restored v7.4.0-dev
diff --git a/snap.html b/snap.html
index 286872b6..8128823b 100755
--- a/snap.html
+++ b/snap.html
@@ -30,7 +30,7 @@
-
+
diff --git a/src/gui.js b/src/gui.js
index 7514bb7a..0d990934 100644
--- a/src/gui.js
+++ b/src/gui.js
@@ -5808,15 +5808,41 @@ IDE_Morph.prototype.rawOpenSpritesString = function (str) {
this.spriteBar.tabBar.tabTo('scripts');
if (Process.prototype.isCatchingErrors) {
try {
- this.serializer.loadSprites(str, this);
+ this.deserializeSpritesString(str);
} catch (err) {
this.showMessage('Load failed: ' + err);
}
} else {
- this.serializer.loadSprites(str, this);
+ this.deserializeSpritesString(str);
}
};
+IDE_Morph.prototype.deserializeSpritesString = function (str) {
+ var xml = this.serializer.parse(str),
+ blocksModel = xml.childNamed('blocks'),
+ blocks;
+
+ if (blocksModel) {
+ // load the custom block definitions the sprites depend on
+ blocks = this.serializer.loadBlocksModel(blocksModel, this.stage);
+ blocks.global.forEach(def => {
+ def.receiver = this.stage;
+ this.stage.globalBlocks.push(def);
+ this.stage.replaceDoubleDefinitionsFor(def);
+ });
+ // notice, there should not be any local blocks in this part of
+ // the model instead we're expecting them inside each sprite
+ this.flushPaletteCache();
+ this.refreshPalette();
+ this.createCategories();
+ this.categories.refreshEmpty();
+ this.createPaletteHandle();
+ this.categories.fixLayout();
+ this.fixLayout();
+ }
+ this.serializer.loadSpritesModel(xml, this);
+};
+
IDE_Morph.prototype.openMediaString = function (str) {
if (Process.prototype.isCatchingErrors) {
try {
@@ -5898,7 +5924,7 @@ IDE_Morph.prototype.deserializeScriptString = function (str) {
this.categories.fixLayout();
this.fixLayout();
}
- return this.serializer.loadScriptModule(scriptModel, this.currentSprite);
+ return this.serializer.loadScriptModel(scriptModel, this.currentSprite);
};
IDE_Morph.prototype.openDataString = function (str, name, type) {
diff --git a/src/store.js b/src/store.js
index 6505abbb..55f462bc 100644
--- a/src/store.js
+++ b/src/store.js
@@ -63,7 +63,7 @@ Project*/
// Global stuff ////////////////////////////////////////////////////////
-modules.store = '2022-March-15';
+modules.store = '2022-March-17';
// XML_Serializer ///////////////////////////////////////////////////////
/*
@@ -705,16 +705,24 @@ SnapSerializer.prototype.loadBlocksModel = function (model, targetStage) {
SnapSerializer.prototype.loadSprites = function (xmlString, ide) {
// public - import a set of sprites represented by xmlString
// into the current scene of the ide
- var model, scene;
+ var model = this.parse(xmlString);
+
+ if (+model.attributes.version > this.version) {
+ throw 'Module uses newer version of Serializer';
+ }
+ this.loadSpritesModel(model, ide);
+};
+
+SnapSerializer.prototype.loadSpritesModel = function (xmlNode, ide) {
+ // public - import a set of sprites represented by an xml model
+ // into the current scene of the ide
+ var model = xmlNode,
+ scene;
this.scene = new Scene(ide.stage);
scene = this.scene;
scene.spritesDict[scene.stage.name] = scene.stage;
- model = this.parse(xmlString);
- if (+model.attributes.version > this.version) {
- throw 'Module uses newer version of Serializer';
- }
model.childrenNamed('sprite').forEach(model => {
var sprite = new SpriteMorph(scene.globalVariables);
@@ -1154,7 +1162,7 @@ SnapSerializer.prototype.loadScriptsArray = function (model, object) {
return scripts;
};
-SnapSerializer.prototype.loadScriptModule = function (model, object) {
+SnapSerializer.prototype.loadScriptModel = function (model, object) {
// return a new script represented by the given xml model,
// note: custom block definitions referenced here must be loaded before
var script;