pull/29/head
Bernat Romagosa 2016-12-29 12:23:01 +01:00
commit 0d65bc9b79
14 zmienionych plików z 183 dodań i 165 usunięć

117
blocks.js
Wyświetl plik

@ -149,7 +149,7 @@ isSnapObject, copy, PushButtonMorph, SpriteIconMorph, Process, AlignmentMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2016-December-19';
modules.blocks = '2016-December-27';
var SyntaxElementMorph;
var BlockMorph;
@ -246,52 +246,52 @@ SyntaxElementMorph.uber = Morph.prototype;
outline:
corner - radius of command block rounding
corner - radius of command block rounding
rounding - radius of reporter block rounding
edge - width of 3D-ish shading box
hatHeight - additional top space for hat blocks
hatHeight - additional top space for hat blocks
hatWidth - minimum width for hat blocks
rfBorder - pixel width of reification border (grey outline)
minWidth - minimum width for any syntax element's contents
jigsaw shape:
inset - distance from indentation to left edge
inset - distance from indentation to left edge
dent - width of indentation bottom
paddings:
bottomPadding - adds to the width of the bottom most c-slot
bottomPadding - adds to the width of the bottom most c-slot
cSlotPadding - adds to the width of the open "C" in c-slots
typeInPadding - adds pixels between text and edge in input slots
typeInPadding - adds pixels between text and edge in input slots
labelPadding - adds left/right pixels to block labels
label:
labelFontName - <string> specific font family name
labelFontStyle - <string> generic font family name, cascaded
fontSize - duh
embossing - <Point> offset for embossing effect
labelWidth - column width, used for word wrapping
labelWordWrap - <bool> if true labels can break after each word
dynamicInputLabels - <bool> if true inputs can have dynamic labels
labelFontName - <string> specific font family name
labelFontStyle - <string> generic font family name, cascaded
fontSize - duh
embossing - <Point> offset for embossing effect
labelWidth - column width, used for word wrapping
labelWordWrap - <bool> if true labels can break after each word
dynamicInputLabels - <bool> if true inputs can have dynamic labels
snapping:
feedbackColor - <Color> for displaying drop feedbacks
feedbackMinHeight - height of white line for command block snaps
minSnapDistance - threshold when commands start snapping
reporterDropFeedbackPadding - increases reporter drop feedback
feedbackColor - <Color> for displaying drop feedbacks
feedbackMinHeight - height of white line for command block snaps
minSnapDistance - threshold when commands start snapping
reporterDropFeedbackPadding - increases reporter drop feedback
color gradients:
contrast - <percent int> 3D-ish shading gradient contrast
labelContrast - <percent int> 3D-ish label shading contrast
activeHighlight - <Color> for stack highlighting when active
errorHighlight - <Color> for error highlighting
activeBlur - <pixels int> shadow for blurred activeHighlight
labelContrast - <percent int> 3D-ish label shading contrast
activeHighlight - <Color> for stack highlighting when active
errorHighlight - <Color> for error highlighting
activeBlur - <pixels int> shadow for blurred activeHighlight
activeBorder - <pixels int> unblurred activeHighlight
rfColor - <Color> for reified outlines and slot backgrounds
rfColor - <Color> for reified outlines and slot backgrounds
*/
SyntaxElementMorph.prototype.setScale = function (num) {
@ -1120,7 +1120,8 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
part = new InputSlotMorph(
null,
false,
{ color: ['color'],
{
color: ['color'],
fisheye: ['fisheye'],
whirl: ['whirl'],
pixelate: ['pixelate'],
@ -2020,14 +2021,14 @@ SyntaxElementMorph.prototype.endLayout = function () {
SyntaxElementMorph my most important attributes and public
accessors are:
selector - (string) name of method to be triggered
receiver() - answer the object (sprite) to which I apply
inputs() - answer an array with my arg slots and nested reporters
defaults - an optional Array containing default input values
topBlock() - answer the top block of the stack I'm attached to
blockSpec - a formalized description of my label parts
setSpec() - force me to change my label structure
evaluate() - answer the result of my evaluation
selector - (string) name of method to be triggered
receiver() - answer the object (sprite) to which I apply
inputs() - answer an array with my arg slots and nested reporters
defaults - an optional Array containing default input values
topBlock() - answer the top block of the stack I'm attached to
blockSpec - a formalized description of my label parts
setSpec() - force me to change my label structure
evaluate() - answer the result of my evaluation
isUnevaluated() - answer whether I am part of a special form
Zebra coloring provides a mechanism to alternate brightness of nested,
@ -2101,28 +2102,28 @@ SyntaxElementMorph.prototype.endLayout = function () {
arity: multiple
%mult%x - where %x stands for any of the above single inputs
%inputs - for an additional text label 'with inputs'
%words - for an expandable list of default 2 (used in JOIN)
%exp - for a static expandable list of minimum 0 (used in LIST)
%scriptVars - for an expandable list of variable reporter templates
%parms - for an expandable list of formal parameters
%ringparms - the same for use inside Rings
%mult%x - where %x stands for any of the above single inputs
%inputs - for an additional text label 'with inputs'
%words - for an expandable list of default 2 (used in JOIN)
%exp - for a static expandable list of minimum 0 (used in LIST)
%scriptVars - for an expandable list of variable reporter templates
%parms - for an expandable list of formal parameters
%ringparms - the same for use inside Rings
special form: upvar
%upvar - same as %t (inline variable reporter template)
%upvar - same as %t (inline variable reporter template)
special form: input name
%inputName - variable blob (used in input type dialog)
%inputName - variable blob (used in input type dialog)
examples:
'if %b %c else %c' - creates Scratch's If/Else block
'set pen color to %clr' - creates Scratch's Pen color block
'set pen color to %clr' - creates Scratch's Pen color block
'list %mult%s' - creates BYOB's list reporter block
'call %n %inputs' - creates BYOB's Call block
'call %n %inputs' - creates BYOB's Call block
'the script %parms %c' - creates BYOB's THE SCRIPT block
*/
@ -2349,7 +2350,7 @@ BlockMorph.prototype.userMenu = function () {
menu.addItem(
"script pic with result...",
function () {
top.ExportResultPic();
top.exportResultPic();
},
'open a new window\n' +
'with a picture of both\nthis script and its result',
@ -4909,7 +4910,7 @@ ReporterBlockMorph.prototype.mouseClickLeft = function (pos) {
// ReporterBlock exporting picture with result bubble
ReporterBlockMorph.prototype.ExportResultPic = function () {
ReporterBlockMorph.prototype.exportResultPic = function () {
var top = this.topBlock(),
receiver = top.receiver(),
stage;
@ -4923,7 +4924,6 @@ ReporterBlockMorph.prototype.ExportResultPic = function () {
}
};
// ReporterBlockMorph deleting
ReporterBlockMorph.prototype.userDestroy = function () {
@ -8620,19 +8620,18 @@ TemplateSlotMorph.prototype.unflash = function () {
I am a diamond-shaped argument slot.
My block spec is
%b - Boolean
%b - Boolean
%boolUE - Boolean unevaluated
I can be directly edited. When the user clicks on me I toggle
between <true>, <false> and <null> values.
evaluate returns my value.
evaluate() returns my value.
my most important public attributes and accessors are:
value - user editable contents (Boolean or null)
value - user editable contents (Boolean or null)
setContents(Boolean/null) - display the argument (Boolean or null)
*/
// BooleanSlotMorph inherits from ArgMorph:
@ -10848,7 +10847,7 @@ function BlockHighlightMorph() {
evaluation is handles by the interpreter
*/
// MultiArgMorph inherits from ArgMorph:
// MultiArgMorph inherits from ArgMorph:
MultiArgMorph.prototype = new ArgMorph();
MultiArgMorph.prototype.constructor = MultiArgMorph;
@ -11256,10 +11255,9 @@ MultiArgMorph.prototype.mappedCode = function (definitions) {
// MultiArgMorph arity evaluating:
MultiArgMorph.prototype.evaluate = function () {
/*
this is usually overridden by the interpreter. This method is only
called (and needed) for the variables menu.
*/
// this is usually overridden by the interpreter. This method is only
// called (and needed) for the variables menu.
var result = [];
this.inputs().forEach(function (slot) {
result.push(slot.evaluate());
@ -11285,7 +11283,7 @@ MultiArgMorph.prototype.isEmptySlot = function () {
input's value along.
*/
// ArgLabelMorph inherits from ArgMorph:
// ArgLabelMorph inherits from ArgMorph:
ArgLabelMorph.prototype = new ArgMorph();
ArgLabelMorph.prototype.constructor = ArgLabelMorph;
@ -11395,10 +11393,9 @@ ArgLabelMorph.prototype.reactToGrabOf = function () {
// ArgLabelMorph evaluating:
ArgLabelMorph.prototype.evaluate = function () {
/*
this is usually overridden by the interpreter. This method is only
called (and needed) for the variables menu.
*/
// this is usually overridden by the interpreter. This method is only
// called (and needed) for the variables menu.
return this.argMorph().evaluate();
};
@ -11410,7 +11407,7 @@ ArgLabelMorph.prototype.isEmptySlot = function () {
/*
I am an unevaluated, non-editable, rf-colored, rounded or diamond
input slot. My current (only) use is in the THE BLOCK block.
input slot. My current (only) use is in the THE BLOCK block.
My command spec is %f
*/

Wyświetl plik

@ -2,7 +2,7 @@
byob.js
"build your own blocks" for SNAP!
"build your own blocks" for Snap!
based on morphic.js, widgets.js blocks.js, threads.js and objects.js
inspired by Scratch
@ -108,7 +108,7 @@ WatcherMorph, Variable*/
// Global stuff ////////////////////////////////////////////////////////
modules.byob = '2016-September-27';
modules.byob = '2016-December-27';
// Declarations

21
gui.js
Wyświetl plik

@ -72,7 +72,7 @@ isRetinaSupported, SliderMorph, Animation*/
// Global stuff ////////////////////////////////////////////////////////
modules.gui = '2016-December-19';
modules.gui = '2016-December-27';
// Declarations
@ -1358,6 +1358,7 @@ IDE_Morph.prototype.createSpriteEditor = function () {
this.spriteEditor.contents.acceptsDrops = true;
scripts.scrollFrame = this.spriteEditor;
scripts.updateUndropControls();
this.add(this.spriteEditor);
this.spriteEditor.scrollX(this.spriteEditor.padding);
this.spriteEditor.scrollY(this.spriteEditor.padding);
@ -2410,6 +2411,20 @@ IDE_Morph.prototype.settingsMenu = function () {
);
}
menu.addLine();
/*
addPreference(
'JavaScript',
function () {
Process.prototype.enableJS = !Process.prototype.enableJS;
myself.currentSprite.blocksCache.operators = null;
myself.currentSprite.paletteCache.operators = null;
myself.refreshPalette();
},
Process.prototype.enableJS,
'uncheck to disable support for\nnative JavaScript functions',
'check to support\nnative JavaScript functions'
);
*/
if (isRetinaSupported()) {
addPreference(
'Retina display support',
@ -2485,7 +2500,7 @@ IDE_Morph.prototype.settingsMenu = function () {
'Execute on slider change',
'toggleSliderExecute',
ArgMorph.prototype.executeOnSliderEdit,
'uncheck to supress\nrunning scripts\nwhen moving the slider',
'uncheck to suppress\nrunning scripts\nwhen moving the slider',
'check to run\nthe edited script\nwhen moving the slider'
);
}
@ -4475,6 +4490,8 @@ IDE_Morph.prototype.toggleAppMode = function (appMode) {
}
});
}
// update undrop controls
this.currentSprite.scripts.updateUndropControls();
}
this.setExtent(this.world().extent()); // resume trackChanges
};

Wyświetl plik

@ -3206,6 +3206,24 @@ http://snap.berkeley.edu/run#cloud:Username=jens&ProjectName=rotation
------
* Objects: added Boolean operators to “reporterize”
161222
------
* Objects: simplified reporterize>>blockFromAST
* Threads: prevented color slots from flashing. Good catch, thanks, Joan!
161223
------
* Objects: tweaked reporterize infixParser
161225
------
* GUI: update undrop controls when switching sprites and display modes
161227
------
* GUI, Threads, Objects, Store: Disable JS-Functions, to protect users from malicious scripts, commented out for now
== v4.10 === (in development)
Features:

Wyświetl plik

@ -846,7 +846,7 @@ SnapTranslator.dict.ca = {
'uncheck for round ends of lines':
'desmarqueu per fer que\nels extrems de les línies\ndel llapis siguin arrodonides',
'Inheritance support':
'Suport per a herència',
'Suport a l\'herència d\'objectes',
// inputs
'with inputs':
@ -1122,9 +1122,9 @@ SnapTranslator.dict.ca = {
'Command\n(C-shape)':
'Comanda\n(en forma de C)',
'Any\n(unevaluated)':
'Qualsevol\n(sense evaluar)',
'Qualsevol\n(sense avaluar)',
'Boolean\n(unevaluated)':
'Booleà\n(sense evaluar)',
'Booleà\n(sense avaluar)',
'Single input.':
'Entrada única.',
'Default Value:':
@ -1904,8 +1904,6 @@ SnapTranslator.dict.ca = {
'desmarqueu per deshabilitar\nel suport a l\'edició per teclat',
'check to enable\nkeyboard editing support':
'marqueu per habilitar\nel suport a l\'edició per teclat',
'Inheritance support':
'Suport a l\'herència d\'objectes',
'uncheck to disable\nsprite inheritance features':
'desmarqueu per deshabilitar les\nfuncionalitats relatives a l\'herència d\'objectes',
'check for sprite\ninheritance features':
@ -1924,8 +1922,6 @@ SnapTranslator.dict.ca = {
'captura de pantalla',
'stage image':
'imatge de l\'escenari',
'frames':
'frames',
'processes':
'processos',
'map %repRing over %l':

Wyświetl plik

@ -1909,8 +1909,6 @@ SnapTranslator.dict.pt = {
'Desassinalar para desactivar\na edição usando o teclado.',
'check to enable\nkeyboard editing support':
'Assinalar para activar\na edição usando o teclado.',
'Inheritance support':
'Suporte para herança',
'uncheck to disable\nsprite inheritance features':
'Desassinalar para desactivar\nfuncionalidades de herança de actores.',
'check for sprite\ninheritance features':

Wyświetl plik

@ -1,6 +1,6 @@
/*
lang-zh.js
lang-zh_CN.js
Simplified Chinese translation for SNAP!
@ -166,7 +166,7 @@
/*global SnapTranslator*/
SnapTranslator.dict.zh = {
SnapTranslator.dict.zh_CN = {
/*
Special characters: (see <http://0xcc.net/jsescape/>)

Wyświetl plik

@ -1,6 +1,6 @@
/*
lang-tw.js
lang-zh_TW.js
Traditional Chinese translation for SNAP!
SNAP 繁體中文翻譯版
@ -167,7 +167,7 @@
/*global SnapTranslator*/
SnapTranslator.dict.tw = {
SnapTranslator.dict.zh_TW = {
/*
Special characters: (see <http://0xcc.net/jsescape/>)

Wyświetl plik

@ -0,0 +1 @@
<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="safely try %&apos;action&apos; then if %&apos;error&apos; %&apos;handler&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%cs"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><custom-block s="let %upvar be %s"><l>reset</l><block s="evaluate"><block s="reportJSFunction"><list><l>proc</l></list><l>var oldHandleError = proc.handleError,&#xD; oldCatchingErrors = proc.isCatchingErrors;&#xD;&#xD;return function(){&#xD; proc.handleError = oldHandleError;&#xD; proc.isCatchingErrors = oldCatchingErrors;&#xD;}</l></block><list></list></block></custom-block><block s="doCallCC"><block s="reifyScript"><script><block s="doRun"><block s="reportJSFunction"><list><l>reset</l><l>action</l><l>handler</l><l>proc</l></list><l>proc.isCatchingErrors = true;&#xD;proc.handleError = function(error, element){&#xD; reset();&#xD; proc.context = handler;&#xD; proc.context.variables.setVar("error", error);&#xD;}&#xD;&#xD;try{&#xD; proc.evaluate(action, new List(), true);&#xD;}&#xD;catch(e){&#xD; proc.handleError(e, null);&#xD;} </l></block><list><block var="reset"/><block var="action"/><block s="reifyScript"><script><block s="doRun"><block s="reifyScript"><script><block s="doRun"><block var="handler"/><list></list></block><block s="doRun"><block var="return"/><list></list></block></script><list></list></block><list></list></block></script><list></list></block></list></block></script><list><l>return</l></list></block></block><block s="doRun"><block var="reset"/><list></list></block></script></block-definition><block-definition s="error %&apos;msg&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>msg</l></list><l>throw new Error(msg);</l></block><list><block var="msg"/></list></block></script></block-definition><block-definition s="let %&apos;var&apos; be %&apos;val&apos;" type="command" category="other"><header></header><code></code><inputs><input type="%upvar"></input><input type="%s"></input></inputs><script><block s="doSetVar"><l>var</l><block var="val"/></block></script></block-definition></blocks>

Wyświetl plik

@ -42,7 +42,7 @@
/*global modules, contains*/
modules.locale = '2016-December-09';
modules.locale = '2016-December-27';
// Global stuff
@ -229,7 +229,7 @@ SnapTranslator.dict.cs = {
'2015-11-16'
};
SnapTranslator.dict.zh = {
SnapTranslator.dict.zh_CN = {
'language_name':
'简体中文',
'language_translator':
@ -317,7 +317,7 @@ SnapTranslator.dict.pl = {
'2016-11-14'
};
SnapTranslator.dict.tw = {
SnapTranslator.dict.zh_TW = {
'language_name':
'繁體中文',
'language_translator':

Wyświetl plik

@ -1136,7 +1136,7 @@
/*global window, HTMLCanvasElement, FileReader, Audio, FileList*/
var morphicVersion = '2016-December-12';
var morphicVersion = '2016-December-27';
var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@ -3849,9 +3849,7 @@ Morph.prototype.perish = function (msecs, onComplete) {
// Morph utilities:
Morph.prototype.nop = function () {
nop();
};
Morph.prototype.nop = nop;
Morph.prototype.resize = function () {
this.world().activeHandle = new HandleMorph(this);
@ -4122,7 +4120,7 @@ Morph.prototype.developersMenu = function () {
menu.addItem(
"pick up",
'pickUp',
'disattach and put \ninto the hand'
'detach and put \ninto the hand'
);
menu.addItem(
"attach...",
@ -6310,9 +6308,7 @@ SliderButtonMorph.prototype.init = function (orientation) {
SliderButtonMorph.uber.init.call(this, orientation);
};
SliderButtonMorph.prototype.autoOrientation = function () {
nop();
};
SliderButtonMorph.prototype.autoOrientation = nop;
SliderButtonMorph.prototype.drawNew = function () {
var colorBak = this.color.copy();
@ -6548,9 +6544,7 @@ SliderMorph.prototype.init = function (
// this.drawNew();
};
SliderMorph.prototype.autoOrientation = function () {
nop();
};
SliderMorph.prototype.autoOrientation = nop;
SliderMorph.prototype.rangeSize = function () {
return this.stop - this.start;
@ -9833,9 +9827,7 @@ ScrollFrameMorph.prototype.scrollY = function (steps) {
}
};
ScrollFrameMorph.prototype.step = function () {
nop();
};
ScrollFrameMorph.prototype.step = nop;
ScrollFrameMorph.prototype.mouseDownLeft = function (pos) {
if (!this.isScrollingByDragging) {
@ -10026,7 +10018,6 @@ ScrollFrameMorph.prototype.developersMenu = function () {
return menu;
};
ScrollFrameMorph.prototype.toggleTextLineWrapping = function () {
this.isTextLineWrapping = !this.isTextLineWrapping;
};
@ -11447,21 +11438,13 @@ WorldMorph.prototype.initEventListeners = function () {
};
};
WorldMorph.prototype.mouseDownLeft = function () {
nop();
};
WorldMorph.prototype.mouseDownLeft = nop;
WorldMorph.prototype.mouseClickLeft = function () {
nop();
};
WorldMorph.prototype.mouseClickLeft = nop;
WorldMorph.prototype.mouseDownRight = function () {
nop();
};
WorldMorph.prototype.mouseDownRight = nop;
WorldMorph.prototype.mouseClickRight = function () {
nop();
};
WorldMorph.prototype.mouseClickRight = nop;
WorldMorph.prototype.wantsDropOf = function () {
// allow handle drops if any drops are allowed
@ -11538,7 +11521,7 @@ WorldMorph.prototype.contextMenu = function () {
menu.addItem(
"fill page...",
'fillPage',
'let the World automatically\nadjust to browser resizings'
'let the World automatically\nadjust to browser resizing'
);
if (useBlurredShadows) {
menu.addItem(

Wyświetl plik

@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/
modules.objects = '2016-December-21';
modules.objects = '2016-December-27';
var SpriteMorph;
var StageMorph;
@ -2027,8 +2027,11 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportIsA'));
blocks.push(block('reportIsIdentical'));
blocks.push('-');
blocks.push(block('reportJSFunction'));
if (true) { // (Process.prototype.enableJS) {
blocks.push('-');
blocks.push(block('reportJSFunction'));
}
// for debugging: ///////////////
@ -2641,8 +2644,8 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
var ast;
function parseInfix(expression, operator, already) {
// very basic binary infix parser for arithmetic expressions
// with strict left-to-right operator precedence (like in Smalltalk)
// very basic diadic infix parser for arithmetic expressions
// with strict left-to-right operator precedence (as in Smalltalk)
// which can be overriden by - nested - parentheses.
// assumes well-formed expressions, no graceful error handling yet.
@ -2702,13 +2705,17 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
case '&':
case '|':
if (!operator && !inputs[0].length) {
inputs[0] += ch;
inputs[0] = ch;
} else if (operator) {
return parseInfix(
expression.slice(idx),
ch,
[operator, already, format(inputs[1])]
);
if (!inputs[1].length) {
inputs[1] = ch;
} else {
return parseInfix(
expression.slice(idx),
ch,
[operator, already, format(inputs[1])]
);
}
} else {
operator = ch;
already = format(inputs[0]);
@ -2725,7 +2732,8 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
}
function blockFromAST(ast) {
var block, selectors, monads, alias, key, sel, i, inps;
var block, selectors, monads, alias, key, sel, i, inps,
off = 1;
selectors = {
'+': 'reportSum',
'-': 'reportDifference',
@ -2747,60 +2755,40 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
'!' : 'not'
};
key = alias[ast[0]] || ast[0];
if (contains(monads, key)) {
if (contains(monads, key)) { // monadic
sel = selectors[key];
if (sel) {
if (sel) { // single input
block = SpriteMorph.prototype.blockForSelector(sel);
inps = block.inputs();
i = 0;
} else {
} else { // two inputs, first is function name
block = SpriteMorph.prototype.blockForSelector('reportMonadic');
inps = block.inputs();
inps[0].setContents([key]);
i = 1;
off = 0;
}
if (ast[1] instanceof Array) {
block.silentReplaceInput(inps[i], blockFromAST(ast[1]));
} else if (isString(ast[1])) {
if (contains(['true', 'false'], ast[1])) {
} else { // diadic
block = SpriteMorph.prototype.blockForSelector(selectors[key]);
inps = block.inputs();
}
for (i = 1; i < ast.length; i += 1) {
if (ast[i] instanceof Array) {
block.silentReplaceInput(inps[i - off], blockFromAST(ast[i]));
} else if (isString(ast[i])) {
if (contains(['true', 'false'], ast[i])) {
block.silentReplaceInput(
inps[i],
inps[i - off],
SpriteMorph.prototype.blockForSelector(
ast[1] === 'true' ? 'reportTrue' : 'reportFalse'
ast[i] === 'true' ? 'reportTrue' : 'reportFalse'
)
);
} else if (ast[1] !== '_') {
} else if (ast[i] !== '_') {
block.silentReplaceInput(
inps[i],
SpriteMorph.prototype.variableBlock(ast[1])
inps[i - off],
SpriteMorph.prototype.variableBlock(ast[i])
);
}
} else { // number
inps[i].setContents(ast[1]);
}
} else { // diadic
block = SpriteMorph.prototype.blockForSelector(selectors[ast[0]]);
inps = block.inputs();
for (i = 1; i < 3; i += 1) {
if (ast[i] instanceof Array) {
block.silentReplaceInput(inps[i - 1], blockFromAST(ast[i]));
} else if (isString(ast[i])) {
if (contains(['true', 'false'], ast[i])) {
block.silentReplaceInput(
inps[i - 1],
SpriteMorph.prototype.blockForSelector(
ast[i] === 'true' ? 'reportTrue' : 'reportFalse'
)
);
} else if (ast[i] !== '_') {
block.silentReplaceInput(
inps[i - 1],
SpriteMorph.prototype.variableBlock(ast[i])
);
}
} else { // number
inps[i - 1].setContents(ast[i]);
}
inps[i - off].setContents(ast[i]);
}
}
block.isDraggable = true;
@ -6248,8 +6236,11 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportIsA'));
blocks.push(block('reportIsIdentical'));
blocks.push('-');
blocks.push(block('reportJSFunction'));
if (true) { // (Process.prototype.enableJS) {
blocks.push('-');
blocks.push(block('reportJSFunction'));
}
// for debugging: ///////////////

Wyświetl plik

@ -61,7 +61,7 @@ normalizeCanvas*/
// Global stuff ////////////////////////////////////////////////////////
modules.store = '2016-November-24';
modules.store = '2016-December-27';
// XML_Serializer ///////////////////////////////////////////////////////
@ -1017,6 +1017,16 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter) {
model.attributes['var']
);
}
/*
if (model.attributes.s === 'reportJSFunction' &&
!Process.prototype.enableJS) {
if (window.confirm('enable JavaScript?')) {
Process.prototype.enableJS = true;
} else {
throw new Error('JavaScript is not enabled');
}
}
*/
block = SpriteMorph.prototype.blockForSelector(model.attributes.s);
} else if (model.tag === 'custom-block') {
isGlobal = model.attributes.scope ? false : true;

Wyświetl plik

@ -59,9 +59,9 @@ degrees, detect, nop, radians, ReporterSlotMorph, CSlotMorph, RingMorph,
IDE_Morph, ArgLabelMorph, localize, XML_Element, hex_sha512, TableDialogMorph,
StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph,
TableFrameMorph, isSnapObject*/
TableFrameMorph, ColorSlotMorph, isSnapObject*/
modules.threads = '2016-October-27';
modules.threads = '2016-December-27';
var ThreadManager;
var Process;
@ -473,6 +473,7 @@ Process.prototype.isCatchingErrors = true;
Process.prototype.enableLiveCoding = false; // experimental
Process.prototype.enableSingleStepping = false; // experimental
Process.prototype.flashTime = 0; // experimental
// Process.prototype.enableJS = false;
function Process(topBlock, onComplete, rightAway) {
this.topBlock = topBlock || null;
@ -1000,6 +1001,11 @@ Process.prototype.evaluate = function (
) {
if (!context) {return null; }
if (context instanceof Function) {
/*
if (!this.enableJS) {
throw new Error('JavaScript is not enabled');
}
*/
return context.apply(
this.blockReceiver(),
args.asArray().concat([this])
@ -3357,7 +3363,8 @@ Process.prototype.flashContext = function () {
expr instanceof SyntaxElementMorph &&
!(expr instanceof CommandSlotMorph) &&
!this.context.isFlashing &&
expr.world()) {
expr.world() &&
!(expr instanceof ColorSlotMorph)) {
this.unflash();
expr.flash();
this.context.isFlashing = true;