blockNumber: & UnaryOperators

This commit is contained in:
ckcz123 2020-07-05 18:28:02 +08:00
parent 74ec3e817a
commit 6011545f68
5 changed files with 51 additions and 8 deletions

View File

@ -3098,6 +3098,7 @@ statExprSplit : '=== statement ^ === expression v ===' ;
expression
: expression Arithmetic_List expression
| negate_e
| unaryOperation_e
| bool_e
| idFixedList_e
| idFlag_e
@ -3106,6 +3107,7 @@ expression
| idString_e
| enemyattr_e
| blockId_e
| blockNumber_e
| blockCls_e
| equip_e
| evalString_e
@ -3115,7 +3117,9 @@ expression
//todo 修改recieveOrder,根据Arithmetic_List_0不同的值设定不同的recieveOrder
var code = expression_0 + Arithmetic_List_0 + expression_1;
var ops = {
'**': 'Math.pow('+expression_0+','+expression_1+')'
'**': 'Math.pow('+expression_0+','+expression_1+')',
'min': 'Math.min('+expression_0+','+expression_1+')',
'max': 'Math.max('+expression_0+','+expression_1+')',
}
if (ops[Arithmetic_List_0])code = ops[Arithmetic_List_0];
var orders = {
@ -3135,7 +3139,9 @@ var orders = {
'<=': Blockly.JavaScript.ORDER_RELATIONAL,
'&&': Blockly.JavaScript.ORDER_LOGICAL_AND,
'||': Blockly.JavaScript.ORDER_LOGICAL_OR,
'^': Blockly.JavaScript.ORDER_BITWISE_XOR
'^': Blockly.JavaScript.ORDER_BITWISE_XOR,
'min': Blockly.JavaScript.ORDER_MEMBER, //recieveOrder : ORDER_COMMA
'max': Blockly.JavaScript.ORDER_MEMBER, //recieveOrder : ORDER_COMMA
}
return [code, orders[Arithmetic_List_0]];
*/;
@ -3150,6 +3156,16 @@ var code = '!'+expression_0;
return [code, Blockly.JavaScript.ORDER_LOGICAL_NOT];
*/;
unaryOperation_e
: UnaryOperator_List expression
/* unaryOperation_e
var code = UnaryOperator_List_0 + expression_0;
return [code, Blockly.JavaScript.ORDER_MEMBER];
*/;
bool_e
: ':' Bool
@ -3217,6 +3233,17 @@ return [code, Blockly.JavaScript.ORDER_ATOMIC];
*/;
blockNumber_e
: '图块数字:' Int ',' Int
/* blockNumber_e
default : [0,0]
var code = 'blockNumber:'+Int_0+','+Int_1;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
*/;
blockCls_e
: '图块类别:' Int ',' Int
@ -3332,12 +3359,16 @@ ShopUse_List
/*ShopUse_List ['money','exp']*/;
Arithmetic_List
: '加'|'减'|'乘'|'除'|'取余'|'乘方'|'等于'|'不等于'|'大于'|'小于'|'大于等于'|'小于等于'|'且'|'或'|'异或'|'弱相等'|'弱不相等'
/*Arithmetic_List ['+','-','*','/','%','**','===','!==','>','<','>=','<=','&&','||','^','==','!=']*/;
: '加'|'减'|'乘'|'除'|'取余'|'乘方'|'等于'|'不等于'|'大于'|'小于'|'大于等于'|'小于等于'|'且'|'或'|'异或'|'取较大'|'取较小'|'弱相等'|'弱不相等'
/*Arithmetic_List ['+','-','*','/','%','**','===','!==','>','<','>=','<=','&&','||','^','max','min','==','!=']*/;
AssignOperator_List
: '设为'|'增加'|'减少'|'乘以'|'除以'|'乘方'|'除以并取商'|'除以并取余'
/*AssignOperator_List ['=','+=','-=','*=','/=','**=','//=','%=']*/;
: '设为'|'增加'|'减少'|'乘以'|'除以'|'乘方'|'除以并取商'|'除以并取余'|'设为不小于'|'设为不大于'
/*AssignOperator_List ['=','+=','-=','*=','/=','**=','//=','%=','min=','max=']*/;
UnaryOperator_List
: '向下取整'|'向上取整'|'四舍五入'|'整数截断'|'绝对值'|'开方'
/*UnaryOperator_List ['Math.floor', 'Math.ceil', 'Math.round', 'Math.trunc', 'Math.abs', 'Math.sqrt']*/;
Weather_List
: '无'|'雨'|'雪'|'雾'|'云'

View File

@ -1098,6 +1098,12 @@ ActionParser.prototype.matchEvalAtom = function(args) {
args=[match[1],match[2]]
return rt(MotaActionBlocks['blockId_e'].xmlText, args);
}
// 图块数字
match=/^blockNumber:(-?\d+),(-?\d+)$/.exec(args[0])
if(match){
args=[match[1],match[2]]
return rt(MotaActionBlocks['blockNumber_e'].xmlText, args);
}
// 图块类别
match=/^blockCls:(-?\d+),(-?\d+)$/.exec(args[0])
if(match){
@ -1412,7 +1418,7 @@ MotaActionFunctions.replaceToName = function (str) {
return map[b] ? ("怪物:" + map[b]) : b;
}).replace(/enemy:/g, "怪物:");
str = str.replace(/blockId:/g, "图块ID").replace(/blockCls:/g, "图块类别:").replace(/equip:/g, "装备孔:");
str = str.replace(/blockId:/g, "图块ID").replace(/blockNumber:/g, "图块数字:").replace(/blockCls:/g, "图块类别:").replace(/equip:/g, "装备孔:");
return str;
}
@ -1450,7 +1456,7 @@ MotaActionFunctions.replaceFromName = function (str) {
return map[c] ? ("enemy:" + b + ":" + map[c]) : c;
}).replace(/(enemy:[a-zA-Z0-9_]+)[:]/g, '$1:');
str = str.replace(/图块I[dD][:]/g, "blockId:").replace(/图块类别[:]/g, "blockCls:").replace(/装备孔[:]/g, "equip:");
str = str.replace(/图块I[dD][:]/g, "blockId:").replace(/图块数字[:]/g, "blockNumber:").replace(/图块类别[:]/g, "blockCls:").replace(/装备孔[:]/g, "equip:");
return str;
}

