summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2014-01-09 15:34:12 +0100
committerjmoenig <jens@moenig.org>2014-01-09 15:36:16 +0100
commit8a1ca3116b834625e6f71c6376c115975d4f9d75 (patch)
treee827c2f916f1f7bde9c6f038282bd909a6916617
parent4139efc35f2d36ca9088351f8ac32de9c2d6d4d1 (diff)
downloadsnap-byow-8a1ca3116b834625e6f71c6376c115975d4f9d75.tar.gz
snap-byow-8a1ca3116b834625e6f71c6376c115975d4f9d75.zip
Collapse STOP primitives into a single block with a dropdown of options
-rw-r--r--blocks.js17
-rwxr-xr-xhistory.txt5
-rw-r--r--objects.js55
-rw-r--r--threads.js19
4 files changed, 84 insertions, 12 deletions
diff --git a/blocks.js b/blocks.js
index 1ad2239..9997d70 100644
--- a/blocks.js
+++ b/blocks.js
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/
// Global stuff ////////////////////////////////////////////////////////
-modules.blocks = '2014-January-08';
+modules.blocks = '2014-January-09';
var SyntaxElementMorph;
var BlockMorph;
@@ -1037,6 +1037,20 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
);
part.setContents(['encode URI']);
break;
+ case '%stopChoices':
+ part = new InputSlotMorph(
+ null,
+ false,
+ {
+ 'all' : ['all'],
+ 'this script' : ['this script'],
+ 'this block' : ['this block']
+ },
+ true
+ );
+ part.setContents(['all']);
+ part.isStatic = true;
+ break;
case '%stopOthersChoices':
part = new InputSlotMorph(
null,
@@ -3279,6 +3293,7 @@ CommandBlockMorph.prototype.snap = function () {
CommandBlockMorph.prototype.isStop = function () {
return ([
+ 'doStopThis',
'doStop',
'doStopBlock',
'doStopAll',
diff --git a/history.txt b/history.txt
index a82204d..70c57bc 100755
--- a/history.txt
+++ b/history.txt
@@ -2055,3 +2055,8 @@ ______
* Threads, Blocks, Objects: Added StopOthers primitive, thanks, Kartik!
* Added „all but this option“ to StopOthers primitive, fixed the implementation
* Updated German translation with new strings
+
+140109
+------
+* Objects: Mechanism for migrating blocks in existing projects to newer versions
+* Blocks, Objects, Threads: Collapse old STOP primitives into a single one with a dropdown of options
diff --git a/objects.js b/objects.js
index 9f892d4..3f3df76 100644
--- a/objects.js
+++ b/objects.js
@@ -124,7 +124,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.objects = '2014-January-08';
+modules.objects = '2014-January-09';
var SpriteMorph;
var StageMorph;
@@ -581,6 +581,9 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'if %b %c else %c'
},
+
+ /* migrated to a newer block version:
+
doStop: {
type: 'command',
category: 'control',
@@ -591,6 +594,13 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'stop all %stop'
},
+ */
+
+ doStopThis: {
+ type: 'command',
+ category: 'control',
+ spec: 'stop %stopChoices'
+ },
doStopOthers: {
type: 'command',
category: 'control',
@@ -635,11 +645,13 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'report %s'
},
- doStopBlock: {
+ /*
+ doStopBlock: { // migrated to a newer block version
type: 'command',
category: 'control',
spec: 'stop block'
},
+ */
doCallCC: {
type: 'command',
category: 'control',
@@ -1084,6 +1096,25 @@ SpriteMorph.prototype.initBlocks = function () {
SpriteMorph.prototype.initBlocks();
+SpriteMorph.prototype.initBlockMigrations = function () {
+ SpriteMorph.prototype.blockMigrations = {
+ doStopAll: {
+ selector: 'doStopThis',
+ inputs: [['all']]
+ },
+ doStop: {
+ selector: 'doStopThis',
+ inputs: [['this script']]
+ },
+ doStopBlock: {
+ selector: 'doStopThis',
+ inputs: [['this block']]
+ }
+ };
+};
+
+SpriteMorph.prototype.initBlockMigrations();
+
SpriteMorph.prototype.blockAlternatives = {
// motion:
turn: ['turnLeft'],
@@ -1130,9 +1161,6 @@ SpriteMorph.prototype.blockAlternatives = {
receiveClick: ['receiveGo'],
doBroadcast: ['doBroadcastAndWait'],
doBroadcastAndWait: ['doBroadcast'],
- doStopBlock: ['doStop', 'doStopAll'],
- doStop: ['doStopBlock', 'doStopAll'],
- doStopAll: ['doStopBlock', 'doStop'],
// sensing:
getLastAnswer: ['getTimer'],
@@ -1412,8 +1440,9 @@ SpriteMorph.prototype.colorFiltered = function (aColor) {
// SpriteMorph block instantiation
SpriteMorph.prototype.blockForSelector = function (selector, setDefaults) {
- var info, block, defaults, inputs, i;
- info = this.blocks[selector];
+ var migration, info, block, defaults, inputs, i;
+ migration = this.blockMigrations[selector];
+ info = this.blocks[migration ? migration.selector : selector];
if (!info) {return null; }
block = info.type === 'command' ? new CommandBlockMorph()
: info.type === 'hat' ? new HatBlockMorph()
@@ -1426,8 +1455,8 @@ SpriteMorph.prototype.blockForSelector = function (selector, setDefaults) {
block.isStatic = true;
}
block.setSpec(localize(info.spec));
- if (setDefaults && info.defaults) {
- defaults = info.defaults;
+ if ((setDefaults && info.defaults) || (migration && migration.inputs)) {
+ defaults = migration ? migration.inputs : info.defaults;
block.defaults = defaults;
inputs = block.inputs();
if (inputs[0] instanceof MultiArgMorph) {
@@ -1651,9 +1680,13 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('doReport'));
blocks.push('-');
+ /*
+ // old STOP variants, migrated to a newer version, now redundant
blocks.push(block('doStopBlock'));
blocks.push(block('doStop'));
blocks.push(block('doStopAll'));
+ */
+ blocks.push(block('doStopThis'));
blocks.push(block('doStopOthers'));
blocks.push('-');
blocks.push(block('doRun'));
@@ -4358,9 +4391,13 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('doReport'));
blocks.push('-');
+ /*
+ // old STOP variants, migrated to a newer version, now redundant
blocks.push(block('doStopBlock'));
blocks.push(block('doStop'));
blocks.push(block('doStopAll'));
+ */
+ blocks.push(block('doStopThis'));
blocks.push(block('doStopOthers'));
blocks.push('-');
blocks.push(block('doRun'));
diff --git a/threads.js b/threads.js
index 8c3eb25..79af3b9 100644
--- a/threads.js
+++ b/threads.js
@@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/
// Global stuff ////////////////////////////////////////////////////////
-modules.threads = '2014-January-08';
+modules.threads = '2014-January-09';
var ThreadManager;
var Process;
@@ -1372,12 +1372,27 @@ Process.prototype.doStopAll = function () {
}
};
+Process.prototype.doStopThis = function (choice) {
+ switch (this.inputOption(choice)) {
+ case 'all':
+ this.doStopAll();
+ break;
+ case 'this script':
+ this.doStop();
+ break;
+ case 'this block':
+ this.doStopBlock();
+ break;
+ default:
+ nop();
+ }
+};
+
Process.prototype.doStopOthers = function (choice) {
var stage;
if (this.homeContext.receiver) {
stage = this.homeContext.receiver.parentThatIsA(StageMorph);
if (stage) {
-
switch (this.inputOption(choice)) {
case 'all but this script':
stage.threads.stopAll(this);