new format for exporting sprites, under construction

snap8
Jens Mönig 2022-03-17 19:11:24 +01:00
rodzic 6754c61453
commit 81504862c3
2 zmienionych plików z 62 dodań i 8 usunięć

Wyświetl plik

@ -18,6 +18,7 @@
* blocks: refactored dependencies scan for scripts
* gui: refactored palette serialization for scripts
* byob, blocks, gui: refactored blocksLibraryXML()
* gui: new format for exporting sprites, under construction
### 2022-03-16
* restored v7.4.0-dev

Wyświetl plik

@ -5259,14 +5259,67 @@ IDE_Morph.prototype.removeUnusedBlocks = function () {
};
IDE_Morph.prototype.exportSprite = function (sprite) {
var str = this.serializer.serialize(sprite.allParts());
str = '<sprites app="'
+ this.serializer.app
+ '" version="'
+ this.serializer.version
+ '">'
+ str
+ '</sprites>';
var all = sprite.allParts(),
dependencies = [],
categories = [],
blocksXML = '',
str;
function collect(item, array) {
// only once
if (!contains(array, item)) {
array.push(item);
}
}
function collectAll(items, array) {
items.forEach(item => collect(item, array));
}
// collect all dependencies and custom categories.
// only collect global custom block dependencies, because the locals
// will be included in each sprite's serialization code
all.forEach(sprite => {
// global block definition in scripts
sprite.scripts.children.filter(
morph => morph instanceof BlockMorph
).forEach(script =>
collectAll(
script.dependencies(true),
dependencies
)
);
// global block definitions referenced in local block definitions
sprite.customBlocks.forEach(def => {
collect(def.category, categories);
collectAll(
def.collectDependencies([], [], sprite)
.filter(each => each.isGlobal),
dependencies
);
});
});
// encode both parts of the export-file:
// the blocks library and the sprites
if (dependencies.length || categories.length) {
blocksXML = this.blocksLibraryXML(dependencies, categories);
}
str = '<sprites app="' +
this.serializer.app +
'" version="' +
this.serializer.version +
'">' +
blocksXML +
this.serializer.serialize(sprite.allParts()) +
'</sprites>';
this.saveXMLAs(str, sprite.name);
};