View File

@ -243,12 +243,14 @@ editor_blocklyconfig=(function(){
MotaActionBlocks['idFlag_e'].xmlText(),
MotaActionBlocks['idTemp_e'].xmlText(),
MotaActionBlocks['negate_e'].xmlText(),
MotaActionBlocks['unaryOperation_e'].xmlText(),
MotaActionBlocks['bool_e'].xmlText(),
MotaActionBlocks['idString_e'].xmlText(),
MotaActionBlocks['idIdList_e'].xmlText(),
MotaActionBlocks['idFixedList_e'].xmlText(),
MotaActionBlocks['enemyattr_e'].xmlText(),
MotaActionBlocks['blockId_e'].xmlText(),
MotaActionBlocks['blockNumber_e'].xmlText(),
MotaActionBlocks['blockCls_e'].xmlText(),
MotaActionBlocks['equip_e'].xmlText(),
MotaActionBlocks['evalString_e'].xmlText(),

View File

@ -2599,6 +2599,8 @@ events.prototype.setValue = function (name, operator, value, prefix) {
case '**=': value = Math.pow(originValue, value); break;
case '//=': value = Math.trunc(originValue / value); break;
case '%=': value = originValue % value; break;
case 'min=': value = Math.min(originValue, value); break;
case 'max=': value = Math.max(originValue, value); break;
default: break;
}
this._setValue_setStatus(name, value);

View File

@ -93,6 +93,8 @@ utils.prototype.replaceValue = function (value) {
value = value.replace(/enemy:([a-zA-Z0-9_]+)[\.:]([a-zA-Z0-9_]+)/g, "core.material.enemys['$1'].$2");
if (value.indexOf('blockId:')>=0)
value = value.replace(/blockId:(\d+),(\d+)/g, "core.getBlockId($1, $2)");
if (value.indexOf('blockNumber:')>=0)
value = value.replace(/blockNumber:(\d+),(\d+)/g, "core.getBlockNumber($1, $2)");
if (value.indexOf('blockCls:')>=0)
value = value.replace(/blockCls:(\d+),(\d+)/g, "core.getBlockCls($1, $2)");
if (value.indexOf('equip:')>=0)