Merge pull request #313 from zhaouv/common-event

Common event
This commit is contained in:
Zhang Chen 2019-02-02 10:44:41 +08:00 committed by GitHub
commit 4c785c668f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 185 additions and 158 deletions

View File

@ -1,5 +1,7 @@
# editor # editor
>! 以下均是v2.0时的说明, 未及时改动
本目录下所有文件,以及`../editor.html`和`../启动服务.exe`([源码](http://github.com/ckcz123/mota-js-server/))是地图编辑器的所有组件. 本目录下所有文件,以及`../editor.html`和`../启动服务.exe`([源码](http://github.com/ckcz123/mota-js-server/))是地图编辑器的所有组件.
`editor.js`,`editor_file.js`和`editor_mode.js`耦合较强,`editor_blockly.js`和`editor_multi.js`和`fs.js`基本可以独立使用. `editor.js`,`editor_file.js`和`editor_mode.js`耦合较强,`editor_blockly.js`和`editor_multi.js`和`fs.js`基本可以独立使用.
@ -103,23 +105,6 @@ editor_mode.onmode(editor_mode._ids[node.getAttribute('id')]);
`editor.mode.listen`中提供了追加素材的支持. `editor.mode.listen`中提供了追加素材的支持.
处理注释的特殊指令
```
$range(evalstr:thiseval)$end
限制取值范围,要求修改后的eval(evalstr)为true
$leaf(evalstr:thiseval)$end
强制指定为叶节点,如果eval(evalstr)为true
//以下几个中选一个 [
$select(evalstr)$end
渲染成<select>,选项为数组eval(evalstr)['values']
$input(evalstr)$end
渲染成<input>
$textarea(evalstr)$end
渲染成<textarea>
默认选项为$textarea()$end
// ]
```
### editor_blockly.js ### editor_blockly.js
@ -177,9 +162,3 @@ fs.readdir(path, callback)
//所有参数不允许缺省 //所有参数不允许缺省
``` ```
## z-index
目前主体部分使用了 0-15,75,100
blockly使用 200,201
多行文本编辑器使用 300

View File

@ -26,17 +26,6 @@ code=JSON.stringify(code,null,2).split('"data_asdfefw"').join('[\n'+action_0+']\
return code; return code;
*/; */;
//加点 事件编辑器入口之一
point_m
: '加点' BGNL? Newline choicesContext+ BEND
/* point_m
tooltip : 加点事件
helpUrl : https://h5mota.com/games/template/docs/#/event?id=%e5%8a%a0%e7%82%b9%e4%ba%8b%e4%bb%b6
var code = '{"type": "choices", "choices": [\n'+choicesContext_0+']}\n';
return code;
*/;
//升级 事件编辑器入口之一 //升级 事件编辑器入口之一
level_m level_m
@ -217,6 +206,18 @@ var code = '{"floorId": "'+toFloorId+'"'+loc+DirectionEx_List_0+Int_0+Bool_0+' }
return code; return code;
*/; */;
//commonEvent 事件编辑器入口之一
commonEvent_m
: '公共事件' BGNL? Newline action+ BEND
/* commonEvent_m
tooltip : 公共事件
helpUrl : https://h5mota.com/games/template/docs/#/event
var code = '[\n'+action_0+']\n';
return code;
*/;
//为了避免关键字冲突,全部加了_s //为了避免关键字冲突,全部加了_s
//动作 //动作
action action
@ -1960,15 +1961,6 @@ ActionParser.prototype.parse = function (obj,type) {
obj.time,!this.isset(obj.portalWithoutTrigger) obj.time,!this.isset(obj.portalWithoutTrigger)
]); ]);
case 'point':
if(!obj)obj={};
var text_choices = null;
for(var ii=obj.choices.length-1,choice;choice=obj.choices[ii];ii--) {
text_choices=MotaActionBlocks['choicesContext'].xmlText([
choice.text,this.parseList(choice.action),text_choices]);
}
return MotaActionBlocks['point_m'].xmlText([text_choices]);
case 'level': case 'level':
if(!obj)obj={}; if(!obj)obj={};
var text_choices = null; var text_choices = null;

View File

