diff options
Diffstat (limited to 'store.js')
| -rw-r--r-- | store.js | 123 |
1 files changed, 79 insertions, 44 deletions
@@ -7,7 +7,7 @@ written by Jens Mönig jens@moenig.org - Copyright (C) 2014 by Jens Mönig + Copyright (C) 2015 by Jens Mönig This file is part of Snap!. @@ -61,7 +61,7 @@ SyntaxElementMorph, Variable*/ // Global stuff //////////////////////////////////////////////////////// -modules.store = '2014-November-24'; +modules.store = '2015-June-25'; // XML_Serializer /////////////////////////////////////////////////////// @@ -267,7 +267,8 @@ SnapSerializer.prototype.watcherLabels = { getTimer: 'timer', getCostumeIdx: 'costume #', reportMouseX: 'mouse x', - reportMouseY: 'mouse y' + reportMouseY: 'mouse y', + reportThreadCount: 'processes' }; // SnapSerializer instance creation: @@ -305,16 +306,33 @@ XML_Serializer.prototype.mediaXML = function (name) { return xml + '</media>'; }; - // SnapSerializer loading: -SnapSerializer.prototype.load = function (xmlString) { +SnapSerializer.prototype.load = function (xmlString, ide) { // public - answer a new Project represented by the given XML String - return this.loadProjectModel(this.parse(xmlString)); + return this.loadProjectModel(this.parse(xmlString), ide); }; -SnapSerializer.prototype.loadProjectModel = function (xmlNode) { +SnapSerializer.prototype.loadProjectModel = function (xmlNode, ide) { // public - answer a new Project represented by the given XML top node + // show a warning if the origin apps differ + + var appInfo = xmlNode.attributes.app, + app = appInfo ? appInfo.split(' ')[0] : null; + + if (ide && app && app !== this.app.split(' ')[0]) { + ide.inform( + app + ' Project', + 'This project has been created by a different app:\n\n' + + app + + '\n\nand may be incompatible or fail to load here.' + ); + } + return this.rawLoadProjectModel(xmlNode); +}; + +SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { + // private var myself = this, project = {sprites: {}}, model, @@ -473,7 +491,7 @@ SnapSerializer.prototype.loadProjectModel = function (xmlNode) { /* Watchers */ model.sprites.childrenNamed('watcher').forEach(function (model) { - var watcher, color, target, hidden, extX, extY; + var watcher, color, target, hidden, extX, extY, vFrame; color = myself.loadColor(model.attributes.color); target = Object.prototype.hasOwnProperty.call( @@ -494,14 +512,20 @@ SnapSerializer.prototype.loadProjectModel = function (xmlNode) { model.attributes, 'var' )) { - watcher = new WatcherMorph( - model.attributes['var'], - color, - isNil(target) ? project.globalVariables - : target.variables, - model.attributes['var'], - hidden - ); + vFrame = isNil(target) ? project.globalVariables + : target.variables; + if (Object.prototype.hasOwnProperty.call( + vFrame.vars, + model.attributes['var'] + )) { + watcher = new WatcherMorph( + model.attributes['var'], + color, + vFrame, + model.attributes['var'], + hidden + ); + } } else { watcher = new WatcherMorph( localize(myself.watcherLabels[model.attributes.s]), @@ -511,33 +535,35 @@ SnapSerializer.prototype.loadProjectModel = function (xmlNode) { hidden ); } - watcher.setStyle(model.attributes.style || 'normal'); - if (watcher.style === 'slider') { - watcher.setSliderMin(model.attributes.min || '1'); - watcher.setSliderMax(model.attributes.max || '100'); - } - watcher.setPosition( - project.stage.topLeft().add(new Point( - +model.attributes.x || 0, - +model.attributes.y || 0 - )) - ); - project.stage.add(watcher); - watcher.onNextStep = function () {this.currentValue = null; }; - - // set watcher's contentsMorph's extent if it is showing a list and - // its monitor dimensions are given - if (watcher.currentValue instanceof List) { - extX = model.attributes.extX; - if (extX) { - watcher.cellMorph.contentsMorph.setWidth(+extX); + if (watcher) { + watcher.setStyle(model.attributes.style || 'normal'); + if (watcher.style === 'slider') { + watcher.setSliderMin(model.attributes.min || '1'); + watcher.setSliderMax(model.attributes.max || '100'); } - extY = model.attributes.extY; - if (extY) { - watcher.cellMorph.contentsMorph.setHeight(+extY); + watcher.setPosition( + project.stage.topLeft().add(new Point( + +model.attributes.x || 0, + +model.attributes.y || 0 + )) + ); + project.stage.add(watcher); + watcher.onNextStep = function () {this.currentValue = null; }; + + // set watcher's contentsMorph's extent if it is showing a list + // and if its monitor dimensions are given + if (watcher.currentValue instanceof List) { + extX = model.attributes.extX; + if (extX) { + watcher.cellMorph.contentsMorph.setWidth(+extX); + } + extY = model.attributes.extY; + if (extY) { + watcher.cellMorph.contentsMorph.setHeight(+extY); + } + // adjust my contentsMorph's handle position + watcher.cellMorph.contentsMorph.handle.drawNew(); } - // adjust my contentsMorph's handle position - watcher.cellMorph.contentsMorph.handle.drawNew(); } }); this.objects = {}; @@ -764,7 +790,7 @@ SnapSerializer.prototype.loadCustomBlocks = function ( names = definition.parseSpec(definition.spec).filter( function (str) { - return str.charAt(0) === '%'; + return str.charAt(0) === '%' && str.length > 1; } ).map(function (str) { return str.substr(1); @@ -843,7 +869,7 @@ SnapSerializer.prototype.loadScripts = function (scripts, model) { // private var myself = this, scale = SyntaxElementMorph.prototype.scale; - scripts.texture = 'scriptsPaneTexture.gif'; + scripts.cachedTexture = IDE_Morph.prototype.scriptsPaneTexture; model.children.forEach(function (child) { var element; if (child.tag === 'script') { @@ -959,7 +985,11 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter) { ); } if (!receiver) { - return this.obsoleteBlock(isReporter); + if (!isGlobal) { + receiver = this.project.stage; + } else { + return this.obsoleteBlock(isReporter); + } } if (isGlobal) { info = detect(receiver.globalBlocks, function (block) { @@ -1005,6 +1035,7 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter) { this.loadInput(child, inputs[i], block); } }, this); + block.cachedInputs = null; return block; }; @@ -1201,6 +1232,10 @@ SnapSerializer.prototype.loadValue = function (model) { if (el) { v.outerContext = this.loadValue(el); } + if (v.outerContext && v.receiver && + !v.outerContext.variables.parentFrame) { + v.outerContext.variables.parentFrame = v.receiver.variables; + } return v; case 'costume': center = new Point(); |
