new "direction to..." primitive

as variant of "distance to..." in "Sensing"
upd4.2
Jens Mönig 2018-01-02 11:23:01 +01:00
rodzic 5785e00166
commit c506e23d94
8 zmienionych plików z 102 dodań i 49 usunięć

Wyświetl plik

@ -9,7 +9,7 @@
written by Jens Mönig
jens@moenig.org
Copyright (C) 2017 by Jens Mönig
Copyright (C) 2018 by Jens Mönig
This file is part of Snap!.
@ -148,7 +148,7 @@ CustomCommandBlockMorph, SymbolMorph, ToggleButtonMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2017-November-16';
modules.blocks = '2018-January-02';
var SyntaxElementMorph;
var BlockMorph;
@ -1057,6 +1057,17 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
);
part.setContents(1);
break;
case '%rel':
part = new InputSlotMorph(
null, // text
false, // numeric?
{
'distance' : ['distance'],
'direction' : ['direction']
},
true // read-only
);
break;
case '%spr':
part = new InputSlotMorph(
null,
@ -2075,6 +2086,7 @@ SyntaxElementMorph.prototype.endLayout = function () {
%ida - white roundish type-in slot with drop-down for list indices
%idx - white roundish type-in slot for indices incl. "any"
%obj - specially drawn slot for object reporters
%rel - chameleon colored rectangular drop-down for relation options
%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

6
gui.js
Wyświetl plik

@ -9,7 +9,7 @@
written by Jens Mönig
jens@moenig.org
Copyright (C) 2017 by Jens Mönig
Copyright (C) 2018 by Jens Mönig
This file is part of Snap!.
@ -75,7 +75,7 @@ isRetinaSupported, SliderMorph, Animation*/
// Global stuff ////////////////////////////////////////////////////////
modules.gui = '2017-December-01';
modules.gui = '2018-January-02';
// Declarations
@ -3387,7 +3387,7 @@ IDE_Morph.prototype.aboutSnap = function () {
world = this.world();
aboutTxt = 'Snap! 4.1.1 - dev -\nBuild Your Own Blocks\n\n'
+ 'Copyright \u24B8 2017 Jens M\u00F6nig and '
+ 'Copyright \u24B8 2018 Jens M\u00F6nig and '
+ 'Brian Harvey\n'
+ 'jens@moenig.org, bh@cs.berkeley.edu\n\n'

Wyświetl plik

Przed

Szerokość:  |  Wysokość:  |  Rozmiar: 9.2 KiB

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 9.2 KiB

Wyświetl plik

@ -3821,3 +3821,16 @@ Fixes:
171212
------
* fixed #1963
180102
------
* new "direction to..." primitive as variant of "distance to..." in "Sensing"
v4.1.1 Features:
* translation support for custom blocks
* new "direction to..." primitive as variant of "distance to..." in "Sensing"
Fixes:
* enabled color picker for pen trails on stage

Wyświetl plik

@ -6,7 +6,7 @@
written by Jens Mönig
Copyright (C) 2017 by Jens Mönig
Copyright (C) 2018 by Jens Mönig
This file is part of Snap!.
@ -185,7 +185,7 @@ SnapTranslator.dict.de = {
'translator_e-mail':
'jens@moenig.org', // optional
'last_changed':
'2017-10-20', // this, too, will appear in the Translators tab
'2018-01-02', // this, too, will appear in the Translators tab
// GUI
// control bar:
@ -539,8 +539,10 @@ SnapTranslator.dict.de = {
'Maustaste gedr\u00fcckt?',
'key %key pressed?':
'Taste %key gedr\u00fcckt?',
'distance to %dst':
'Entfernung von %dst',
'%rel to %dst':
'%rel zu %dst',
'distance':
'Entfernung',
'reset timer':
'starte Stoppuhr neu',
'timer':

Wyświetl plik

@ -6,7 +6,7 @@
written by Jens Mönig
Copyright (C) 2017 by Jens Mönig
Copyright (C) 2018 by Jens Mönig
This file is part of Snap!.
@ -42,7 +42,7 @@
/*global modules, contains*/
modules.locale = '2017-November-15';
modules.locale = '2018-January-02';
// Global stuff
@ -160,7 +160,7 @@ SnapTranslator.dict.de = {
'translator_e-mail':
'jens@moenig.org',
'last_changed':
'2017-10-20'
'2018-01-02'
};
SnapTranslator.dict.it = {

Wyświetl plik

@ -9,7 +9,7 @@
written by Jens Mönig
jens@moenig.org
Copyright (C) 2017 by Jens Mönig
Copyright (C) 2018 by Jens Mönig
This file is part of Snap!.
@ -83,7 +83,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
AlignmentMorph*/
modules.objects = '2017-December-12';
modules.objects = '2018-January-02';
var SpriteMorph;
var StageMorph;
@ -573,16 +573,6 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'when %keyHat key pressed'
},
/* migrated to a newer block version:
receiveClick: {
type: 'hat',
category: 'control',
spec: 'when I am clicked'
},
*/
receiveInteraction: {
type: 'hat',
category: 'control',
@ -696,25 +686,6 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'control',
spec: 'call %repRing %inputs'
},
/*
doRunWithInputList: {
type: 'command',
category: 'control',
spec: 'run %cmd with input list %l'
},
forkWithInputList: {
type: 'command',
category: 'control',
spec: 'launch %cmd with input list %l'
},
evaluateWithInputList: {
type: 'reporter',
category: 'control',
spec: 'call %r with input list %l'
},
*/
doReport: {
type: 'command',
category: 'control',
@ -745,7 +716,7 @@ SpriteMorph.prototype.initBlocks = function () {
// Message passing - very experimental
doTellTo: { // under construction +++
doTellTo: {
dev: true,
type: 'command',
category: 'control',
@ -872,11 +843,20 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'sensing',
spec: 'key %key pressed?'
},
reportDistanceTo: {
/*
reportDistanceTo: { // has been superseded by reportRelationTo
type: 'reporter',
category: 'sensing',
spec: 'distance to %dst'
},
*/
reportRelationTo: {
only: SpriteMorph,
type: 'reporter',
category: 'sensing',
spec: '%rel to %dst',
defaults: [['distance']]
},
doResetTimer: {
type: 'command',
category: 'sensing',
@ -1310,6 +1290,11 @@ SpriteMorph.prototype.initBlockMigrations = function () {
selector: 'doMapValueCode',
inputs: [['String'], '<#1>'],
offset: 1
},
reportDistanceTo: {
selector: 'reportRelationTo',
inputs: [['distance']],
offset: 1
}
};
};
@ -2058,7 +2043,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportKeyPressed'));
blocks.push('-');
blocks.push(block('reportDistanceTo'));
blocks.push(block('reportRelationTo'));
blocks.push('-');
blocks.push(block('doResetTimer'));
blocks.push(watcherToggle('getTimer'));
@ -4479,6 +4464,10 @@ SpriteMorph.prototype.setHeading = function (degrees, noShadow) {
};
SpriteMorph.prototype.faceToXY = function (x, y) {
this.setHeading(this.angleToXY(x, y));
};
SpriteMorph.prototype.angleToXY = function (x, y) {
var deltaX = (x - this.xPosition()) * this.parent.scale,
deltaY = (y - this.yPosition()) * this.parent.scale,
angle = Math.abs(deltaX) < 0.001 ? (deltaY < 0 ? 90 : 270)
@ -4486,7 +4475,7 @@ SpriteMorph.prototype.faceToXY = function (x, y) {
(deltaX >= 0 ? 0 : 180)
- (Math.atan(deltaY / deltaX) * 57.2957795131)
);
this.setHeading(angle + 90);
return angle + 90;
};
SpriteMorph.prototype.turn = function (degrees) {

Wyświetl plik

@ -9,7 +9,7 @@
written by Jens Mönig
jens@moenig.org
Copyright (C) 2017 by Jens Mönig
Copyright (C) 2018 by Jens Mönig
This file is part of Snap!.
@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph,
TableFrameMorph, ColorSlotMorph, isSnapObject*/
modules.threads = '2017-December-01';
modules.threads = '2018-January-02';
var ThreadManager;
var Process;
@ -3058,6 +3058,17 @@ Process.prototype.reportColorIsTouchingColor = function (color1, color2) {
return false;
};
Process.prototype.reportRelationTo = function (relation, name) {
var rel = this.inputOption(relation);
if (rel === 'distance') {
return this.reportDistanceTo(name);
}
if (rel === 'direction') {
return this.reportDirectionTo(name);
}
return 0;
};
Process.prototype.reportDistanceTo = function (name) {
var thisObj = this.blockReceiver(),
thatObj,
@ -3084,6 +3095,32 @@ Process.prototype.reportDistanceTo = function (name) {
return 0;
};
Process.prototype.reportDirectionTo = function (name) {
var thisObj = this.blockReceiver(),
thatObj;
if (thisObj) {
if (this.inputOption(name) === 'mouse-pointer') {
return thisObj.angleToXY(this.reportMouseX(), this.reportMouseY());
}
if (name instanceof List) {
return thisObj.angleToXY(
name.at(1),
name.at(2)
);
}
thatObj = this.getOtherObject(name, this.homeContext.receiver);
if (thatObj) {
return thisObj.angleToXY(
thatObj.xPosition(),
thatObj.yPosition()
);
}
return thisObj.direction();
}
return 0;
};
Process.prototype.reportAttributeOf = function (attribute, name) {
var thisObj = this.blockReceiver(),
thatObj,