@ -62,6 +62,7 @@ editor.prototype.init = function (callback) {
editor.mode.floor(); editor.mode.floor();
editor.mode.tower(); editor.mode.tower();
editor.mode.functions(); editor.mode.functions();
editor.mode.commonevent();
editor.mode.showMode('tower'); editor.mode.showMode('tower');
editor_multi = editor_multi(); editor_multi = editor_multi();

View File

@ -23,17 +23,6 @@ editor_blockly = function () {
{"type": "hide", "time": 500}, {"type": "hide", "time": 500},
],'event'), ],'event'),
MotaActionBlocks['changeFloor_m'].xmlText(), MotaActionBlocks['changeFloor_m'].xmlText(),
//MotaActionFunctions.actionParser.parse({"type": "choices", "choices": [
// {"text": "攻击+\${point}", "action": [
// {"type": "setValue", "name": "status:atk", "value": "status:atk+\${point}"},
// ]},
// {"text": "防御+\${2*point}", "action": [
// {"type": "setValue", "name": "status:def", "value": "status:def+\${2*point}"},
// ]},
// {"text": "生命+\${200*point}", "action": [
// {"type": "setValue", "name": "status:hp", "value": "status:hp+\${200*point}"},
// ]},
//]},'point'),
MotaActionFunctions.actionParser.parse([{ MotaActionFunctions.actionParser.parse([{
"id": "moneyShop1", "id": "moneyShop1",
"name": "贪婪之神", "name": "贪婪之神",
@ -55,6 +44,7 @@ editor_blockly = function () {
MotaActionBlocks['firstArrive_m'].xmlText(), MotaActionBlocks['firstArrive_m'].xmlText(),
MotaActionBlocks['eachArrive_m'].xmlText(), MotaActionBlocks['eachArrive_m'].xmlText(),
MotaActionBlocks['level_m'].xmlText(), MotaActionBlocks['level_m'].xmlText(),
MotaActionBlocks['commonEvent_m'].xmlText(),
], ],
'显示文字':[ '显示文字':[
MotaActionBlocks['text_0_s'].xmlText(), MotaActionBlocks['text_0_s'].xmlText(),

View File

@ -7,6 +7,7 @@ editor_file = function (editor, callback) {
'comment': 'comment', 'comment': 'comment',
'data.comment': 'dataComment', 'data.comment': 'dataComment',
'functions.comment': 'functionsComment', 'functions.comment': 'functionsComment',
'events.comment': 'eventsComment',
} }
for (var key in commentjs) { for (var key in commentjs) {
(function (key) { (function (key) {
@ -49,25 +50,7 @@ editor_file = function (editor, callback) {
throw('未设置callback') throw('未设置callback')
} }
; ;
/* var fs = editor.fs;
fs.readFile('project/floors/'+filename+'.js','utf-8',function(err, data){
if (err!=null){callback(err);return;}
data=data.split('=');
data=[data[0],data.slice(1).join('=')];
var varnameId = data[0].split('.').slice(-1)[0].trim();
var filenameId = filename.split('/').slice(-1)[0].split('\\').slice(-1)[0];
eval('b3917d1d_71c2_41f2_a8aa_481b215ffb99='+data[1]);
var floorData = b3917d1d_71c2_41f2_a8aa_481b215ffb99;
delete(b3917d1d_71c2_41f2_a8aa_481b215ffb99);
var floorId = floorData.floorId;
if (varnameId!=filenameId || filenameId!=floorId){
callback('文件名,第一行的变量名以及floorId不一致');
return;
}
editor.currentFloorId = floorId;
editor.currentFloorData = floorData;
callback(null)
}); */
editor.currentFloorId = editor.core.status.floorId; editor.currentFloorId = editor.core.status.floorId;
editor.currentFloorData = editor.core.floors[editor.currentFloorId]; editor.currentFloorData = editor.core.floors[editor.currentFloorId];
} }
@ -833,6 +816,39 @@ editor_file = function (editor, callback) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
editor_file.editCommonEvent = function (actionList, callback) {
/*actionList:[
["change","['test']",['123']],
]
[]时只查询不修改
*/
var data_obj = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent;
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) {
value[1] = "['commonEvent']" + value[1];
});
saveSetting('events', actionList, function (err) {
callback([
Object.assign({},data_obj),
editor_file.eventsComment._data.commonEvent,
err]);
});
} else {
callback([
Object.assign({},data_obj),
editor_file.eventsComment._data.commonEvent,
null]);
}
}
//callback([obj,commentObj,err:String])
////////////////////////////////////////////////////////////////////
var isset = function (val) { var isset = function (val) {
if (val == undefined || val == null) { if (val == undefined || val == null) {
return false; return false;
@ -996,37 +1012,20 @@ editor_file = function (editor, callback) {
editor_file.saveFloorFile(callback); editor_file.saveFloorFile(callback);
return; return;
} }
if (file == 'events') {
actionList.forEach(function (value) {
eval("events_c12a15a8_c380_4b28_8144_256cba95f760" + value[1] + '=' + JSON.stringify(value[2]));
});
var datastr = 'var events_c12a15a8_c380_4b28_8144_256cba95f760 = \n';
datastr += JSON.stringify(events_c12a15a8_c380_4b28_8144_256cba95f760, null, '\t');
fs.writeFile('project/events.js', encode(datastr), 'base64', function (err, data) {
callback(err);
});
return;
}
callback('出错了,要设置的文件名不识别'); callback('出错了,要设置的文件名不识别');
} }
/*
$select({\"values\":[\"keys\",\"items\",\"constants\",\"tools\"]})$end
$range(thiseval==~~thiseval &&thiseval>0)$end
$leaf(true)$end
$select({\"values\":[true]})$end
$select({\"values\":[false]})$end
$select({\"values\":[true,false]})$end
*/
/*
所有注释中的特殊指令
$range(evalstr:thiseval)$end
限制取值范围,要求修改后的eval(evalstr)为true
$leaf(evalstr:thiseval)$end
强制指定为叶节点,如果eval(evalstr)为true
//以下几个中选一个 [
$select(evalstr)$end
渲染成<select>,选项为数组eval(evalstr)['values']
$input(evalstr)$end
渲染成<input>
$textarea(evalstr)$end
渲染成<textarea>
默认选项为$textarea()$end
// ]
*/
return editor_file; return editor_file;
} }
//editor_file = editor_file(editor); //editor_file = editor_file(editor);

View File

@ -11,6 +11,8 @@ editor_mode = function (editor) {
'map': 'left', 'map': 'left',
'appendpic': 'left1', 'appendpic': 'left1',
'commonevent': 'left9',
} }
this._ids = {} this._ids = {}
this.dom = {} this.dom = {}
@ -341,75 +343,40 @@ editor_mode = function (editor) {
editor_mode.prototype.doActionList = function (mode, actionList) { editor_mode.prototype.doActionList = function (mode, actionList) {
if (actionList.length == 0) return; if (actionList.length == 0) return;
printf('修改中...'); printf('修改中...');
var cb=function(objs_){
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功');
}
switch (mode) { switch (mode) {
case 'loc': case 'loc':
editor.file.editLoc(editor_mode.pos.x, editor_mode.pos.y, actionList, function (objs_) {
editor.file.editLoc(editor_mode.pos.x, editor_mode.pos.y, actionList, function (objs_) {//console.log(objs_); cb(objs_);
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功');
editor.drawPosSelection(); editor.drawPosSelection();
}); });
break; break;
case 'enemyitem': case 'enemyitem':
if (editor_mode.info.images == 'enemys' || editor_mode.info.images == 'enemy48') { if (editor_mode.info.images == 'enemys' || editor_mode.info.images == 'enemy48') {
editor.file.editEnemy(editor_mode.info.id, actionList, function (objs_) {//console.log(objs_); editor.file.editEnemy(editor_mode.info.id, actionList, cb);
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
} else if (editor_mode.info.images == 'items') { } else if (editor_mode.info.images == 'items') {
editor.file.editItem(editor_mode.info.id, actionList, function (objs_) {//console.log(objs_); editor.file.editItem(editor_mode.info.id, actionList, cb);
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
} else { } else {
editor.file.editMapBlocksInfo(editor_mode.info.idnum, actionList, function (objs_) {//console.log(objs_); editor.file.editMapBlocksInfo(editor_mode.info.idnum, actionList, cb);
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功');
});
} }
break; break;
case 'floor': case 'floor':
editor.file.editFloor(actionList, cb);
editor.file.editFloor(actionList, function (objs_) {//console.log(objs_);
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功');
});
break; break;
case 'tower': case 'tower':
editor.file.editTower(actionList, cb);
editor.file.editTower(actionList, function (objs_) {//console.log(objs_);
if (objs_.slice(-1)[0] != null) {
printe(objs_.slice(-1)[0]);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
break; break;
case 'functions': case 'functions':
editor.file.editFunctions(actionList, cb);
editor.file.editFunctions(actionList, function (objs_) {//console.log(objs_); break;
if (objs_.slice(-1)[0] != null) { case 'commonevent':
printe(objs_.slice(-1)[0]); editor.file.editCommonEvent(actionList, cb);
throw(objs_.slice(-1)[0])
}
;printf('修改成功')
});
break; break;
default: default:
break; break;
@ -540,6 +507,19 @@ editor_mode = function (editor) {
if (Boolean(callback)) callback(); if (Boolean(callback)) callback();
} }
editor_mode.prototype.commonevent = function (callback) {
var objs = [];
editor.file.editCommonEvent([], function (objs_) {
objs = objs_;
//console.log(objs_)
});
//只查询不修改时,内部实现不是异步的,所以可以这么写
var tableinfo = editor_mode.objToTable_(objs[0], objs[1]);
document.getElementById('table_b7bf0124_99fd_4af8_ae2f_0017f04a7c7d').innerHTML = tableinfo.HTML;
tableinfo.listen(tableinfo.guids);
if (Boolean(callback)) callback();
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
editor_mode.prototype.listen = function (callback) { editor_mode.prototype.listen = function (callback) {

36
_server/events.comment.js Normal file
View File

@ -0,0 +1,36 @@
var events_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
{
"_type": "object",
"_data": {
"commonEvent": {
"_type": "object",
"_data": function (key) {
var obj = {
"addPoint": {
"_leaf": true,
"_type": "event",
"_range": "thiseval instanceof Array",
"_event": "commonEvent",
"_data": "加点事件,可以双击进入事件编辑器"
},
"test": {
"_leaf": true,
"_type": "event",
"_range": "thiseval instanceof Array",
"_event": "commonEvent",
"_data": "测试事件, events.comment.js中标记了_range不能为null, 所以应该无法删除"
},
}
if (obj[key]) return obj[key];
return {
"_leaf": true,
"_type": "event",
"_event": "commonEvent",
"_data": "自定义公共事件,可以双击进入事件编辑器"
}
}
}
}
}

View File

@ -1,4 +1,4 @@
var maps_comment_90f36752_8815_4be8_b32b_d7fad1d0542e = var maps_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
{ {
////////////////////////// 地形部分 ////////////////////////// ////////////////////////// 地形部分 //////////////////////////

View File

@ -185,7 +185,6 @@
<select id="entryType" disabled="disabled" style="display: none"> <select id="entryType" disabled="disabled" style="display: none">
<option value="event">event</option> <option value="event">event</option>
<option value="changeFloor">changeFloor</option> <option value="changeFloor">changeFloor</option>
<option value="point">point</option>
<option value="level">level</option> <option value="level">level</option>
<option value="shop">shop</option> <option value="shop">shop</option>
<option value="afterBattle">afterBattle</option> <option value="afterBattle">afterBattle</option>
@ -193,6 +192,7 @@
<option value="afterOpenDoor">afterOpenDoor</option> <option value="afterOpenDoor">afterOpenDoor</option>
<option value="firstArrive">firstArrive</option> <option value="firstArrive">firstArrive</option>
<option value="eachArrive">eachArrive</option> <option value="eachArrive">eachArrive</option>
<option value="commonEvent">commonEvent</option>
</select> </select>
<button onclick="editor_blockly.confirm()">确认</button> <button onclick="editor_blockly.confirm()">确认</button>
<button onclick="editor_blockly.parse()">解析</button> <button onclick="editor_blockly.parse()">解析</button>
@ -242,6 +242,23 @@
</div> </div>
</div> </div>
</div> </div>
<div id="left9" class='leftTab' style="z-index:-1;opacity: 0;"><!-- commonevent -->
<h3 class="leftTabHeader">公共事件&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('add')">添加</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('delete')">删除</button>
</h3>
<div class="leftTabContent">
<div class='etable'>
<table>
<tbody id='table_b7bf0124_99fd_4af8_ae2f_0017f04a7c7d'>
<tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="mid"> <div id="mid">
<div class="col" id='mapColMark'></div> <div class="col" id='mapColMark'></div>
<div class="row" id='mapRowMark'></div> <div class="row" id='mapRowMark'></div>
@ -309,6 +326,7 @@
<option value="tower">全塔属性</option> <option value="tower">全塔属性</option>
<option value="functions">脚本编辑</option> <option value="functions">脚本编辑</option>
<option value="appendpic">追加素材</option> <option value="appendpic">追加素材</option>
<option value="commonevent">公共事件</option>
</select> </select>
<select id="brushMod" style="clear:right"> <select id="brushMod" style="clear:right">
<option value="line">画线</option> <option value="line">画线</option>

View File

@ -181,7 +181,6 @@
<select id="entryType" disabled="disabled" style="display: none"> <select id="entryType" disabled="disabled" style="display: none">
<option value="event">event</option> <option value="event">event</option>
<option value="changeFloor">changeFloor</option> <option value="changeFloor">changeFloor</option>
<option value="point">point</option>
<option value="level">level</option> <option value="level">level</option>
<option value="shop">shop</option> <option value="shop">shop</option>
<option value="afterBattle">afterBattle</option> <option value="afterBattle">afterBattle</option>
@ -189,6 +188,7 @@
<option value="afterOpenDoor">afterOpenDoor</option> <option value="afterOpenDoor">afterOpenDoor</option>
<option value="firstArrive">firstArrive</option> <option value="firstArrive">firstArrive</option>
<option value="eachArrive">eachArrive</option> <option value="eachArrive">eachArrive</option>
<option value="commonEvent">commonEvent</option>
</select> </select>
<button onclick="editor_blockly.confirm()">确认</button> <button onclick="editor_blockly.confirm()">确认</button>
<button onclick="editor_blockly.parse()">解析</button> <button onclick="editor_blockly.parse()">解析</button>
@ -238,6 +238,23 @@
</div> </div>
</div> </div>
</div> </div>
<div id="left9" class='leftTab' style="z-index:-1;opacity: 0;"><!-- commonevent -->
<h3 class="leftTabHeader">公共事件&nbsp;&nbsp;<button onclick="editor.mode.onmode('save')">保存</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('add')">添加</button>&nbsp;&nbsp;<button onclick="editor.mode.changeDoubleClickModeByButton('delete')">删除</button>
</h3>
<div class="leftTabContent">
<div class='etable'>
<table>
<tbody id='table_b7bf0124_99fd_4af8_ae2f_0017f04a7c7d'>
<tr>
<td>条目</td>
<td>注释</td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="mid"> <div id="mid">
<table class="col" id='mapColMark'></table> <table class="col" id='mapColMark'></table>
<table class="row" id='mapRowMark'></table> <table class="row" id='mapRowMark'></table>
@ -277,6 +294,7 @@
<option value="tower">全塔属性</option> <option value="tower">全塔属性</option>
<option value="functions">脚本编辑</option> <option value="functions">脚本编辑</option>
<option value="appendpic">追加素材</option> <option value="appendpic">追加素材</option>
<option value="commonevent">公共事件</option>
</select> </select>
<br/> <br/>
<span style="font-size: 12px;"> <span style="font-size: 12px;">

View File

@ -75,7 +75,7 @@ function main() {
'loader', 'control', 'utils', 'items', 'icons', 'maps', 'enemys', 'events', 'actions', 'data', 'ui', 'core' 'loader', 'control', 'utils', 'items', 'icons', 'maps', 'enemys', 'events', 'actions', 'data', 'ui', 'core'
]; ];
this.pureData = [ this.pureData = [
'data', 'enemys', 'icons', 'maps', 'items', 'functions' 'data', 'enemys', 'icons', 'maps', 'items', 'functions', 'events'
]; ];
this.materials = [ this.materials = [
'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains', 'enemy48', 'npc48' 'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains', 'enemy48', 'npc48'

14
project/events.js Normal file
View File

@ -0,0 +1,14 @@
var events_c12a15a8_c380_4b28_8144_256cba95f760 =
{
"commonEvent": {
"addPoint": [
""
],
"test": [
"应该无法删除"
],
"test2": [
"应该可以删除"
]
}
}