import sprites with dependencies

snap8
Jens Mönig 2022-03-17 23:31:02 +01:00
rodzic 81504862c3
commit d0b06812f1
4 zmienionych plików z 47 dodań i 11 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -30,7 +30,7 @@
<script src="src/maps.js?version=2021-06-15"></script>
<script src="src/extensions.js?version=2022-02-08"></script>
<script src="src/xml.js?version=2021-07-05"></script>
<script src="src/store.js?version=2022-03-15"></script>
<script src="src/store.js?version=2022-03-17"></script>
<script src="src/locale.js?version=2022-03-16"></script>
<script src="src/cloud.js?version=2021-02-04"></script>
<script src="src/api.js?version=2022-01-03"></script>

Wyświetl plik

@ -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) {

Wyświetl plik

@ -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;