new format for exported scripts, under construction

snap8
Jens Mönig 2022-03-14 19:29:25 +01:00
rodzic f10e88a25c
commit 938c01dd10
5 zmienionych plików z 64 dodań i 11 usunięć

Wyświetl plik

@ -15,6 +15,7 @@
### 2022-03-14
* gui, byob: refactored library serialization
* blocks, byob, gui: new format for exported scripts, under construction
### 2022-03-11
* blocks: fixed an edge case for slot type inferral

Wyświetl plik

@ -16,7 +16,7 @@
<script src="src/morphic.js?version=2022-01-28"></script>
<script src="src/symbols.js?version=2021-03-03"></script>
<script src="src/widgets.js?version=2021-17-09"></script>
<script src="src/blocks.js?version=2022-03-11"></script>
<script src="src/blocks.js?version=2022-03-14"></script>
<script src="src/threads.js?version=2022-03-03"></script>
<script src="src/objects.js?version=2022-03-11"></script>
<script src="src/scenes.js?version=2022-03-03"></script>

Wyświetl plik

@ -161,7 +161,7 @@ CostumeIconMorph, SoundIconMorph, SVG_Costume*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2022-March-11';
modules.blocks = '2022-March-14';
var SyntaxElementMorph;
var BlockMorph;
@ -3967,7 +3967,8 @@ BlockMorph.prototype.exportResultPic = function () {
// BlockMorph exporting a script
BlockMorph.prototype.exportScript = function () {
/*
BlockMorph.prototype.exportScript = function () { // +++
var ide = this.parentThatIsA(IDE_Morph),
blockEditor = this.parentThatIsA(BlockEditorMorph);
if (!ide && blockEditor) {
@ -3980,6 +3981,54 @@ BlockMorph.prototype.exportScript = function () {
false);
}
};
*/
BlockMorph.prototype.exportScript = function () { // +++
// assumes this is the script's top block
var ide = this.parentThatIsA(IDE_Morph),
blockEditor = this.parentThatIsA(BlockEditorMorph),
rcvr = this.scriptTarget(),
dependencies = [],
str;
if (!ide && blockEditor) {
ide = blockEditor.target.parentThatIsA(IDE_Morph);
}
if (!ide) {
return;
}
// collect custom block definitions referenced in this script:
this.forAllChildren(morph => {
var def;
if (morph.isCustomBlock) {
def = morph.isGlobal ? morph.definition
: rcvr.getMethod(morph.semanticSpec);
[def].concat(def.collectDependencies([], [], rcvr)).forEach(
fun => {
if (!contains(dependencies, fun)) {
dependencies.push(fun);
}
}
);
}
});
str = '<stack app="' +
ide.serializer.app +
'" version="' +
ide.serializer.version +
'">' +
(dependencies.length ? ide.blocksLibraryXML(dependencies, false) : '') +
ide.serializer.serialize(this) +
'</stack>';
ide.saveXMLAs(
str,
this.selector + ' script',
false
);
};
// BlockMorph syntax analysis

Wyświetl plik

@ -4315,7 +4315,7 @@ BlockExportDialogMorph.prototype.exportBlocks = function () {
if (this.blocks.length) {
ide.saveXMLAs(
ide.blocksLibraryXML(this.blocks),
ide.blocksLibraryXML(this.blocks, true), // as file
(ide.getProjectName() || localize('untitled')) +
' ' +
localize('blocks'

Wyświetl plik

@ -7391,18 +7391,21 @@ IDE_Morph.prototype.getURL = function (url, callback, responseType) {
// IDE_Morph serialization helper ops
IDE_Morph.prototype.blocksLibraryXML = function (definitions) {
IDE_Morph.prototype.blocksLibraryXML = function (definitions, asFile) {
// answer an XML string encoding of an array of CustomBlockDefinitions
var globals = definitions.filter(def => def.isGlobal),
locals = definitions.filter(def => !def.isGlobal),
glbStr = globals.length ? this.serializer.serialize(globals, true) : '',
locStr = locals.length ? this.serializer.serialize(locals, true) : '';
locStr = locals.length ? this.serializer.serialize(locals, true) : '',
appStr = ' app="' +
this.serializer.app +
'" version="' +
this.serializer.version +
'"';
return '<blocks app="' +
this.serializer.app +
'" version="' +
this.serializer.version +
'">' +
return '<blocks' +
(asFile ? appStr : '' ) +
'>' +
this.paletteXML(definitions) +
(globals.length ? glbStr : '') +
(locals.length ? ('<local>' + locStr + '</local>') : '') +