kopia lustrzana https://github.com/backface/turtlestitch
new format for exported scripts, under construction
rodzic
f10e88a25c
commit
938c01dd10
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
### 2022-03-14
|
### 2022-03-14
|
||||||
* gui, byob: refactored library serialization
|
* gui, byob: refactored library serialization
|
||||||
|
* blocks, byob, gui: new format for exported scripts, under construction
|
||||||
|
|
||||||
### 2022-03-11
|
### 2022-03-11
|
||||||
* blocks: fixed an edge case for slot type inferral
|
* blocks: fixed an edge case for slot type inferral
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<script src="src/morphic.js?version=2022-01-28"></script>
|
<script src="src/morphic.js?version=2022-01-28"></script>
|
||||||
<script src="src/symbols.js?version=2021-03-03"></script>
|
<script src="src/symbols.js?version=2021-03-03"></script>
|
||||||
<script src="src/widgets.js?version=2021-17-09"></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/threads.js?version=2022-03-03"></script>
|
||||||
<script src="src/objects.js?version=2022-03-11"></script>
|
<script src="src/objects.js?version=2022-03-11"></script>
|
||||||
<script src="src/scenes.js?version=2022-03-03"></script>
|
<script src="src/scenes.js?version=2022-03-03"></script>
|
||||||
|
|
|
@ -161,7 +161,7 @@ CostumeIconMorph, SoundIconMorph, SVG_Costume*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.blocks = '2022-March-11';
|
modules.blocks = '2022-March-14';
|
||||||
|
|
||||||
var SyntaxElementMorph;
|
var SyntaxElementMorph;
|
||||||
var BlockMorph;
|
var BlockMorph;
|
||||||
|
@ -3967,7 +3967,8 @@ BlockMorph.prototype.exportResultPic = function () {
|
||||||
|
|
||||||
// BlockMorph exporting a script
|
// BlockMorph exporting a script
|
||||||
|
|
||||||
BlockMorph.prototype.exportScript = function () {
|
/*
|
||||||
|
BlockMorph.prototype.exportScript = function () { // +++
|
||||||
var ide = this.parentThatIsA(IDE_Morph),
|
var ide = this.parentThatIsA(IDE_Morph),
|
||||||
blockEditor = this.parentThatIsA(BlockEditorMorph);
|
blockEditor = this.parentThatIsA(BlockEditorMorph);
|
||||||
if (!ide && blockEditor) {
|
if (!ide && blockEditor) {
|
||||||
|
@ -3980,6 +3981,54 @@ BlockMorph.prototype.exportScript = function () {
|
||||||
false);
|
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
|
// BlockMorph syntax analysis
|
||||||
|
|
||||||
|
|
|
@ -4315,7 +4315,7 @@ BlockExportDialogMorph.prototype.exportBlocks = function () {
|
||||||
|
|
||||||
if (this.blocks.length) {
|
if (this.blocks.length) {
|
||||||
ide.saveXMLAs(
|
ide.saveXMLAs(
|
||||||
ide.blocksLibraryXML(this.blocks),
|
ide.blocksLibraryXML(this.blocks, true), // as file
|
||||||
(ide.getProjectName() || localize('untitled')) +
|
(ide.getProjectName() || localize('untitled')) +
|
||||||
' ' +
|
' ' +
|
||||||
localize('blocks'
|
localize('blocks'
|
||||||
|
|
17
src/gui.js
17
src/gui.js
|
@ -7391,18 +7391,21 @@ IDE_Morph.prototype.getURL = function (url, callback, responseType) {
|
||||||
|
|
||||||
// IDE_Morph serialization helper ops
|
// 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
|
// answer an XML string encoding of an array of CustomBlockDefinitions
|
||||||
var globals = definitions.filter(def => def.isGlobal),
|
var globals = definitions.filter(def => def.isGlobal),
|
||||||
locals = definitions.filter(def => !def.isGlobal),
|
locals = definitions.filter(def => !def.isGlobal),
|
||||||
glbStr = globals.length ? this.serializer.serialize(globals, true) : '',
|
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="' +
|
return '<blocks' +
|
||||||
this.serializer.app +
|
(asFile ? appStr : '' ) +
|
||||||
'" version="' +
|
'>' +
|
||||||
this.serializer.version +
|
|
||||||
'">' +
|
|
||||||
this.paletteXML(definitions) +
|
this.paletteXML(definitions) +
|
||||||
(globals.length ? glbStr : '') +
|
(globals.length ? glbStr : '') +
|
||||||
(locals.length ? ('<local>' + locStr + '</local>') : '') +
|
(locals.length ? ('<local>' + locStr + '</local>') : '') +
|
||||||
|
|
Ładowanie…
Reference in New Issue