From c3dcde5bf80e63ad2433ad97dba593a9153904f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Mo=CC=88nig?= Date: Fri, 9 Mar 2018 11:47:11 +0100 Subject: [PATCH] added "random" option for "go to", "point towards" and "point in direction" primitives --- blocks.js | 25 +++++++++++++++++++++++-- history.txt | 4 ++++ objects.js | 6 +++--- threads.js | 26 ++++++++++++++++++++++++-- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/blocks.js b/blocks.js index 38d04932..227c7ea6 100644 --- a/blocks.js +++ b/blocks.js @@ -148,7 +148,7 @@ CustomCommandBlockMorph, SymbolMorph, ToggleButtonMorph, DialMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2018-February-15'; +modules.blocks = '2018-March-09'; var SyntaxElementMorph; var BlockMorph; @@ -938,7 +938,8 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { '(90) right' : 90, '(-90) left' : -90, '(0) up' : '0', - '(180) down' : 180 + '(180) down' : 180, + 'random' : ['random'] } ); part.setContents(90); @@ -1095,6 +1096,14 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { true ); break; + case '%trg': // target selection + part = new InputSlotMorph( + null, + false, + 'targetsMenu', + true + ); + break; case '%cln': // clones part = new InputSlotMorph( null, @@ -2095,6 +2104,7 @@ SyntaxElementMorph.prototype.endLayout = function () { %spr - chameleon colored rectangular drop-down for object-names %col - chameleon colored rectangular drop-down for collidables %dst - chameleon colored rectangular drop-down for distances + %trg - chameleon colored rectangular drop-down for target destinations %cst - chameleon colored rectangular drop-down for costume-names %eff - chameleon colored rectangular drop-down for graphic effects %snd - chameleon colored rectangular drop-down for sound names @@ -8432,6 +8442,17 @@ InputSlotMorph.prototype.distancesMenu = function () { return dict; }; +InputSlotMorph.prototype.targetsMenu = function () { + var dict = { + 'random position' : ['random position'] + }, + dst = this.distancesMenu(); + Object.keys(dst).forEach(function (dstName) { + dict[dstName] = dst[dstName]; + }); + return dict; +}; + InputSlotMorph.prototype.clonablesMenu = function () { var dict = {}, rcvr = this.parentThatIsA(BlockMorph).scriptTarget(), diff --git a/history.txt b/history.txt index 3e86336e..2b05b76f 100755 --- a/history.txt +++ b/history.txt @@ -4015,3 +4015,7 @@ Translation Updates: ------ * Objects: fixed #2053 * GUI: fixed #2052 + +180309 +------ +* Blocks, Objects, Threads: added "random" option for "go to", "point towards" and "point in direction" primitives diff --git a/objects.js b/objects.js index 885a49a7..9f6578c2 100644 --- a/objects.js +++ b/objects.js @@ -83,7 +83,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph, AlignmentMorph, Process*/ -modules.objects = '2018-March-08'; +modules.objects = '2018-March-09'; var SpriteMorph; var StageMorph; @@ -209,7 +209,7 @@ SpriteMorph.prototype.initBlocks = function () { only: SpriteMorph, type: 'command', category: 'motion', - spec: 'point towards %dst' + spec: 'point towards %trg' }, gotoXY: { only: SpriteMorph, @@ -222,7 +222,7 @@ SpriteMorph.prototype.initBlocks = function () { only: SpriteMorph, type: 'command', category: 'motion', - spec: 'go to %dst' + spec: 'go to %trg' }, doGlide: { only: SpriteMorph, diff --git a/threads.js b/threads.js index f9534657..a0964c63 100644 --- a/threads.js +++ b/threads.js @@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, TableFrameMorph, ColorSlotMorph, isSnapObject*/ -modules.threads = '2018-March-05'; +modules.threads = '2018-March-09'; var ThreadManager; var Process; @@ -3002,6 +3002,17 @@ Process.prototype.getObjectsNamed = function (name, thisObj, stageObj) { return those; }; +Process.prototype.setHeading = function (direction) { + var thisObj = this.blockReceiver(); + + if (thisObj) { + if (this.inputOption(direction) === 'random') { + direction = this.reportRandom(1, 36000) / 100; + } + thisObj.setHeading(direction); + } +}; + Process.prototype.doFaceTowards = function (name) { var thisObj = this.blockReceiver(), thatObj; @@ -3009,6 +3020,8 @@ Process.prototype.doFaceTowards = function (name) { if (thisObj) { if (this.inputOption(name) === 'mouse-pointer') { thisObj.faceToXY(this.reportMouseX(), this.reportMouseY()); + } if (this.inputOption(name) === 'random position') { + thisObj.setHeading(this.reportRandom(1, 36000) / 100); } else { if (name instanceof List) { thisObj.faceToXY( @@ -3030,11 +3043,20 @@ Process.prototype.doFaceTowards = function (name) { Process.prototype.doGotoObject = function (name) { var thisObj = this.blockReceiver(), - thatObj; + thatObj, + stage; if (thisObj) { if (this.inputOption(name) === 'mouse-pointer') { thisObj.gotoXY(this.reportMouseX(), this.reportMouseY()); + } else if (this.inputOption(name) === 'random position') { + stage = thisObj.parentThatIsA(StageMorph); + if (stage) { + thisObj.setCenter(new Point( + this.reportRandom(stage.left(), stage.right()), + this.reportRandom(stage.top(), stage.bottom()) + )); + } } else { if (name instanceof List) { thisObj.gotoXY(