added "random" option for "go to", "point towards" and "point in direction" primitives

upd4.2
Jens Mönig 2018-03-09 11:47:11 +01:00
rodzic 04d3a37b67
commit c3dcde5bf8
4 zmienionych plików z 54 dodań i 7 usunięć

Wyświetl plik

@ -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(),

Wyświetl plik

@ -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

Wyświetl plik

@ -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,

Wyświetl plik

@ -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(