From 1585a1664a9bbdb7c8efa5f3da361b4aaf6450e4 Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 1 Mar 2015 09:51:26 +0100 Subject: remove language and location blocks --- threads.js | 72 -------------------------------------------------------------- 1 file changed, 72 deletions(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 06454e3..7587f06 100644 --- a/threads.js +++ b/threads.js @@ -2669,78 +2669,6 @@ Process.prototype.reportTimer = function () { return 0; }; -Process.prototype.reportLanguage = function () { - var ide = this.homeContext.receiver.parentThatIsA(IDE_Morph); - if (ide) { - var lang = ide.userLanguage; - if (lang) { - return lang; - } - } - return 'en'; -}; - -Process.prototype.reportLocation = function (name) { - var myself = this; - - if (!myself.context.jsonpScript) { - if (!navigator.geolocation) { - myself.handleError({name: 'Location', - message: 'navigator.geolocation is not supported'}); - } - window.OSM_JSONP_Callback = function (data) { - myself.context.json = data; - window.OSM_JSONP_Callback = undefined; - }; - myself.context.jsonpScript = document.createElement('script'); - - navigator.geolocation.getCurrentPosition( - function (pos) { - var crd = pos.coords; - - myself.context.jsonpScript.src = - 'https://nominatim.openstreetmap.org/reverse' - + '?format=json&json_callback=OSM_JSONP_Callback' - + '&zoom=18&addressdetails=1' - + '&lat=' - + crd.latitude - + '&lon=' - + crd.longitude; - document.getElementsByTagName('HEAD')[0] - .appendChild(myself.context.jsonpScript); - }, - function (err) { - console.log(err); - myself.handleError({name: 'Location', message: err}); - }, - { enableHightAccuracy: true, timeout: 30000, maximumAge: 0} - ); - } else { - if (myself.context.json) { - switch (myself.inputOption(name)) { - case 'all': - return myself.context.json.display_name; - case 'state district': - return myself.context.json.address.state_district; - case 'house number': - return myself.context.json.address.house_number; - case 'licence': - return myself.context.json.licence; - case 'country': - case 'state': - case 'suburb': - case 'city': - case 'road': - return myself.context. - json.address[myself.inputOption(name)]; - } - } - } - - this.pushContext('doYield'); - this.pushContext(); -}; - // Process Dates and times in Snap // Map block options to built-in functions var dateMap = { -- cgit v1.3.1 From 692486e3778a0b678151a671d4aa999e0536859f Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 8 Mar 2015 15:04:58 +0100 Subject: speed up connections to self --- threads.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 2d1ce77..165c7fc 100644 --- a/threads.js +++ b/threads.js @@ -1299,16 +1299,22 @@ Process.prototype.doRemoveTemporaries = function () { Process.prototype.sendPeerMessage = function (message, peer) { var myself = this; + var stage = this.homeContext.receiver.parentThatIsA(StageMorph), + ide = this.homeContext.receiver.parentThatIsA(IDE_Morph); + console.log(peer, stage.peerId); if (peer instanceof List) { peer.asArray().forEach(function (singlePeer) { myself.sendPeerMessage(message, singlePeer); }); return; } + if (peer == stage.peerId) { + console.log('hello self!'); + stage.newPeerMessage(message, peer); + return; + } - var stage = this.homeContext.receiver.parentThatIsA(StageMorph), - ide = this.homeContext.receiver.parentThatIsA(IDE_Morph); var connection = stage.peer.connect(peer, {reliable: true}); connection.on('open', function () { var data; -- cgit v1.3.1 From 916dfe65e4afe636ce42e178fe88815b4b86026d Mon Sep 17 00:00:00 2001 From: Gubolin Date: Sun, 8 Mar 2015 16:13:29 +0100 Subject: another attempt to fix disconnect issues --- objects.js | 13 ++++--------- threads.js | 6 ++---- 2 files changed, 6 insertions(+), 13 deletions(-) (limited to 'threads.js') diff --git a/objects.js b/objects.js index 3a39a5c..b115b3b 100644 --- a/objects.js +++ b/objects.js @@ -4426,11 +4426,9 @@ StageMorph.prototype.init = function (globals) { StageMorph.prototype.initPeering = function (id) { var myself = this; - if (window.peers) { + if (window.peer) { // I don't know why, but it works. - while (window.peers.length > 0) { - window.peers.pop().destroy(); - } + window.peer.destroy(); } this.peer = new Peer(id, { @@ -4440,13 +4438,10 @@ StageMorph.prototype.initPeering = function (id) { path: '/' }); - this.peer.on('open', function (id) { - myself.peerId = id; - }); this.peer.on('disconnected', function () { // peer.reconnect does not work (?) because 'id' is undefined if (!myself.peer.destroyed) { - myself.initPeering(myself.peerId); + myself.initPeering(myself.peer.id); } }); this.peer.on('error', function (err) { @@ -4461,7 +4456,7 @@ StageMorph.prototype.initPeering = function (id) { }); }); - window.peers.push(this.peer); + window.peer = this.peer; }; StageMorph.prototype.newPeerMessage = function (data, peer) { diff --git a/threads.js b/threads.js index 165c7fc..d8ec04f 100644 --- a/threads.js +++ b/threads.js @@ -1302,15 +1302,13 @@ Process.prototype.sendPeerMessage = function (message, peer) { var stage = this.homeContext.receiver.parentThatIsA(StageMorph), ide = this.homeContext.receiver.parentThatIsA(IDE_Morph); - console.log(peer, stage.peerId); if (peer instanceof List) { peer.asArray().forEach(function (singlePeer) { myself.sendPeerMessage(message, singlePeer); }); return; } - if (peer == stage.peerId) { - console.log('hello self!'); + if (peer == stage.peer.id) { stage.newPeerMessage(message, peer); return; } @@ -1348,7 +1346,7 @@ Process.prototype.reportPeerList = function () { Process.prototype.reportPeerId = function () { var stage = this.homeContext.receiver.parentThatIsA(StageMorph); - return stage.peerId; + return stage.peer.id; }; // Process lists primitives -- cgit v1.3.1 From 121cf8b3658909f79571b621e9a9916c7f601dfc Mon Sep 17 00:00:00 2001 From: Gubolin Date: Fri, 20 Mar 2015 20:53:20 +0100 Subject: create one peer per IDE --- gui.js | 31 ++++++++++++++++++++++++++++++- objects.js | 33 +-------------------------------- threads.js | 14 +++++++------- 3 files changed, 38 insertions(+), 40 deletions(-) (limited to 'threads.js') diff --git a/gui.js b/gui.js index 1f51405..543f776 100644 --- a/gui.js +++ b/gui.js @@ -246,7 +246,36 @@ IDE_Morph.prototype.init = function (isAutoFill) { // override inherited properites: this.color = this.backgroundColor; - window.peers = []; + this.createPeer(); +}; + +IDE_Morph.prototype.createPeer = function() { + var myself = this; + this.peer = new Peer(this.peerId, { + host: 'snapmesh.herokuapp.com', + port: 443, + secure: true, + path: '/' + }); + + this.peer.on('open', function (id) { + myself.peerId = id; + }); + this.peer.on('disconnected', function () { + myself.peer.destroy(); + myself.createPeer(); + }); + this.peer.on('error', function (err) { + console.log(err); // DEBUG + }); + + this.peer.on('connection', function (connection) { + connection.on('open', function () { + connection.on('data', function (data) { + myself.stage.newPeerMessage(data, connection.peer); + }); + }); + }); }; IDE_Morph.prototype.openIn = function (world) { diff --git a/objects.js b/objects.js index e25f119..3859295 100644 --- a/objects.js +++ b/objects.js @@ -4419,42 +4419,11 @@ StageMorph.prototype.init = function (globals) { this.acceptsDrops = false; this.setColor(new Color(255, 255, 255)); this.fps = this.frameRate; - - this.initPeering(); -}; - -StageMorph.prototype.initPeering = function (id) { - var myself = this; - - this.peer = new Peer(id, { - host: 'snapmesh.herokuapp.com', - port: 443, - secure: true, - path: '/' - }); - - this.peer.on('disconnected', function () { - if (!myself.peer.destroyed && myself.peer.id) { - myself.peer.reconnect(); - } else { - myself.initPeering(); - } - }); - this.peer.on('error', function (err) { - console.log(err); // DEBUG - }); - - this.peer.on('connection', function (connection) { - connection.on('open', function () { - connection.on('data', function (data) { - myself.newPeerMessage(data, connection.peer); - }); - }); - }); }; StageMorph.prototype.newPeerMessage = function (data, peer) { var ide = this.parentThatIsA(IDE_Morph); + if (!ide || !peer) return; var myself = this; var hats = [], model, message; diff --git a/threads.js b/threads.js index d8ec04f..573b7fe 100644 --- a/threads.js +++ b/threads.js @@ -1308,12 +1308,12 @@ Process.prototype.sendPeerMessage = function (message, peer) { }); return; } - if (peer == stage.peer.id) { + if (peer == ide.peer.id) { stage.newPeerMessage(message, peer); return; } - var connection = stage.peer.connect(peer, {reliable: true}); + var connection = ide.peer.connect(peer, {reliable: true}); connection.on('open', function () { var data; if (typeof message == "string") { @@ -1331,11 +1331,11 @@ Process.prototype.reportPeerList = function () { var myself = this; if (!this.context.wait) { - var stage = this.homeContext.receiver.parentThatIsA(StageMorph); - stage.peer.listAllPeers(function (peers) { + this.context.wait = true; + var ide = this.homeContext.receiver.parentThatIsA(IDE_Morph); + ide.peer.listAllPeers(function (peers) { myself.context.result = new List(peers); }); - this.context.wait = true; } else if (this.context.result) { return this.context.result; } @@ -1345,8 +1345,8 @@ Process.prototype.reportPeerList = function () { }; Process.prototype.reportPeerId = function () { - var stage = this.homeContext.receiver.parentThatIsA(StageMorph); - return stage.peer.id; + var ide = this.homeContext.receiver.parentThatIsA(IDE_Morph); + return ide.peer.id; }; // Process lists primitives -- cgit v1.3.1 From 4acf1896bd9fa57d3dbe3f4721b6790c6f3b0d56 Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Sat, 21 Mar 2015 11:12:43 +0100 Subject: Prototypal inheritance of sprite-local variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (experimental) slotwise inheritance à la Henry Lieberman for sprite-local variables. see http://web.media.mit.edu/~lieber/Lieberary/OOP/Delegation/Delegation.htm l Let a sprite inherit another sprite’s local variables by making it the “parent” in the sprite-icon’s context menu (the button icon in the sprite corral underneath the stage). The child not only inherits the variable slot but also - dynamically - the parent variable’s value. Changing the parent’s variable value also changes it for every child. If a child uses SET or CHANGE on an inherited variable it automatically “shadows” it with its own value, thereby stopping dynamic participation in the parent slot’s value (in effect dis-inheriting that slot). Deleting a shadowed variable slot once again reinstates its inheritance status. inherited variables are shown as “ghosted” both in the child’s variables palette and in such stage watchers. “Shadowing” them un-ghosts both the variable blob template in the palette and the watcher onstage (if any). Deleting a shadowed variable once again ghosts the watcher and the palette block template. Delete a (shadowed) variable either via the “Delete a variable” button in the IDE or using the new “Delete” block in the variables category --- blocks.js | 12 +++- gui.js | 18 ++++-- history.txt | 4 ++ morphic.js | 27 +++++--- objects.js | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----- snap.html | 2 +- store.js | 45 +++++++++++-- threads.js | 73 ++++++++++++++------- widgets.js | 11 ++-- 9 files changed, 335 insertions(+), 63 deletions(-) (limited to 'threads.js') diff --git a/blocks.js b/blocks.js index aef09da..711976f 100644 --- a/blocks.js +++ b/blocks.js @@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2015-March-09'; +modules.blocks = '2015-March-21'; var SyntaxElementMorph; @@ -3016,6 +3016,12 @@ BlockMorph.prototype.alternateBlockColor = function () { this.fixChildrensBlockColor(true); // has issues if not forced }; +BlockMorph.prototype.ghost = function () { + this.setColor( + SpriteMorph.prototype.blockColor[this.category].lighter(35) + ); +}; + BlockMorph.prototype.fixLabelColor = function () { if (this.zebraContrast > 0 && this.category) { var clr = SpriteMorph.prototype.blockColor[this.category]; @@ -3096,6 +3102,10 @@ BlockMorph.prototype.mouseClickLeft = function () { } }; +BlockMorph.prototype.reactToTemplateCopy = function () { + this.forceNormalColoring(); +}; + // BlockMorph thumbnail BlockMorph.prototype.thumbnail = function (scale, clipWidth, noShadow) { diff --git a/gui.js b/gui.js index 50f3cb2..4cd2a9b 100644 --- a/gui.js +++ b/gui.js @@ -69,7 +69,7 @@ SpeechBubbleMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2015-March-15'; +modules.gui = '2015-March-21'; // Declarations @@ -2598,7 +2598,7 @@ IDE_Morph.prototype.aboutSnap = function () { module, btn1, btn2, btn3, btn4, licenseBtn, translatorsBtn, world = this.world(); - aboutTxt = 'Snap! 4.0\nBuild Your Own Blocks\n\n--- rc ---\n\n' + aboutTxt = 'Snap! 4.1 (OOP)\nBuild Your Own Blocks\n\n--- dev ---\n\n' + 'Copyright \u24B8 2015 Jens M\u00F6nig and ' + 'Brian Harvey\n' + 'jens@moenig.org, bh@cs.berkeley.edu\n\n' @@ -5182,7 +5182,7 @@ function SpriteIconMorph(aSprite, aTemplate) { } SpriteIconMorph.prototype.init = function (aSprite, aTemplate) { - var colors, action, query, myself = this; + var colors, action, query, hover, myself = this; if (!aTemplate) { colors = [ @@ -5212,6 +5212,11 @@ SpriteIconMorph.prototype.init = function (aSprite, aTemplate) { return false; }; + hover = function () { + if (!aSprite.exemplar) {return null; } + return (localize('parent' + ':\n' + aSprite.exemplar.name)); + }; + // additional properties: this.object = aSprite || new SpriteMorph(); // mandatory, actually this.version = this.object.version; @@ -5227,7 +5232,7 @@ SpriteIconMorph.prototype.init = function (aSprite, aTemplate) { this.object.name, // label string query, // predicate/selector null, // environment - null, // hint + hover, // hint aTemplate // optional, for cached background images ); @@ -5398,6 +5403,7 @@ SpriteIconMorph.prototype.userMenu = function () { menu.addItem("duplicate", 'duplicateSprite'); menu.addItem("delete", 'removeSprite'); menu.addLine(); + menu.addItem("parent...", 'chooseExemplar'); if (this.object.anchor) { menu.addItem( localize('detach from') + ' ' + this.object.anchor.name, @@ -5432,6 +5438,10 @@ SpriteIconMorph.prototype.exportSprite = function () { this.object.exportSprite(); }; +SpriteIconMorph.prototype.chooseExemplar = function () { + this.object.chooseExemplar(); +}; + SpriteIconMorph.prototype.showSpriteOnStage = function () { this.object.showOnStage(); }; diff --git a/history.txt b/history.txt index b53e59c..e02d368 100755 --- a/history.txt +++ b/history.txt @@ -2476,3 +2476,7 @@ ______ ------ * Store: fixed #743 * GUI, html: switch from beta to release candidate + +150321 +------ +* OOP: Prototypal inheritance of sprite-local variables diff --git a/morphic.js b/morphic.js index 9616897..359e552 100644 --- a/morphic.js +++ b/morphic.js @@ -8,7 +8,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!. @@ -527,6 +527,12 @@ a duplicate of the template whose "isDraggable" flag is true and whose "isTemplate" flag is false, in other words: a non-template. + When creating a copy from a template, the copy's + + reactToTemplateCopy + + is invoked, if it is present. + Dragging is indicated by adding a drop shadow to the morph in hand. If a morph follows the hand without displaying a drop shadow it is merely being moved about without changing its parent (owner morph), @@ -1020,9 +1026,10 @@ programming hero. I have originally written morphic.js in Florian Balmer's Notepad2 - editor for Windows and later switched to Apple's Dashcode. I've also - come to depend on both Douglas Crockford's JSLint, Mozilla's Firebug - and Google's Chrome to get it right. + editor for Windows, later switched to Apple's Dashcode and later + still to Apple's Xcode. I've also come to depend on both Douglas + Crockford's JSLint, Mozilla's Firebug and Google's Chrome to get + it right. IX. contributors @@ -1041,7 +1048,7 @@ /*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio, FileList, getBlurredShadowSupport*/ -var morphicVersion = '2014-December-05'; +var morphicVersion = '2015-March-21'; var modules = {}; // keep track of additional loaded modules var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug @@ -8060,7 +8067,7 @@ TriggerMorph.prototype.init = function ( this.environment = environment || null; this.labelString = labelString || null; this.label = null; - this.hint = hint || null; + this.hint = hint || null; // null, String, or Function this.fontSize = fontSize || MorphicPreferences.menuFontSize; this.fontStyle = fontStyle || 'sans-serif'; this.highlightColor = new Color(192, 192, 192); @@ -8209,10 +8216,11 @@ TriggerMorph.prototype.triggerDoubleClick = function () { // TriggerMorph events: TriggerMorph.prototype.mouseEnter = function () { + var contents = this.hint instanceof Function ? this.hint() : this.hint; this.image = this.highlightImage; this.changed(); - if (this.hint) { - this.bubbleHelp(this.hint); + if (contents) { + this.bubbleHelp(contents); } }; @@ -9683,6 +9691,9 @@ HandMorph.prototype.processMouseMove = function (event) { morph = this.morphToGrab.fullCopy(); morph.isTemplate = false; morph.isDraggable = true; + if (morph.reactToTemplateCopy) { + morph.reactToTemplateCopy(); + } this.grab(morph); this.grabOrigin = this.morphToGrab.situation(); } diff --git a/objects.js b/objects.js index 1fe1309..56e5806 100644 --- a/objects.js +++ b/objects.js @@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2015-February-28'; +modules.objects = '2015-March-21'; var SpriteMorph; var StageMorph; @@ -1103,6 +1103,13 @@ SpriteMorph.prototype.initBlocks = function () { spec: 'script variables %scriptVars' }, + // inheritance - experimental + doDeleteAttr: { + type: 'command', + category: 'variables', + spec: 'delete %var' + }, + // Lists reportNewList: { type: 'reporter', @@ -1348,11 +1355,13 @@ SpriteMorph.prototype.init = function (globals) { 'confetti': 0 }; + // sprite inheritance + this.exemplar = null; + SpriteMorph.uber.init.call(this); this.isDraggable = true; this.isDown = false; - this.heading = 90; this.changed(); this.drawNew(); @@ -1642,7 +1651,8 @@ SpriteMorph.prototype.variableBlock = function (varName) { SpriteMorph.prototype.blockTemplates = function (category) { var blocks = [], myself = this, varNames, button, - cat = category || 'motion', txt; + cat = category || 'motion', txt, + inheritedVars = this.inheritedVariableNames(); function block(selector) { if (StageMorph.prototype.hiddenPrimitives[selector]) { @@ -1657,6 +1667,9 @@ SpriteMorph.prototype.blockTemplates = function (category) { var newBlock = SpriteMorph.prototype.variableBlock(varName); newBlock.isDraggable = false; newBlock.isTemplate = true; + if (contains(inheritedVars, varName)) { + newBlock.ghost(); + } return newBlock; } @@ -1705,15 +1718,16 @@ SpriteMorph.prototype.blockTemplates = function (category) { } function addVar(pair) { + var ide; if (pair) { - if (myself.variables.silentFind(pair[0])) { + if (myself.isVariableNameInUse(pair[0])) { myself.inform('that name is already in use'); } else { + ide = myself.parentThatIsA(IDE_Morph); myself.addVariable(pair[0], pair[1]); myself.toggleVariableWatcher(pair[0], pair[1]); - myself.blocksCache[cat] = null; - myself.paletteCache[cat] = null; - myself.parentThatIsA(IDE_Morph).refreshPalette(); + ide.flushBlocksCache('variables'); // b/c of inheritance + ide.refreshPalette(); } } } @@ -2028,7 +2042,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { button.showHelp = BlockMorph.prototype.showHelp; blocks.push(button); - if (this.variables.allNames().length > 0) { + if (this.deletableVariableNames().length > 0) { button = new PushButtonMorph( null, function () { @@ -2037,7 +2051,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { null, myself ); - myself.variables.allNames().forEach(function (name) { + myself.deletableVariableNames().forEach(function (name) { menu.addItem(name, name); }); menu.popUpAtHand(myself.world()); @@ -2067,6 +2081,13 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(block('doHideVar')); blocks.push(block('doDeclareVariables')); + // inheritance: + + blocks.push('-'); + blocks.push(block('doDeleteAttr')); + + /////////////////////////////// + blocks.push('='); blocks.push(block('reportNewList')); @@ -2491,7 +2512,7 @@ SpriteMorph.prototype.searchBlocks = function () { SpriteMorph.prototype.addVariable = function (name, isGlobal) { var ide = this.parentThatIsA(IDE_Morph); if (isGlobal) { - this.variables.parentFrame.addVar(name); + this.globalVariables().addVar(name); if (ide) { ide.flushBlocksCache('variables'); } @@ -2503,7 +2524,10 @@ SpriteMorph.prototype.addVariable = function (name, isGlobal) { SpriteMorph.prototype.deleteVariable = function (varName) { var ide = this.parentThatIsA(IDE_Morph); - this.deleteVariableWatcher(varName); + if (!contains(this.inheritedVariableNames(true), varName)) { + // check only shadowed variables + this.deleteVariableWatcher(varName); + } this.variables.deleteVar(varName); if (ide) { ide.flushBlocksCache('variables'); // b/c the var could be global @@ -3643,6 +3667,7 @@ SpriteMorph.prototype.reportThreadCount = function () { SpriteMorph.prototype.findVariableWatcher = function (varName) { var stage = this.parentThatIsA(StageMorph), + globals = this.globalVariables(), myself = this; if (stage === null) { return null; @@ -3652,7 +3677,7 @@ SpriteMorph.prototype.findVariableWatcher = function (varName) { function (morph) { return morph instanceof WatcherMorph && (morph.target === myself.variables - || morph.target === myself.variables.parentFrame) + || morph.target === globals) && morph.getter === varName; } ); @@ -3660,6 +3685,7 @@ SpriteMorph.prototype.findVariableWatcher = function (varName) { SpriteMorph.prototype.toggleVariableWatcher = function (varName, isGlobal) { var stage = this.parentThatIsA(StageMorph), + globals = this.globalVariables(), watcher, others; if (stage === null) { @@ -3679,12 +3705,12 @@ SpriteMorph.prototype.toggleVariableWatcher = function (varName, isGlobal) { // if no watcher exists, create a new one if (isNil(isGlobal)) { - isGlobal = contains(this.variables.parentFrame.names(), varName); + isGlobal = contains(globals.names(), varName); } watcher = new WatcherMorph( varName, this.blockColor.variables, - isGlobal ? this.variables.parentFrame : this.variables, + isGlobal ? globals : this.variables, varName ); watcher.setPosition(stage.position().add(10)); @@ -4110,6 +4136,118 @@ SpriteMorph.prototype.restoreLayers = function () { this.layers = null; }; +// SpriteMorph inheritance - general + +SpriteMorph.prototype.chooseExemplar = function () { + var stage = this.parentThatIsA(StageMorph), + myself = this, + other = stage.children.filter(function (m) { + return m instanceof SpriteMorph && + (!contains(m.allExemplars(), myself)); + }), + menu; + menu = new MenuMorph( + function (aSprite) {myself.setExemplar(aSprite); }, + localize('current parent') + + ':\n' + + (this.exemplar ? this.exemplar.name : localize('none')) + ); + other.forEach(function (eachSprite) { + menu.addItem(eachSprite.name, eachSprite); + }); + menu.addLine(); + menu.addItem(localize('none'), null); + menu.popUpAtHand(this.world()); +}; + +SpriteMorph.prototype.setExemplar = function (another) { + var ide = this.parentThatIsA(IDE_Morph); + this.exemplar = another; + if (isNil(another)) { + this.variables.parentFrame = (this.globalVariables()); + } else { + this.variables.parentFrame = (another.variables); + } + if (ide) { + ide.flushBlocksCache('variables'); + ide.refreshPalette(); + } +}; + +SpriteMorph.prototype.allExemplars = function () { + // including myself + var all = [], + current = this; + while (!isNil(current)) { + all.push(current); + current = current.exemplar; + } + return all; +}; + +SpriteMorph.prototype.specimens = function () { + // without myself + var myself = this; + return this.siblings().filter(function (m) { + return m instanceof SpriteMorph && (m.exemplar === myself); + }); +}; + +SpriteMorph.prototype.allSpecimens = function () { + // without myself + var myself = this; + return this.siblings().filter(function (m) { + return m instanceof SpriteMorph && contains(m.allExemplars(), myself); + }); +}; + +// SpriteMorph inheritance - variables + +SpriteMorph.prototype.isVariableNameInUse = function (vName) { + if (contains(this.variables.names(), vName)) {return true; } + return contains(this.globalVariables().names(), vName); +}; + +SpriteMorph.prototype.globalVariables = function () { + var current = this.variables.parentFrame; + while (current.owner) { + current = current.parentFrame; + } + return current; +}; + +SpriteMorph.prototype.shadowVar = function (name, value) { + var ide = this.parentThatIsA(IDE_Morph); + this.variables.addVar(name, value); + ide.flushBlocksCache('variables'); + ide.refreshPalette(); +}; + +SpriteMorph.prototype.inheritedVariableNames = function (shadowedOnly) { + var names = [], + own = this.variables.names(), + current = this.variables.parentFrame; + + function test(each) { + return shadowedOnly ? contains(own, each) : !contains(own, each); + } + + while (current.owner instanceof SpriteMorph) { + names.push.apply( + names, + current.names().filter(test) + ); + current = current.parentFrame; + } + return names; +}; + +SpriteMorph.prototype.deletableVariableNames = function () { + return this.variables.names().concat( + this.globalVariables().names() + ); +}; + // SpriteMorph highlighting SpriteMorph.prototype.addHighlight = function (oldHighlight) { @@ -4966,7 +5104,7 @@ StageMorph.prototype.blockTemplates = function (category) { function addVar(pair) { if (pair) { - if (myself.variables.silentFind(pair[0])) { + if (myself.isVariableNameInUse(pair[0])) { myself.inform('that name is already in use'); } else { myself.addVariable(pair[0], pair[1]); @@ -5269,6 +5407,13 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('doHideVar')); blocks.push(block('doDeclareVariables')); + // inheritance: + + blocks.push('-'); + blocks.push(block('doDeleteAttr')); + + /////////////////////////////// + blocks.push('='); blocks.push(block('reportNewList')); @@ -5660,6 +5805,14 @@ StageMorph.prototype.doubleDefinitionsFor StageMorph.prototype.replaceDoubleDefinitionsFor = SpriteMorph.prototype.replaceDoubleDefinitionsFor; +// StageMorph inheritance support - variables + +StageMorph.prototype.isVariableNameInUse + = SpriteMorph.prototype.isVariableNameInUse; + +StageMorph.prototype.globalVariables + = SpriteMorph.prototype.globalVariables; + // SpriteBubbleMorph //////////////////////////////////////////////////////// /* @@ -6892,13 +7045,32 @@ WatcherMorph.prototype.setSliderMax = function (num) { // WatcherMorph updating: WatcherMorph.prototype.update = function () { - var newValue, - num; + var newValue, sprite, num; + if (this.target && this.getter) { this.updateLabel(); if (this.target instanceof VariableFrame) { newValue = this.target.vars[this.getter] ? this.target.vars[this.getter].value : undefined; + if (newValue === undefined && this.target.owner) { + sprite = this.target.owner; + if (contains(sprite.inheritedVariableNames(), this.getter)) { + newValue = this.target.getVar(this.getter); + // ghost cell color + this.cellMorph.setColor( + SpriteMorph.prototype.blockColor.variables + .lighter(35) + ); + } else { + this.destroy(); + return; + } + } else { + // un-ghost the cell color + this.cellMorph.setColor( + SpriteMorph.prototype.blockColor.variables + ); + } } else { newValue = this.target[this.getter](); } diff --git a/snap.html b/snap.html index 976bcd6..234ed1f 100755 --- a/snap.html +++ b/snap.html @@ -2,7 +2,7 @@ - Snap! Build Your Own Blocks + Snap! Build Your Own Blocks. Development (OOP) diff --git a/store.js b/store.js index d4a2b64..b2bb0a3 100644 --- a/store.js +++ b/store.js @@ -61,7 +61,7 @@ SyntaxElementMorph, Variable*/ // Global stuff //////////////////////////////////////////////////////// -modules.store = '2015-March-15'; +modules.store = '2015-March-21'; // XML_Serializer /////////////////////////////////////////////////////// @@ -459,9 +459,17 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { myself.loadValue(model); }); - // restore nesting associations + // restore inheritance and nesting associations myself.project.stage.children.forEach(function (sprite) { - var anchor; + var exemplar, anchor; + if (sprite.inheritanceInfo) { // only sprites can inherit + exemplar = myself.project.sprites[ + sprite.inheritanceInfo.exemplar + ]; + if (exemplar) { + sprite.setExemplar(exemplar); + } + } if (sprite.nestingInfo) { // only sprites may have nesting info anchor = myself.project.sprites[sprite.nestingInfo.anchor]; if (anchor) { @@ -471,6 +479,7 @@ SnapSerializer.prototype.rawLoadProjectModel = function (xmlNode) { } }); myself.project.stage.children.forEach(function (sprite) { + delete sprite.inheritanceInfo; if (sprite.nestingInfo) { // only sprites may have nesting info sprite.nestingScale = +(sprite.nestingInfo.scale || sprite.scale); delete sprite.nestingInfo; @@ -639,9 +648,17 @@ SnapSerializer.prototype.loadSprites = function (xmlString, ide) { myself.loadObject(sprite, model); }); - // restore nesting associations + // restore inheritance and nesting associations project.stage.children.forEach(function (sprite) { - var anchor; + var exemplar, anchor; + if (sprite.inheritanceInfo) { // only sprites can inherit + exemplar = project.sprites[ + sprite.inheritanceInfo.exemplar + ]; + if (exemplar) { + sprite.setExemplar(exemplar); + } + } if (sprite.nestingInfo) { // only sprites may have nesting info anchor = project.sprites[sprite.nestingInfo.anchor]; if (anchor) { @@ -651,6 +668,7 @@ SnapSerializer.prototype.loadSprites = function (xmlString, ide) { } }); project.stage.children.forEach(function (sprite) { + delete sprite.inheritanceInfo; if (sprite.nestingInfo) { // only sprites may have nesting info sprite.nestingScale = +(sprite.nestingInfo.scale || sprite.scale); delete sprite.nestingInfo; @@ -690,6 +708,7 @@ SnapSerializer.prototype.loadMediaModel = function (xmlNode) { SnapSerializer.prototype.loadObject = function (object, model) { // private var blocks = model.require('blocks'); + this.loadInheritanceInfo(object, model); this.loadNestingInfo(object, model); this.loadCostumes(object, model); this.loadSounds(object, model); @@ -699,6 +718,14 @@ SnapSerializer.prototype.loadObject = function (object, model) { this.loadScripts(object.scripts, model.require('scripts')); }; +SnapSerializer.prototype.loadInheritanceInfo = function (object, model) { + // private + var info = model.childNamed('inherit'); + if (info) { + object.inheritanceInfo = info.attributes; + } +}; + SnapSerializer.prototype.loadNestingInfo = function (object, model) { // private var info = model.childNamed('nest'); @@ -1467,6 +1494,7 @@ SpriteMorph.prototype.toXML = function (serializer) { ' draggable="@"' + '%' + ' costume="@" color="@,@,@" pen="@" ~>' + + '%' + // inheritance info '%' + // nesting info '%' + '%' + @@ -1489,6 +1517,13 @@ SpriteMorph.prototype.toXML = function (serializer) { this.color.b, this.penPoint, + // inheritance info + this.exemplar + ? '' + : '', + // nesting info this.anchor ? ' optional, if specified label will left-align hasPreview, // show press color on left edge (e.g. category) @@ -560,12 +560,13 @@ ToggleButtonMorph.prototype.init = function ( // ToggleButtonMorph events ToggleButtonMorph.prototype.mouseEnter = function () { + var contents = this.hint instanceof Function ? this.hint() : this.hint; if (!this.state) { this.image = this.highlightImage; this.changed(); } - if (this.hint) { - this.bubbleHelp(this.hint); + if (contents) { + this.bubbleHelp(contents); } }; -- cgit v1.3.1 From af9b3dec293c45ac4b109f4ef3c21ba2f5bc55c3 Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Mon, 23 Mar 2015 12:44:46 +0100 Subject: OOP: Tweaks for scope conflicts when adding / removing vars --- blocks.js | 29 +++++++++++++++++++++++++++-- history.txt | 4 ++++ objects.js | 38 ++++++++++++++++++++++---------------- threads.js | 9 ++++++--- 4 files changed, 59 insertions(+), 21 deletions(-) (limited to 'threads.js') diff --git a/blocks.js b/blocks.js index 711976f..45f1049 100644 --- a/blocks.js +++ b/blocks.js @@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2015-March-21'; +modules.blocks = '2015-March-23'; var SyntaxElementMorph; @@ -1191,6 +1191,15 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { ); part.isStatic = true; break; + case '%shd': + part = new InputSlotMorph( + null, + false, + 'shadowedVariablesMenu', + true + ); + part.isStatic = true; + break; case '%lst': part = new InputSlotMorph( null, @@ -1889,7 +1898,8 @@ SyntaxElementMorph.prototype.endLayout = function () { %att - chameleon colored rectangular drop-down for attributes %fun - chameleon colored rectangular drop-down for math functions %typ - chameleon colored rectangular drop-down for data types - %var - chameleon colored rectangular drop-down for variable names + %var - chameleon colored rectangular drop-down for variable names + %shd - Chameleon colored rectuangular drop-down for shadowed var names %lst - chameleon colored rectangular drop-down for list names %b - chameleon colored hexagonal slot (for predicates) %l - list icon @@ -6902,6 +6912,21 @@ InputSlotMorph.prototype.getVarNamesDict = function () { return {}; }; +InputSlotMorph.prototype.shadowedVariablesMenu = function () { + var block = this.parentThatIsA(BlockMorph), + rcvr, + dict = {}; + + if (!block) {return dict; } + rcvr = block.receiver(); + if (rcvr) { + rcvr.inheritedVariableNames(true).forEach(function (name) { + dict[name] = name; + }); + } + return dict; +}; + InputSlotMorph.prototype.setChoices = function (dict, readonly) { // externally specify choices and read-only status, // used for custom blocks diff --git a/history.txt b/history.txt index e02d368..fc54386 100755 --- a/history.txt +++ b/history.txt @@ -2480,3 +2480,7 @@ ______ 150321 ------ * OOP: Prototypal inheritance of sprite-local variables + +150321 +------ +* OOP: Objects, Blocks, Threads - tweaks diff --git a/objects.js b/objects.js index 56e5806..2ea8427 100644 --- a/objects.js +++ b/objects.js @@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2015-March-21'; +modules.objects = '2015-March-23'; var SpriteMorph; var StageMorph; @@ -1107,7 +1107,7 @@ SpriteMorph.prototype.initBlocks = function () { doDeleteAttr: { type: 'command', category: 'variables', - spec: 'delete %var' + spec: 'delete %shd' }, // Lists @@ -1720,12 +1720,14 @@ SpriteMorph.prototype.blockTemplates = function (category) { function addVar(pair) { var ide; if (pair) { - if (myself.isVariableNameInUse(pair[0])) { + if (myself.isVariableNameInUse(pair[0], pair[1])) { myself.inform('that name is already in use'); } else { ide = myself.parentThatIsA(IDE_Morph); myself.addVariable(pair[0], pair[1]); - myself.toggleVariableWatcher(pair[0], pair[1]); + if (!myself.showingVariableWatcher(pair[0])) { + myself.toggleVariableWatcher(pair[0], pair[1]); + } ide.flushBlocksCache('variables'); // b/c of inheritance ide.refreshPalette(); } @@ -4203,7 +4205,10 @@ SpriteMorph.prototype.allSpecimens = function () { // SpriteMorph inheritance - variables -SpriteMorph.prototype.isVariableNameInUse = function (vName) { +SpriteMorph.prototype.isVariableNameInUse = function (vName, isGlobal) { + if (isGlobal) { + return contains(this.variables.allNames(), vName); + } if (contains(this.variables.names(), vName)) {return true; } return contains(this.globalVariables().names(), vName); }; @@ -4243,8 +4248,14 @@ SpriteMorph.prototype.inheritedVariableNames = function (shadowedOnly) { }; SpriteMorph.prototype.deletableVariableNames = function () { - return this.variables.names().concat( - this.globalVariables().names() + var locals = this.variables.names(), + inherited = this.inheritedVariableNames(); + return locals.concat( + this.globalVariables().names().filter( + function (each) { + return !contains(locals, each) && !contains(inherited, each); + } + ) ); }; @@ -5406,16 +5417,7 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('doShowVar')); blocks.push(block('doHideVar')); blocks.push(block('doDeclareVariables')); - - // inheritance: - - blocks.push('-'); - blocks.push(block('doDeleteAttr')); - - /////////////////////////////// - blocks.push('='); - blocks.push(block('reportNewList')); blocks.push('-'); blocks.push(block('reportCONS')); @@ -5813,6 +5815,10 @@ StageMorph.prototype.isVariableNameInUse StageMorph.prototype.globalVariables = SpriteMorph.prototype.globalVariables; +StageMorph.prototype.inheritedVariableNames = function () { + return []; +}; + // SpriteBubbleMorph //////////////////////////////////////////////////////// /* diff --git a/threads.js b/threads.js index d3dcfc9..82f7ab0 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-March-21'; +modules.threads = '2015-March-23'; var ThreadManager; var Process; @@ -1299,14 +1299,17 @@ Process.prototype.doRemoveTemporaries = function () { Process.prototype.doDeleteAttr = function (attrName) { // currently only variables are deletable - var name = attrName; + var name = attrName, + rcvr = this.blockReceiver(); if (name instanceof Context) { if (name.expression.selector === 'reportGetVar') { name = name.expression.blockSpec; } } - this.blockReceiver().deleteVariable(name); + if (contains(rcvr.inheritedVariableNames(true), name)) { + rcvr.deleteVariable(name); + } }; // Process lists primitives -- cgit v1.3.1 From 34187eb69e99b87158fe21a94a810085227b88cb Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Mon, 23 Mar 2015 13:56:05 +0100 Subject: fix (part of) "show variable" primitive for inheritance --- threads.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 82f7ab0..0511c53 100644 --- a/threads.js +++ b/threads.js @@ -1216,7 +1216,7 @@ Process.prototype.doShowVar = function (varName) { } // if no watcher exists, create a new one isGlobal = contains( - this.homeContext.receiver.variables.parentFrame.names(), + this.homeContext.receiver.globalVariables().names(), varName ); if (isGlobal || target.owner) { -- cgit v1.3.1 From 5bf3820ce190d2334187681fb384421c594f52ac Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Wed, 25 Mar 2015 14:03:06 +0100 Subject: fixed #752 and #745 --- history.txt | 4 ++++ threads.js | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'threads.js') diff --git a/history.txt b/history.txt index b53e59c..e30cb00 100755 --- a/history.txt +++ b/history.txt @@ -2476,3 +2476,7 @@ ______ ------ * Store: fixed #743 * GUI, html: switch from beta to release candidate + +150325 +------ +* Threads: fixed #752 diff --git a/threads.js b/threads.js index 50af8dd..7100aa6 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-February-28'; +modules.threads = '2015-March-25'; var ThreadManager; var Process; @@ -1153,13 +1153,16 @@ Process.prototype.doDeclareVariables = function (varNames) { Process.prototype.doSetVar = function (varName, value) { var varFrame = this.context.variables, name = varName; - if (name instanceof Context) { if (name.expression.selector === 'reportGetVar') { - name = name.expression.blockSpec; + name.variables.setVar( + name.expression.blockSpec, + value + ); + return; } } - varFrame.setVar(name, value); + varFrame.setVar(name, value, this.blockReceiver()); }; Process.prototype.doChangeVar = function (varName, value) { @@ -1168,10 +1171,14 @@ Process.prototype.doChangeVar = function (varName, value) { if (name instanceof Context) { if (name.expression.selector === 'reportGetVar') { - name = name.expression.blockSpec; + name.variables.changeVar( + name.expression.blockSpec, + value + ); + return; } } - varFrame.changeVar(name, value); + varFrame.changeVar(name, value, this.blockReceiver()); }; Process.prototype.reportGetVar = function () { @@ -1323,6 +1330,8 @@ Process.prototype.doDeleteFromList = function (index, list) { } if (this.inputOption(index) === 'last') { idx = list.length(); + } else if (isNaN(+this.inputOption(index))) { + return null; } list.remove(idx); }; -- cgit v1.3.1 From 303188f2d5c3280972d02060e8e0fdaf50b4310e Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Wed, 25 Mar 2015 14:05:34 +0100 Subject: OOP: integrated and adjusted fix for #752 and #745 --- history.txt | 5 +++++ threads.js | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'threads.js') diff --git a/history.txt b/history.txt index fda02a3..8a2066d 100755 --- a/history.txt +++ b/history.txt @@ -2488,3 +2488,8 @@ ______ 150323 ------ * OOP: Morphic, Objects, Store - tweak inherited variable watcher slider deserialization + +150325 +------ +* Threads: fixed #752 +* OOP: integrated and adjusted fix for #752 diff --git a/threads.js b/threads.js index 0511c53..52f464d 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-March-23'; +modules.threads = '2015-March-25'; var ThreadManager; var Process; @@ -1153,10 +1153,14 @@ Process.prototype.doDeclareVariables = function (varNames) { Process.prototype.doSetVar = function (varName, value) { var varFrame = this.context.variables, name = varName; - if (name instanceof Context) { if (name.expression.selector === 'reportGetVar') { - name = name.expression.blockSpec; + name.variables.setVar( + name.expression.blockSpec, + value, + this.blockReceiver() + ); + return; } } varFrame.setVar(name, value, this.blockReceiver()); @@ -1168,7 +1172,12 @@ Process.prototype.doChangeVar = function (varName, value) { if (name instanceof Context) { if (name.expression.selector === 'reportGetVar') { - name = name.expression.blockSpec; + name.variables.changeVar( + name.expression.blockSpec, + value, + this.blockReceiver() + ); + return; } } varFrame.changeVar(name, value, this.blockReceiver()); @@ -1340,6 +1349,8 @@ Process.prototype.doDeleteFromList = function (index, list) { } if (this.inputOption(index) === 'last') { idx = list.length(); + } else if (isNaN(+this.inputOption(index))) { + return null; } list.remove(idx); }; -- cgit v1.3.1 From 7eb778a98e08e4c79a73ed41be6beafa1fda5788 Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Wed, 15 Apr 2015 17:02:10 +0200 Subject: flush Stage>>keysPressed when prompting the user --- history.txt | 5 +++++ threads.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'threads.js') diff --git a/history.txt b/history.txt index 8a2066d..ef96624 100755 --- a/history.txt +++ b/history.txt @@ -2493,3 +2493,8 @@ ______ ------ * Threads: fixed #752 * OOP: integrated and adjusted fix for #752 + +150415 +------ +* Threads: flush Stage>>keysPressed when prompting the user + diff --git a/threads.js b/threads.js index 52f464d..6ba0442 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-March-25'; +modules.threads = '2015-April-15'; var ThreadManager; var Process; @@ -1835,6 +1835,7 @@ Process.prototype.doAsk = function (data) { isStage = this.blockReceiver() instanceof StageMorph, activePrompter; + stage.keysPressed = {}; if (!this.prompter) { activePrompter = detect( stage.children, -- cgit v1.3.1 From db01489a49631ffed9a3d2acefa8581ded8752ad Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Wed, 15 Apr 2015 17:03:36 +0200 Subject: flush Stage>>keysPressed when prompting the user --- history.txt | 4 ++++ threads.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'threads.js') diff --git a/history.txt b/history.txt index e30cb00..9cdc5c9 100755 --- a/history.txt +++ b/history.txt @@ -2480,3 +2480,7 @@ ______ 150325 ------ * Threads: fixed #752 + +150415 +------ +* Threads: flush Stage>>keysPressed when prompting the user diff --git a/threads.js b/threads.js index 7100aa6..dfd89e7 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-March-25'; +modules.threads = '2015-April-15'; var ThreadManager; var Process; @@ -1816,6 +1816,7 @@ Process.prototype.doAsk = function (data) { isStage = this.blockReceiver() instanceof StageMorph, activePrompter; + stage.keysPressed = {}; if (!this.prompter) { activePrompter = detect( stage.children, -- cgit v1.3.1 From b6efcaf17c0230d5eea3f3d8a6d30e142c8d67cf Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Fri, 1 May 2015 11:59:17 -0400 Subject: return empty string when querying first letter of a list --- threads.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index dfd89e7..165ad0e 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-April-15'; +modules.threads = '2015-May-01'; var ThreadManager; var Process; @@ -2185,6 +2185,9 @@ Process.prototype.reportJoinWords = function (aList) { // Process string ops Process.prototype.reportLetter = function (idx, string) { + if (string instanceof List) { // catch a common user error + return ''; + } var i = +(idx || 0), str = (string || '').toString(); return str[i - 1] || ''; -- cgit v1.3.1 From d96a5984e64cdd2e8c4abcd0abaabaadf7cc1c02 Mon Sep 17 00:00:00 2001 From: Jens Mönig Date: Fri, 1 May 2015 11:59:51 -0400 Subject: return empty string when querying first letter of a list --- threads.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 6ba0442..47d5616 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-April-15'; +modules.threads = '2015-May-01'; var ThreadManager; var Process; @@ -2204,6 +2204,9 @@ Process.prototype.reportJoinWords = function (aList) { // Process string ops Process.prototype.reportLetter = function (idx, string) { + if (string instanceof List) { // catch a common user error + return ''; + } var i = +(idx || 0), str = (string || '').toString(); return str[i - 1] || ''; -- cgit v1.3.1 From c67a13b7bda166591a1b9f572e5113b31aa20f21 Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Tue, 19 May 2015 15:48:17 -0500 Subject: Fixed typo in Process constructor Changed Process.prototype.contructor to Process.prototype.constructor --- threads.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 165ad0e..df67b2c 100644 --- a/threads.js +++ b/threads.js @@ -339,7 +339,7 @@ ThreadManager.prototype.findProcess = function (block) { */ Process.prototype = {}; -Process.prototype.contructor = Process; +Process.prototype.constructor = Process; Process.prototype.timeout = 500; // msecs after which to force yield Process.prototype.isCatchingErrors = true; -- cgit v1.3.1 From e21a872b0dcbca2e7ea8311d9b54f709876d1848 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 15 Jun 2015 17:19:25 -0700 Subject: Implement log10 and 10^x math functions --- blocks.js | 6 +++--- threads.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'threads.js') diff --git a/blocks.js b/blocks.js index 67324ca..1ef322c 100644 --- a/blocks.js +++ b/blocks.js @@ -1111,9 +1111,9 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { acos : ['acos'], atan : ['atan'], ln : ['ln'], - // log : 'log', - 'e^' : ['e^'] - // '10^' : '10^' + log : ['log'], + 'e^' : ['e^'], + '10^' : ['10^'] }, true ); diff --git a/threads.js b/threads.js index 165ad0e..61b5722 100644 --- a/threads.js +++ b/threads.js @@ -2122,14 +2122,14 @@ Process.prototype.reportMonadic = function (fname, n) { case 'ln': result = Math.log(x); break; - case 'log': - result = 0; + case 'log': // base 10 + result = Math.log(x) / Math.LN10; break; case 'e^': result = Math.exp(x); break; case '10^': - result = 0; + result = Math.pow(10, x); break; default: nop(); -- cgit v1.3.1 From 93d67ed386bba4862ac00eb55dcf664300ce53c7 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 15 Jun 2015 18:49:24 -0700 Subject: Fix Error Handing in the DATE block For some reason the function wasnt properly catching errors and was instead rasing native JS errors. This fixes that bug, so the function will now report nothing when it doesnt know what to do. In addition, moving the variable `dateMap` inside the function reduces a global variable, which shouldnt affect anything other than keeping the code clean. :) --- threads.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 165ad0e..efe9ba4 100644 --- a/threads.js +++ b/threads.js @@ -2640,26 +2640,26 @@ Process.prototype.reportTimer = function () { }; // Process Dates and times in Snap -// Map block options to built-in functions -var dateMap = { - 'year' : 'getFullYear', - 'month' : 'getMonth', - 'date': 'getDate', - 'day of week' : 'getDay', - 'hour' : 'getHours', - 'minute' : 'getMinutes', - 'second' : 'getSeconds', - 'time in milliseconds' : 'getTime' -}; - Process.prototype.reportDate = function (datefn) { var inputFn = this.inputOption(datefn), - currDate = new Date(), - func = dateMap[inputFn], - result = currDate[func](); + // Map block options to built-in functions + dateMap = { + 'year' : 'getFullYear', + 'month' : 'getMonth', + 'date': 'getDate', + 'day of week' : 'getDay', + 'hour' : 'getHours', + 'minute' : 'getMinutes', + 'second' : 'getSeconds', + 'time in milliseconds' : 'getTime' + }; if (!dateMap[inputFn]) { return ''; } + var currDate = new Date(), + func = dateMap[inputFn], + result = currDate[func](); + // Show months as 1-12 and days as 1-7 if (inputFn === 'month' || inputFn === 'day of week') { result += 1; -- cgit v1.3.1 From f4ff1056eae012b9a257c7dea88af3d007012632 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Thu, 25 Jun 2015 15:30:58 +0200 Subject: update threads.js version --- threads.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index efe9ba4..edbe2cf 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2015-May-01'; +modules.threads = '2015-June-25'; var ThreadManager; var Process; @@ -2641,7 +2641,8 @@ Process.prototype.reportTimer = function () { // Process Dates and times in Snap Process.prototype.reportDate = function (datefn) { - var inputFn = this.inputOption(datefn), + var currDate, func, result, + inputFn = this.inputOption(datefn), // Map block options to built-in functions dateMap = { 'year' : 'getFullYear', @@ -2655,16 +2656,14 @@ Process.prototype.reportDate = function (datefn) { }; if (!dateMap[inputFn]) { return ''; } - - var currDate = new Date(), - func = dateMap[inputFn], - result = currDate[func](); + currDate = new Date(); + func = dateMap[inputFn]; + result = currDate[func](); // Show months as 1-12 and days as 1-7 if (inputFn === 'month' || inputFn === 'day of week') { result += 1; } - return result; }; -- cgit v1.3.1