Support Callback in Editor

This commit is contained in:
oc 2018-03-05 19:37:21 +08:00
parent 3ca7c95231
commit 66117ebf08
16 changed files with 84 additions and 137 deletions

File diff suppressed because one or more lines are too long

View File

@ -140,7 +140,7 @@ changeFloor_m
/* changeFloor_m
tooltip : 楼梯, 传送门, 如果目标楼层有多个楼梯, 写upFloor或downFloor可能会导致到达的楼梯不确定, 这时候请使用loc方式来指定具体的点位置
helpUrl : https://ckcz123.github.io/mota-js/#/element?id=%e8%b7%af%e9%9a%9c%ef%bc%8c%e6%a5%bc%e6%a2%af%ef%bc%8c%e4%bc%a0%e9%80%81%e9%97%a8
default : ["MT1",null,0,0,null,500,null]
default : ["MT1",null,0,0,[['不变',''],['上','up'],['下','down'],['左','left'],['右','right']],500,null]
var loc = ', "loc": ['+Int_0+', '+Int_1+']';
if (Stair_List_0!=='loc')loc = ', "stair": "'+Stair_List_0+'"';
DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"');
@ -470,7 +470,7 @@ changeFloor_s
/* changeFloor_s
tooltip : changeFloor: 楼层切换,动画时间可不填
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=changefloor-%e6%a5%bc%e5%b1%82%e5%88%87%e6%8d%a2
default : ["MT1",0,0,null,500]
default : ["MT1",0,0,[['不变',''],['上','up'],['下','down'],['左','left'],['右','right']],500]
colour : this.dataColor
DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"');
Int_2 = Int_2 ?(', "time": '+Int_2):'';
@ -485,7 +485,7 @@ changePos_0_s
/* changePos_0_s
tooltip : changePos: 当前位置切换
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=changepos-%e5%bd%93%e5%89%8d%e4%bd%8d%e7%bd%ae%e5%88%87%e6%8d%a2%e5%8b%87%e5%a3%ab%e8%bd%ac%e5%90%91
default : [0,0,null]
default : [0,0,[['不变',''],['上','up'],['下','down'],['左','left'],['右','right']]]
colour : this.dataColor
DirectionEx_List_0 = DirectionEx_List_0 && (', "direction": "'+DirectionEx_List_0+'"');
var code = '{"type": "changePos", "loc": ['+Int_0+','+Int_1+']'+DirectionEx_List_0+'},\n';
@ -500,6 +500,7 @@ changePos_1_s
tooltip : changePos: 勇士转向
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=changepos-%e5%bd%93%e5%89%8d%e4%bd%8d%e7%bd%ae%e5%88%87%e6%8d%a2%e5%8b%87%e5%a3%ab%e8%bd%ac%e5%90%91
colour : this.dataColor
default : [[['上','up'],['下','down'],['左','left'],['右','right']]]
var code = '{"type": "changePos", "direction": "'+Direction_List_0+'"},\n';
return code;
*/
@ -1037,23 +1038,23 @@ LineComment
;
/* Function_0
//converter.evisitor.recieveOrder='ORDER_NONE';
converter.evisitor.valueColor=330;
converter.evisitor.statementColor=70;
converter.evisitor.entryColor=250;
//this.evisitor.recieveOrder='ORDER_NONE';
this.evisitor.valueColor=330;
this.evisitor.statementColor=70;
this.evisitor.entryColor=250;
converter.evisitor.idstring_eColor=310;
converter.evisitor.subColor=190;
converter.evisitor.printColor=70;
converter.evisitor.dataColor=130;
converter.evisitor.eventColor=220;
converter.evisitor.soundColor=20;
this.evisitor.idstring_eColor=310;
this.evisitor.subColor=190;
this.evisitor.printColor=70;
this.evisitor.dataColor=130;
this.evisitor.eventColor=220;
this.evisitor.soundColor=20;
*/
/* Function_1
delete(converter.evisitor.expressionRules.negate_e.blockjs.inputsInline);
converter.evisitor.expressionRules.idString_1_e.blockjs.output='idString_e';
converter.evisitor.expressionRules.idString_2_e.blockjs.output='idString_e';
delete(this.block('negate_e').inputsInline);
this.block('idString_1_e').output='idString_e';
this.block('idString_2_e').output='idString_e';
*/
/* Functions
@ -1075,7 +1076,7 @@ ActionParser.prototype.parse = function (obj,type) {
if(!obj)obj={};
if(!this.isset(obj.loc))obj.loc=[0,0];
return MotaActionBlocks['changeFloor_m'].xmlText([
obj.floorId,obj.stair||'loc',obj.loc[0],obj.loc[1],this.Direction(obj.direction),obj.time||0,!this.isset(obj.portalWithoutTrigger)
obj.floorId,obj.stair||'loc',obj.loc[0],obj.loc[1],obj.direction,obj.time||0,!this.isset(obj.portalWithoutTrigger)
]);
case 'point':
@ -1215,15 +1216,15 @@ ActionParser.prototype.parseAction = function() {
break;
case "changeFloor": // 楼层转换
this.next = MotaActionBlocks['changeFloor_s'].xmlText([
data.floorId,data.loc[0],data.loc[1],this.Direction(data.direction),this.time||0,this.next]);
data.floorId,data.loc[0],data.loc[1],data.direction,this.time||0,this.next]);
break;
case "changePos": // 直接更换勇士位置, 不切换楼层
if(this.isset(data.loc)){
this.next = MotaActionBlocks['changePos_0_s'].xmlText([
data.loc[0],data.loc[1],this.Direction(data.direction),this.next]);
data.loc[0],data.loc[1],data.direction,this.next]);
} else {
this.next = MotaActionBlocks['changePos_1_s'].xmlText([
this.Direction(data.direction),this.next]);
data.direction,this.next]);
}
break;
case "animate": // 显示动画
@ -1390,18 +1391,6 @@ ActionParser.prototype.StepString = function(steplist) {
return StepString.join('');
}
ActionParser.prototype.Direction = function(Direction) {
var stepchar = {
'up': '上',
'down': '下',
'left': '左',
'right': '右'
}
Direction=stepchar[Direction];
if(!Direction)Direction='不变';
return Direction;
}
ActionParser.prototype.EvalString = function(EvalString) {
return EvalString.split('\b').join('\\b').split('\t').join('\\t').split('\n').join('\\n');
}
@ -1428,20 +1417,6 @@ MotaActionFunctions.IdString_pre = function(IdString){
return IdString;
}
MotaActionFunctions.DirectionEx_List_pre = function(DirectionEx_List){
var directionchar = {
'上': 'up',
'下': 'down',
'左': 'left',
'右': 'right'
}
Direction=directionchar[DirectionEx_List];
if(!Direction)Direction='';
return Direction;
}
MotaActionFunctions.Direction_List_pre = MotaActionFunctions.DirectionEx_List_pre
MotaActionFunctions.StepString_pre = function(StepString){
//StepString='上右3下2左上左2'
var route = StepString.replace(/上/g,'U').replace(/下/g,'D').replace(/左/g,'L').replace(/右/g,'R');

View File

@ -20,25 +20,25 @@ editor.prototype.init = function(callback){
if (Boolean(callback))callback();
});
}
var afterMainInit = function(){
editor.main=main;
editor.core=core;
editor.fs=fs;
editor_file = editor_file(editor);
editor.file=editor_file;
editor_mode = editor_mode(editor);
editor.mode=editor_mode;
editor.material.images=core.material.images;
editor.listen(); // 开始监听事件
var hard = 'Hard';
core.resetStatus(core.firstData.hero, hard, core.firstData.floorId, null, core.initStatus.maps);
//core.status.maps = core.clone(core.maps.initMaps(floorIds));
core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() {
afterCoreReset();
}, true);
core.events.setInitData(hard);
editor_file = editor_file(editor, function() {
editor.file=editor_file;
editor_mode = editor_mode(editor);
editor.mode=editor_mode;
editor.material.images=core.material.images;
editor.listen(); // 开始监听事件
core.resetStatus(core.firstData.hero, null, core.firstData.floorId, null, core.initStatus.maps);
core.changeFloor(core.status.floorId, null, core.firstData.hero.loc, null, function() {
afterCoreReset();
}, true);
core.events.setInitData(null);
});
}
setTimeout(afterMainInit, 500);
afterMainInit();
}
editor.prototype.reset = function(callback){

View File

@ -239,10 +239,10 @@ editor_blockly.runOne = function (){
//var printf = function(){};
var grammerFile = input_;
converter = new Converter().init();
converter.generBlocks(grammerFile,[]);
converter.generBlocks(grammerFile);
//printf(converter.blocks);
converter.renderGrammerName();
converter.generToolbox();
//converter.generToolbox();
converter.generMainFile();
//printf(converter.mainFile.join(''));
console.log(converter);

View File

@ -1,7 +1,9 @@
editor_file = function(editor){
editor_file = function(editor, callback){
var editor_file = {};
(function(){
var script = document.createElement('script');
if (window.location.href.indexOf('_server')!==-1)
@ -12,6 +14,8 @@ editor_file = function(editor){
script.onload = function () {
editor_file.comment=comment_c456ea59_6018_45ef_8bcc_211a24c627dc;
delete(comment_c456ea59_6018_45ef_8bcc_211a24c627dc);
if (editor_file.comment && editor_file.dataComment && callback)
callback();
}
})();
(function(){
@ -24,6 +28,8 @@ editor_file = function(editor){
script.onload = function () {
editor_file.dataComment=data_comment_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d;
delete(data_comment_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d);
if (editor_file.comment && editor_file.dataComment && callback)
callback();
}
})();

View File

@ -321,19 +321,21 @@ function hasOwnProp (obj, key) {
</script>
<script src='_server/editor.js'></script>
<script>
main.init('editor');
editor.init(function(){
editor.pos={x: 0, y: 0};
editor.mode.loc();
editor.info=editor.ids[editor.indexs[201]];
editor.mode.emenyitem();
editor.mode.floor();
editor.mode.tower();
editor.mode.listen();
editor_blockly=editor_blockly();
main.init('editor', function() {
editor.init(function(){
editor.pos={x: 0, y: 0};
editor.mode.loc();
editor.info=editor.ids[editor.indexs[201]];
editor.mode.emenyitem();
editor.mode.floor();
editor.mode.tower();
editor.mode.listen();
editor_blockly=editor_blockly();
});
});
//main.listen();
</script>

View File

@ -151,7 +151,7 @@ function core() {
/////////// 系统事件相关 ///////////
////// 初始化 //////
core.prototype.init = function (coreData) {
core.prototype.init = function (coreData, callback) {
for (var key in coreData) {
core[key] = coreData[key];
}
@ -281,6 +281,9 @@ core.prototype.init = function (coreData) {
core.material.icons.hero.height = core.material.images.hero.height/4;
core.setRequestAnimationFrame();
core.showStartAnimate();
if (core.isset(callback)) callback();
});
}

View File

@ -41,6 +41,7 @@ items.prototype.getItemEffect = function(itemId, itemNum) {
var itemCls = core.material.items[itemId].cls;
// 消耗品
if (itemCls === 'items') {
var ratio = parseInt(core.floors[core.status.floorId].item_ratio) || 1;
if (itemId in this.itemEffect)eval(this.itemEffect[itemId]);
}
else {
@ -50,6 +51,7 @@ items.prototype.getItemEffect = function(itemId, itemNum) {
////// “即捡即用类”道具的文字提示 //////
items.prototype.getItemEffectTip = function(itemId) {
var ratio = parseInt(core.floors[core.status.floorId].item_ratio) || 1;
if (itemId in this.itemEffectTip && (!this.items[itemId].isEquipment || !core.flags.equipment)) {
return eval(this.itemEffectTip[itemId]);
}

View File

@ -109,7 +109,7 @@ function main() {
this.canvas = {};
}
main.prototype.init = function (mode) {
main.prototype.init = function (mode, callback) {
for (var i = 0; i < main.dom.gameCanvas.length; i++) {
main.canvas[main.dom.gameCanvas[i].id] = main.dom.gameCanvas[i].getContext('2d');
}
@ -155,7 +155,7 @@ main.prototype.init = function (mode) {
"animates", "bgms", "sounds", "floorIds", "floors"].forEach(function (t) {
coreData[t] = main[t];
})
main.core.init(coreData);
main.core.init(coreData, callback);
main.core.resize(main.dom.body.clientWidth, main.dom.body.clientHeight);
});
});

View File

@ -43,6 +43,7 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
"weather": "该层的默认天气。本项可忽略表示晴天,如果写则第一项为\"rain\"或\"snow\"代表雨雪第二项为1-10之间的数代表强度。 \n$leaf(true)$end",
"bgm": "到达该层后默认播放的BGM。本项可忽略。 ",
//"map": "地图数据需要是13x13建议使用地图生成器来生成 ",
"item_ratio": "每一层的宝石/血瓶效果,即获得宝石和血瓶时框内\"ratio\"的值。",
"firstArrive": "第一次到该楼层触发的事件 \n$leaf(true)$end",
},
'loc' : {

View File

@ -13,6 +13,7 @@ main.floors.MT0 =
// "color": [0,0,0,0.3], // 该层的默认画面色调。本项可不写代表无色调如果写需要是一个RGBA数组。
// "weather": ["snow",5], // 该层的默认天气。本项可忽略表示晴天,如果写则第一项为"rain"或"snow"代表雨雪第二项为1-10之间的数代表强度。
// "bgm": "bgm.mp3", // 到达该层后默认播放的BGM。本项可忽略。
"item_ratio": 1, // 该层的宝石/血瓶倍率
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成
],

View File

@ -13,6 +13,7 @@ main.floors.sample0 =
// "color": [0,0,0,0.3] // 该层的默认画面色调。本项可不写代表无色调如果写需要是一个RGBA数组。
// "weather": ["snow",5], // 该层的默认天气。本项可忽略表示晴天,如果写则第一项为"rain"或"snow"代表雨雪第二项为1-10之间的数代表强度。
"bgm": "bgm.mp3", // 到达该层后默认播放的BGM。本项可忽略。
"item_ratio": 2, // 该层的宝石/血瓶倍率
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成
[0, 0, 220, 0, 0, 20, 87, 3, 65, 64, 44, 43, 42],
[0, 246, 0, 246, 0, 20, 0, 3, 58, 59, 60, 61, 41],

View File

@ -13,6 +13,7 @@ main.floors.sample1 =
// "color": [0,0,0,0.3] // 该层的默认画面色调。本项可不写代表无色调如果写需要是一个RGBA数组。
"weather": ["snow",6], // 该层的默认天气。本项可忽略表示晴天,如果写则第一项为"rain"或"snow"代表雨雪第二项为1-10之间的数代表强度。
// "bgm": "bgm.mp3", // 到达该层后默认播放的BGM。本项可忽略。
"item_ratio": 1, // 该层的宝石/血瓶倍率
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成
[7, 131, 8, 152, 9, 130, 10, 152, 166, 165, 132, 165, 166],
[0, 0, 0, 0, 0, 0, 0, 152, 165, 164, 0, 162, 165],

View File

@ -13,6 +13,7 @@ main.floors.sample2 =
"color": [255,0,0,0.3], // 该层的默认画面色调。本项可不写代表无色调如果写需要是一个RGBA数组。
"weather": ["rain",10], // 该层的默认天气。本项可忽略表示晴天,如果写则第一项为"rain"或"snow"代表雨雪第二项为1-10之间的数代表强度。
"bgm": "qianjin.mid", // 到达该层后默认播放的BGM。本项可忽略。
"item_ratio": 1, // 该层的宝石/血瓶倍率
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成
[5, 5, 5, 5, 5, 5, 87, 5, 5, 5, 5, 5, 5],
[5, 4, 4, 4, 4, 1, 0, 1, 4, 4, 4, 4, 5],

View File

@ -1,46 +0,0 @@
main.floors.test =
{
"floorId": "test", // 这里需要改楼层名请和文件名及下面的floorId保持完全一致
// 楼层唯一标识符仅能由字母、数字、下划线组成,且不能由数字开头
// 推荐用法第20层就用MT20第38层就用MT38地下6层就用MT_6用下划线代替负号隐藏3层用MT3hh表示隐藏等等
// 楼层唯一标识符,需要和名字完全一致
"title": "test", // 楼层中文名
"name": "", // 显示在状态栏中的层数
"canFlyTo": true, // 该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器)
"canUseQuickShop": true, // 该层是否允许使用快捷商店
"defaultGround": "ground", // 默认地面的图块IDterrains中
"map": [ // 地图数据需要是13x13建议使用地图生成器来生成
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201,201,201,201,201,201,201,201],
[201,201,201,201,201,201, 45,201,201,201,201,201,201],
[201,201,201,201,201,201, 0,201,201,201,201,201,201]
],
"firstArrive": [ // 第一次到该楼层触发的事件
],
"events": { // 该楼的所有可能事件列表
},
"changeFloor": { // 楼层转换事件该事件不能和上面的events有冲突同位置点否则会被覆盖
},
"afterBattle": { // 战斗后可能触发的事件列表
},
"afterGetItem": { // 获得道具后可能触发的事件列表
},
"afterOpenDoor": { // 开完门后可能触发的事件列表
}
}

View File

@ -62,16 +62,16 @@ items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
"itemEffect" : {
"redJewel":"core.status.hero.atk += core.values.redJewel",
"blueJewel":"core.status.hero.def += core.values.blueJewel",
"greenJewel":"core.status.hero.mdef += core.values.greenJewel",
"redJewel":"core.status.hero.atk += core.values.redJewel * ratio",
"blueJewel":"core.status.hero.def += core.values.blueJewel * ratio",
"greenJewel":"core.status.hero.mdef += core.values.greenJewel * ratio",
"yellowJewel":"core.status.hero.hp+=1000;core.status.hero.atk+=6;core.status.hero.def+=6;core.status.hero.mdef+=10;",
// 黄宝石属性:需自己定义
"redPotion":"core.status.hero.hp += core.values.redPotion",
"bluePotion":"core.status.hero.hp += core.values.bluePotion",
"yellowPotion":"core.status.hero.hp += core.values.yellowPotion",
"greenPotion":"core.status.hero.hp += core.values.greenPotion",
"redPotion":"core.status.hero.hp += core.values.redPotion * ratio",
"bluePotion":"core.status.hero.hp += core.values.bluePotion * ratio",
"yellowPotion":"core.status.hero.hp += core.values.yellowPotion * ratio",
"greenPotion":"core.status.hero.hp += core.values.greenPotion * ratio",
"sword1":"core.status.hero.atk += core.values.sword1",
"sword2":"core.status.hero.atk += core.values.sword2",
"sword3":"core.status.hero.atk += core.values.sword3",
@ -91,14 +91,14 @@ items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a =
"itemEffectTip" : {
"redJewel":"',攻击+'+core.values.redJewel",
"blueJewel":"',防御+'+core.values.blueJewel",
"greenJewel":"',魔防+'+core.values.greenJewel",
"redJewel":"',攻击+'+core.values.redJewel * ratio",
"blueJewel":"',防御+'+core.values.blueJewel * ratio",
"greenJewel":"',魔防+'+core.values.greenJewel * ratio",
"yellowJewel":"',全属性提升'",
"redPotion":"',生命+'+core.values.redPotion",
"bluePotion":"',生命+'+core.values.bluePotion",
"yellowPotion":"',生命+'+core.values.yellowPotion",
"greenPotion":"',生命+'+core.values.greenPotion",
"redPotion":"',生命+'+core.values.redPotion * ratio",
"bluePotion":"',生命+'+core.values.bluePotion * ratio",
"yellowPotion":"',生命+'+core.values.yellowPotion * ratio",
"greenPotion":"',生命+'+core.values.greenPotion * ratio",
"sword1":"',攻击+'+core.values.sword1",
"sword2":"',攻击+'+core.values.sword2",
"sword3":"',攻击+'+core.values.sword3",