diff options
| author | jmoenig <jens@moenig.org> | 2013-07-04 15:31:05 +0200 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2013-07-04 15:31:05 +0200 |
| commit | b59f7f3e274688a4c70df6e9a16f02d88005a381 (patch) | |
| tree | 4166e0d642e4c5bcaefafa90ae63a32c3ed8e307 /store.js | |
| parent | 8e0f60fdd68a145d7f2acc5d350d5214c844fd54 (diff) | |
| download | snap-byow-b59f7f3e274688a4c70df6e9a16f02d88005a381.tar.gz snap-byow-b59f7f3e274688a4c70df6e9a16f02d88005a381.zip | |
Codification (blocks to text) support complete
text code mapping and block header support, both via GUI and
primitives, for built-in blocks and for custom ones.
Diffstat (limited to 'store.js')
| -rw-r--r-- | store.js | 38 |
1 files changed, 29 insertions, 9 deletions
@@ -61,7 +61,7 @@ SyntaxElementMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.store = '2013-June-19'; +modules.store = '2013-July-04'; // XML_Serializer /////////////////////////////////////////////////////// @@ -378,6 +378,8 @@ SnapSerializer.prototype.loadProjectModel = function (xmlNode) { project.stage.setExtent(StageMorph.prototype.dimensions); project.stage.isThreadSafe = model.stage.attributes.threadsafe === 'true'; + StageMorph.prototype.enableCodeMapping = + model.stage.attributes.codify === 'true'; model.hiddenPrimitives = model.project.childNamed('hidden'); if (model.hiddenPrimitives) { @@ -390,6 +392,13 @@ SnapSerializer.prototype.loadProjectModel = function (xmlNode) { ); } + model.codeHeaders = model.project.childNamed('headers'); + if (model.codeHeaders) { + model.codeHeaders.children.forEach(function (xml) { + StageMorph.prototype.codeHeaders[xml.tag] = xml.contents; + }); + } + model.codeMappings = model.project.childNamed('code'); if (model.codeMappings) { model.codeMappings.children.forEach(function (xml) { @@ -672,7 +681,7 @@ SnapSerializer.prototype.loadCustomBlocks = function ( // private var myself = this; element.children.forEach(function (child) { - var definition, names, inputs, code, comment, i; + var definition, names, inputs, header, code, comment, i; if (child.tag !== 'block-definition') { return; } @@ -711,6 +720,11 @@ SnapSerializer.prototype.loadCustomBlocks = function ( }); } + header = child.childNamed('header'); + if (header) { + definition.codeHeader = header.contents; + } + code = child.childNamed('code'); if (code) { definition.codeMapping = code.contents; @@ -1266,20 +1280,20 @@ StageMorph.prototype.toXML = function (serializer) { thumbdata = null; } - function codeMappings() { - var code = ''; - Object.keys(StageMorph.prototype.codeMappings).forEach( + function code(key) { + var str = ''; + Object.keys(StageMorph.prototype[key]).forEach( function (selector) { - code += ( + str += ( '<' + selector + '>' + XML_Element.prototype.escape( - StageMorph.prototype.codeMappings[selector] + StageMorph.prototype[key][selector] ) + '</' + selector + '>' ); } ); - return code; + return str; } this.removeAllClones(); @@ -1288,6 +1302,7 @@ StageMorph.prototype.toXML = function (serializer) { '<notes>$</notes>' + '<thumbnail>$</thumbnail>' + '<stage name="@" costume="@" tempo="@" threadsafe="@" ' + + 'codify="@" ' + 'scheduled="@" ~>' + '<pentrails>$</pentrails>' + '<costumes>%</costumes>' + @@ -1297,6 +1312,7 @@ StageMorph.prototype.toXML = function (serializer) { '<scripts>%</scripts><sprites>%</sprites>' + '</stage>' + '<hidden>$</hidden>' + + '<headers>%</headers>' + '<code>%</code>' + '<blocks>%</blocks>' + '<variables>%</variables>' + @@ -1310,6 +1326,7 @@ StageMorph.prototype.toXML = function (serializer) { this.getCostumeIdx(), this.getTempo(), this.isThreadSafe, + this.enableCodeMapping, StageMorph.prototype.frameRate !== 0, this.trailsCanvas.toDataURL('image/png'), serializer.store(this.costumes, this.name + '_cst'), @@ -1322,7 +1339,8 @@ StageMorph.prototype.toXML = function (serializer) { function (a, b) {return a + ' ' + b; }, '' ), - codeMappings(), + code('codeHeaders'), + code('codeMappings'), serializer.store(this.globalBlocks), (ide && ide.globalVariables) ? serializer.store(ide.globalVariables) : '' @@ -1587,6 +1605,7 @@ CustomBlockDefinition.prototype.toXML = function (serializer) { return serializer.format( '<block-definition s="@" type="@" category="@">' + '%' + + '<header>@</header>' + '<code>@</code>' + '<inputs>%</inputs>%%' + '</block-definition>', @@ -1594,6 +1613,7 @@ CustomBlockDefinition.prototype.toXML = function (serializer) { this.type, this.category || 'other', this.comment ? this.comment.toXML(serializer) : '', + this.codeHeader || '', this.codeMapping || '', Object.keys(this.declarations).reduce(function (xml, decl) { return xml + serializer.format( |
