kopia lustrzana https://github.com/backface/turtlestitch
added Boolean operators to “reporterize”
rodzic
29b19ba859
commit
d6ced6fa2b
|
@ -3202,6 +3202,9 @@ http://snap.berkeley.edu/run#cloud:Username=jens&ProjectName=rotation
|
||||||
------
|
------
|
||||||
* Objects: tweaked “reporterize”
|
* Objects: tweaked “reporterize”
|
||||||
|
|
||||||
|
161221
|
||||||
|
------
|
||||||
|
* Objects: added Boolean operators to “reporterize”
|
||||||
|
|
||||||
== v4.10 === (in development)
|
== v4.10 === (in development)
|
||||||
|
|
||||||
|
|
46
objects.js
46
objects.js
|
@ -2696,6 +2696,11 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
|
||||||
case '*':
|
case '*':
|
||||||
case '/':
|
case '/':
|
||||||
case '%':
|
case '%':
|
||||||
|
case '=':
|
||||||
|
case '<':
|
||||||
|
case '>':
|
||||||
|
case '&':
|
||||||
|
case '|':
|
||||||
if (!operator && !inputs[0].length) {
|
if (!operator && !inputs[0].length) {
|
||||||
inputs[0] += ch;
|
inputs[0] += ch;
|
||||||
} else if (operator) {
|
} else if (operator) {
|
||||||
|
@ -2720,21 +2725,32 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function blockFromAST(ast) {
|
function blockFromAST(ast) {
|
||||||
var block, selectors, monads, alias, key, i, inps;
|
var block, selectors, monads, alias, key, sel, i, inps;
|
||||||
selectors = {
|
selectors = {
|
||||||
'+': 'reportSum',
|
'+': 'reportSum',
|
||||||
'-': 'reportDifference',
|
'-': 'reportDifference',
|
||||||
'*': 'reportProduct',
|
'*': 'reportProduct',
|
||||||
'/': 'reportQuotient',
|
'/': 'reportQuotient',
|
||||||
'%': 'reportModulus'
|
'%': 'reportModulus',
|
||||||
|
'=': 'reportEquals',
|
||||||
|
'<': 'reportLessThan',
|
||||||
|
'>': 'reportGreaterThan',
|
||||||
|
'&': 'reportAnd',
|
||||||
|
'|': 'reportOr',
|
||||||
|
round: 'reportRound',
|
||||||
|
not: 'reportNot'
|
||||||
};
|
};
|
||||||
monads = ['abs', 'ceiling', 'floor', 'sqrt', 'sin', 'cos', 'tan',
|
monads = ['abs', 'ceiling', 'floor', 'sqrt', 'sin', 'cos', 'tan',
|
||||||
'asin', 'acos', 'atan', 'ln', 'log', 'round'];
|
'asin', 'acos', 'atan', 'ln', 'log', 'round', 'not'];
|
||||||
alias = {ceil: 'ceiling'};
|
alias = {
|
||||||
|
ceil: 'ceiling',
|
||||||
|
'!' : 'not'
|
||||||
|
};
|
||||||
key = alias[ast[0]] || ast[0];
|
key = alias[ast[0]] || ast[0];
|
||||||
if (contains(monads, key)) {
|
if (contains(monads, key)) {
|
||||||
if (key === 'round') {
|
sel = selectors[key];
|
||||||
block = SpriteMorph.prototype.blockForSelector('reportRound');
|
if (sel) {
|
||||||
|
block = SpriteMorph.prototype.blockForSelector(sel);
|
||||||
inps = block.inputs();
|
inps = block.inputs();
|
||||||
i = 0;
|
i = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2746,7 +2762,14 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
|
||||||
if (ast[1] instanceof Array) {
|
if (ast[1] instanceof Array) {
|
||||||
block.silentReplaceInput(inps[i], blockFromAST(ast[1]));
|
block.silentReplaceInput(inps[i], blockFromAST(ast[1]));
|
||||||
} else if (isString(ast[1])) {
|
} else if (isString(ast[1])) {
|
||||||
if (ast[1] !== '_') {
|
if (contains(['true', 'false'], ast[1])) {
|
||||||
|
block.silentReplaceInput(
|
||||||
|
inps[i],
|
||||||
|
SpriteMorph.prototype.blockForSelector(
|
||||||
|
ast[1] === 'true' ? 'reportTrue' : 'reportFalse'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (ast[1] !== '_') {
|
||||||
block.silentReplaceInput(
|
block.silentReplaceInput(
|
||||||
inps[i],
|
inps[i],
|
||||||
SpriteMorph.prototype.variableBlock(ast[1])
|
SpriteMorph.prototype.variableBlock(ast[1])
|
||||||
|
@ -2762,7 +2785,14 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
|
||||||
if (ast[i] instanceof Array) {
|
if (ast[i] instanceof Array) {
|
||||||
block.silentReplaceInput(inps[i - 1], blockFromAST(ast[i]));
|
block.silentReplaceInput(inps[i - 1], blockFromAST(ast[i]));
|
||||||
} else if (isString(ast[i])) {
|
} else if (isString(ast[i])) {
|
||||||
if (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(
|
block.silentReplaceInput(
|
||||||
inps[i - 1],
|
inps[i - 1],
|
||||||
SpriteMorph.prototype.variableBlock(ast[i])
|
SpriteMorph.prototype.variableBlock(ast[i])
|
||||||
|
|
Ładowanie…
Reference in New Issue