diff --git a/2.0diff.md b/2.0diff.md index 0f9ad4eb..814b4b04 100644 --- a/2.0diff.md +++ b/2.0diff.md @@ -12,8 +12,10 @@ + 重命名为`editor.html` * 需要相应的修改本地服务的按钮打开的网址,为了兼容,临时加了个内容为``的`drawMapGUI.html` + 不再独立的导入数据和画图,尽可能的通过`main.init('editor')`复用代码 -+ 能够在本地服务器环境中直接修改`project`中的数据,目前只完成了文件操作的代码`_server/editor_file.js`,前端尚未完成 ++ 能够在本地服务器环境中直接修改`project`中的数据,即全GUI下做塔 + 把`editor`的代码拆到了`_server/editor.js`中 ++ 添加了`_server/css/editor_mode.css`存放编辑模式有关的样式 ++ 添加了`_server/editor_mode.js`存放编辑模式的实现 ## 具体: @@ -24,7 +26,7 @@ `main.listen`和`main.init`改为在`index.html`中执行 -添加了`main.prototype.loadPureData`,在`main.init`中先加载存数据再加载`libs` +添加了`main.prototype.loadPureData`,在`main.init`中先加载纯数据再加载`libs` ### core.js `core.drawMap`中`editor`模式下不再画图,而是生成画图的函数提供给`editor` @@ -74,7 +76,35 @@ editor.file.editFloor(editor,[["change","['title']",'样板 33 层']],function(a editor.file.editTower(editor,[["change","['values']['lavaDamage']",200]],function(a){console.log(a)}); ``` +### editor_mode.js +4个生成表格并绑定事件的函数 +```javascript +editor_mode.loc(); +editor_mode.emenyitem(); +editor_mode.floor(); +editor_mode.tower(); +``` +切换模式 +```javascript +editor_mode.onmode(''); +editor_mode.onmode('loc'); +editor_mode.onmode('emenyitem'); +editor_mode.onmode('floor'); +editor_mode.onmode('tower'); +``` +在切换模式时,改动才会保存到文件,并且需要刷新页面使得`editor`能看到改动 + +表格的`onchange`的实现中,获得当前模式的方式.不注意的话,修改`index.html`中页面的结构,会被坑 +```javascript +var node = thisTr.parentNode; +while (!editor_mode._ids.hasOwnProperty(node.getAttribute('id'))) { + node = node.parentNode; +} +editor_mode.onmode(editor_mode._ids[node.getAttribute('id')]); +``` ### drawMapGUI.html +重命名为`editor.html` + 把`editor`的代码拆到了`_server/editor.js`中 以`display:none`的形式引入了`index.html`的`dom`,修改了原来的`.gameCanvas #ui #data`等的名字以避免冲突 @@ -96,26 +126,27 @@ $range(evalstr:thiseval)$end $leaf(evalstr:thiseval)$end 强制指定为叶节点,如果eval(evalstr)为true -todo: //以下几个中选一个 [ $select(evalstr)$end 渲染成,此为默认选项 +$input(evalstr)$end + 渲染成 $textarea(evalstr)$end - 渲染成\n'].join(''); + } +} + +editor_mode.prototype.guid = function() { + return 'id_'+'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); + return v.toString(16); + }); +} + +editor_mode.prototype.addAction = function(action){ + editor_mode.actionList.push(action); +} + +editor_mode.prototype.doActionList = function(mode,actionList){ + if (actionList.length==0)return; + switch (mode) { + case 'loc': + + editor_file.editLoc(editor,editor_mode.pos.x,editor_mode.pos.y,actionList,function(objs_){console.log(objs_);if(objs_.slice(-1)[0]!=null)throw(objs_.slice(-1)[0])}); + break; + case 'emenyitem': + + if (editor_mode.info.images=='enemys'){ + editor_file.editEnemy(editor,editor_mode.info.id,actionList,function(objs_){console.log(objs_);if(objs_.slice(-1)[0]!=null)throw(objs_.slice(-1)[0])}); + } else if (editor_mode.info.images=='items'){ + editor_file.editItem(editor,editor_mode.info.id,actionList,function(objs_){console.log(objs_);if(objs_.slice(-1)[0]!=null)throw(objs_.slice(-1)[0])}); + } + break; + case 'floor': + + editor_file.editFloor(editor,actionList,function(objs_){console.log(objs_);if(objs_.slice(-1)[0]!=null)throw(objs_.slice(-1)[0])}); + break; + case 'tower': + + editor.file.editTower(editor,actionList,function(objs_){console.log(objs_);if(objs_.slice(-1)[0]!=null)throw(objs_.slice(-1)[0])}); + break; + default: + break; + } +} + +editor_mode.prototype.onmode = function (mode) { + if (editor_mode.mode!=mode) { + console.log('change mode into : '+mode); + editor_mode.doActionList(editor_mode.mode,editor_mode.actionList); + editor_mode.mode=mode; + editor_mode.actionList=[]; + } +} + +editor_mode.prototype.loc = function(callback){ + //editor.pos={x: 0, y: 0}; + if (!core.isset(editor.pos))return; + editor_mode.pos=editor.pos; + document.getElementById('pos_a6771a78_a099_417c_828f_0a24851ebfce').innerText=editor_mode.pos.x+','+editor_mode.pos.y; + + var objs=[]; + editor_file.editLoc(editor,editor_mode.pos.x,editor_mode.pos.y,[],function(objs_){objs=objs_;console.log(objs_)}); + //只查询不修改时,内部实现不是异步的,所以可以这么写 + var tableinfo=editor_mode.objToTable(objs[0],objs[1]); + document.getElementById('table_3d846fc4_7644_44d1_aa04_433d266a73df').innerHTML=tableinfo.HTML; + tableinfo.listen(tableinfo.guids); + + if (Boolean(callback))callback(); +} + +editor_mode.prototype.emenyitem = function(callback){ + //editor.info=editor.ids[editor.indexs[201]]; + if (!core.isset(editor.info))return; + editor_mode.info=editor.info;//避免editor.info被清空导致无法获得是物品还是怪物 + + if (!core.isset(editor_mode.info.id)){ + document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML=''; + document.getElementById('newIdIdnum').style.display=''; + return; + } + document.getElementById('newIdIdnum').style.display='none'; + + var objs=[]; + if (editor_mode.info.images=='enemys'){ + editor_file.editEnemy(editor,editor_mode.info.id,[],function(objs_){objs=objs_;console.log(objs_)}); + } else if (editor_mode.info.images=='items'){ + editor_file.editItem(editor,editor_mode.info.id,[],function(objs_){objs=objs_;console.log(objs_)}); + } else { + document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML=''; + return; + } + //只查询不修改时,内部实现不是异步的,所以可以这么写 + var tableinfo=editor_mode.objToTable(objs[0],objs[1]); + document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML=tableinfo.HTML; + tableinfo.listen(tableinfo.guids); + + if (Boolean(callback))callback(); +} + +editor_mode.prototype.floor = function(callback){ + var objs=[]; + editor_file.editFloor(editor,[],function(objs_){objs=objs_;console.log(objs_)}); + //只查询不修改时,内部实现不是异步的,所以可以这么写 + var tableinfo=editor_mode.objToTable(objs[0],objs[1]); + document.getElementById('table_4a3b1b09_b2fb_4bdf_b9ab_9f4cdac14c74').innerHTML=tableinfo.HTML; + tableinfo.listen(tableinfo.guids); + if (Boolean(callback))callback(); +} + +editor_mode.prototype.tower = function(callback){ + var objs=[]; + editor.file.editTower(editor,[],function(objs_){objs=objs_;console.log(objs_)}); + //只查询不修改时,内部实现不是异步的,所以可以这么写 + var tableinfo=editor_mode.objToTable(objs[0],objs[1]); + document.getElementById('table_b6a03e4c_5968_4633_ac40_0dfdd2c9cde5').innerHTML=tableinfo.HTML; + tableinfo.listen(tableinfo.guids); + if (Boolean(callback))callback(); +} + +editor_mode.prototype.listen = function(callback){ + + var newIdIdnum = document.getElementById('newIdIdnum'); + newIdIdnum.children[0].onchange = newIdIdnum.children[1].onchange = function(){ + if (newIdIdnum.children[0].value && newIdIdnum.children[1].value){ + var id = newIdIdnum.children[0].value; + var idnum = parseInt(newIdIdnum.children[1].value); + editor_file.changeIdAndIdnum(editor,id,idnum,editor_mode.info,function(err){if(err)throw(err)}); + } + } + //尚未完成,不完善,新物品需要手动改items,新地形的支持不错 + + var selectFloor = document.getElementById('selectFloor'); + editor_file.getFloorFileList(editor,function(floors){ + var outstr=[]; + floors[0].forEach(function(floor){ + outstr.push(["\n'].join('')); + }); + selectFloor.innerHTML=outstr.join(''); + selectFloor.onchange = function(){ + editor_mode.onmode(''); + editor.changeFloor(selectFloor.value); + } + }); + + var saveFloor = document.getElementById('saveFloor'); + saveFloor.onclick = function(){ + editor_mode.onmode(''); + editor_file.saveFloorFile(editor,function(err){if(err)throw(err)}); + } + + var saveFloorAs = document.getElementById('saveFloorAs'); + var saveAsName = document.getElementById('saveAsName'); + saveFloorAs.onclick = function(){ + if (!saveAsName.value)return; + editor_mode.onmode(''); + editor_file.saveFloorFileAs(editor,saveAsName.value,function(err){ + if(err)throw(err); + core.floorIds.push(saveAsName.value); + editor.file.editTower(editor,[['change',"['main']['floorIds']",core.floorIds]],function(objs_){console.log(objs_);if(objs_.slice(-1)[0]!=null)throw(objs_.slice(-1)[0])}); + }); + } + + if (Boolean(callback))callback(); +} + +editor_mode = new editor_mode(); +editor_mode.init(); \ No newline at end of file diff --git a/_server/vm.js b/_server/vm.js index ba4e640e..3ae26442 100644 --- a/_server/vm.js +++ b/_server/vm.js @@ -2,6 +2,7 @@ document.body.onmousedown = function(e){ selectBox.isSelected = false; + editor_mode.onmode(''); editor.info = {}; } iconLib.onmousedown = function(e){ diff --git a/editor.html b/editor.html index 3b0f15cf..1d03c983 100644 --- a/editor.html +++ b/editor.html @@ -3,6 +3,7 @@ +
@@ -15,6 +16,10 @@

{{ errors[error-1] }}

+
+ + +
@@ -26,6 +31,86 @@ +
+
+

测试用标签页

+
+ + + + + + + + + +
条目注释aaa
变量名字符串可能显示不全但是hover时通过span title='xxx'来显示高度以此为准
此处是利用slice实现
+
+
+ + + + + + + +
条目注释
+
+
+ +
+
+
+
+

地图选点

+

0,0

+
+ + + + +
条目注释
+
+
+
+

图块属性

+
+ + +
+
+
+ + + + +
条目注释
+
+
+
+
+

楼层属性

+
+ + + + +
条目注释
+
+
+
+

全塔属性

+
+ + + + +
条目注释
+
+
@@ -201,11 +286,12 @@ + diff --git a/project/comment.js b/project/comment.js index 780f32f9..fe2726a1 100644 --- a/project/comment.js +++ b/project/comment.js @@ -2,7 +2,7 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "items" : { 'items':{ - 'cls': "只能取keys(钥匙) items(宝石、血瓶) constants(物品) tools(道具)\n$range(thiseval in ['keys','items','constants','tools'])$end", + 'cls': "只能取keys(钥匙) items(宝石、血瓶) constants(物品) tools(道具)\n$select({\"values\":[\"keys\",\"items\",\"constants\",\"tools\"]})$end", 'name': '名称', 'text': '道具在道具栏中显示的描述' }, @@ -16,21 +16,21 @@ comment_c456ea59_6018_45ef_8bcc_211a24c627dc = 'def': '防御力', 'money': '金币', 'experience': '经验', - 'special': '特殊属性\n0:无,1:先攻,2:魔攻,3:坚固,4:2连击,5:3连击,6:n连击,7:破甲,8:反击,9:净化,10:模仿,11:吸血,12:中毒,13:衰弱,14:诅咒,15:领域,16:夹击,17:仇恨,18:阻击,19:自爆,20:无敌\n多个属性例如用[1,4,11]表示先攻2连击吸血\n模仿怪的攻防设为0就好\n$leaf(true)$end', + 'special': '特殊属性\n\n0:无,1:先攻,2:魔攻,3:坚固,4:2连击,\n5:3连击,6:n连击,7:破甲,8:反击,9:净化,\n10:模仿,11:吸血,12:中毒,13:衰弱,14:诅咒,\n15:领域,16:夹击,17:仇恨,18:阻击,19:自爆,\n20:无敌\n\n多个属性例如用[1,4,11]表示先攻2连击吸血\n模仿怪的攻防设为0就好\n$leaf(true)$end', 'value': '特殊属性的数值\n领域怪需要加value表示领域伤害的数值\n吸血怪需要在后面添加value代表吸血比例', 'zoneSquare': '领域怪zoneSquare代表是否九宫格伤害', - 'range': 'range可选,代表领域伤害的范围;不加默认为1\n$range(thiseval==~~thiseval &&thiseval>0)$end', - 'bomb':' 加入 "bomb": false 代表该怪物不可被炸弹或圣锤炸掉\n$range(thiseval in [true,false])$end', - 'point': 'point可以在打败怪物后进行加点,详见文档说明\n$range(thiseval==~~thiseval && thiseval>0)$end', - 'n': '多连击需要在后面指定n代表是几连击\n$range(thiseval==~~thiseval &&thiseval>0)$end', + 'range': 'range可选,代表领域伤害的范围;不加默认为1\n$range((thiseval==~~thiseval && thiseval>0)||thiseval==null)$end', + 'bomb':' 加入 "bomb": false 代表该怪物不可被炸弹或圣锤炸掉\n$select({\"values\":[true,false]})$end', + 'point': 'point可以在打败怪物后进行加点,详见文档说明\n$range((thiseval==~~thiseval && thiseval>0)||thiseval==null)$end', + 'n': '多连击需要在后面指定n代表是几连击\n$range((thiseval==~~thiseval && thiseval>0)||thiseval==null)$end', }, "floors" : { 'floor' : { "floorId": "文件名和floorId需要保持完全一致 \n楼层唯一标识符仅能由字母、数字、下划线组成,且不能由数字开头 \n推荐用法:第20层就用MT20,第38层就用MT38,地下6层就用MT_6(用下划线代替负号),隐藏3层用MT3h(h表示隐藏),等等 \n楼层唯一标识符,需要和名字完全一致 \n这里不能更改floorId,请通过另存为来实现\n$range(false)$end", "title": "楼层中文名 ", "name": "显示在状态栏中的层数 ", - "canFlyTo": "该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器) \n$range(thiseval in [true,false])$end", - "canUseQuickShop": "该层是否允许使用快捷商店 \n$range(thiseval in [true,false])$end", + "canFlyTo": "该楼能否被楼传器飞到(不能的话在该楼也不允许使用楼传器) \n$select({\"values\":[true,false]})$end", + "canUseQuickShop": "该层是否允许使用快捷商店 \n$select({\"values\":[true,false]})$end", "defaultGround": "默认地面的图块ID(terrains中) ", "png": "背景图;你可以选择一张png图片来作为背景素材。详细用法请参见文档“自定义素材”中的说明。 ", "color": "该层的默认画面色调。本项可不写(代表无色调),如果写需要是一个RGBA数组。 \n$leaf(true)$end", diff --git a/project/data.comment.js b/project/data.comment.js index aff279fe..22a42c9c 100644 --- a/project/data.comment.js +++ b/project/data.comment.js @@ -1,7 +1,7 @@ data_comment_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = { "main": { - "useCompress": " 是否使用压缩文件 \n 当你即将发布你的塔时,请使用“JS代码压缩工具”将所有js代码进行压缩,然后将这里的useCompress改为true。 \n 请注意,只有useCompress是false时才会读取floors目录下的文件,为true时会直接读取libs目录下的floors.min.js文件。 \n 如果要进行剧本的修改请务必将其改成false。 ", + "useCompress": " 是否使用压缩文件 \n 当你即将发布你的塔时,请使用“JS代码压缩工具”将所有js代码进行压缩,然后将这里的useCompress改为true。 \n 请注意,只有useCompress是false时才会读取floors目录下的文件,为true时会直接读取libs目录下的floors.min.js文件。 \n 如果要进行剧本的修改请务必将其改成false。 \n$select({\"values\":[false]})$end", "floorIds": " 在这里按顺序放所有的楼层;其顺序直接影响到楼层传送器的顺序和上楼器/下楼器的顺序 \n$leaf(true)$end", "pngs": " 在此存放所有可能的背景图片;背景图片最好是416*416像素,其他分辨率会被强制缩放成416*416 \n 建议对于较大的图片,在网上使用在线的“图片压缩工具”来进行压缩,以节省流量 \n 有关使用自定义背景图,请参见文档的“自定义素材”说明 \n\n 依次向后添加 \n$leaf(true)$end", "bgms": " 在此存放所有的bgm,和文件名一致。第一项为默认播放项 \n 音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好 \n$leaf(true)$end", @@ -14,7 +14,7 @@ data_comment_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "floorId": " 初始楼层ID ", "hero": { "name": " 勇士初始数据 \n 勇士名;可以改成喜欢的 ", - "lv": " 初始等级,该项必须为正整数 ", + "lv": " 初始等级,该项必须为正整数 \n$range(thiseval==~~thiseval &&thiseval>0)$end", "hp": " 初始生命值 ", "atk": " 初始攻击 ", "def": " 初始防御 ", @@ -139,27 +139,27 @@ data_comment_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "animateSpeed": " /****** 系统相关 ******/ \n 动画时间 " }, "flags": { - "enableFloor": " 系统FLAG,在游戏运行中中请不要修改它。 /****** 状态栏相关 ******/ \n 是否在状态栏显示当前楼层 ", - "enableLv": " 是否在状态栏显示当前等级 ", - "enableMDef": " 是否在状态栏及战斗界面显示魔防(护盾) ", - "enableMoney": " 是否在状态栏、怪物手册及战斗界面显示金币 ", - "enableExperience": " 是否在状态栏、怪物手册及战斗界面显示经验 ", - "enableLevelUp": " 是否允许等级提升(进阶);如果上面enableExperience为false,则此项恒视为false ", - "enableDebuff": " 是否涉及毒衰咒;如果此项为false则不会在状态栏中显示毒衰咒的debuff ////// 上述的几个开关将直接影响状态栏的显示效果 ////// ", - "flyNearStair": " /****** 道具相关 ******/ \n 是否需要在楼梯边使用传送器 ", - "pickaxeFourDirections": " 使用破墙镐是否四个方向都破坏;如果false则只破坏面前的墙壁 ", - "bombFourDirections": " 使用炸弹是否四个方向都会炸;如果false则只炸面前的怪物(即和圣锤等价) ", - "bigKeyIsBox": " 如果此项为true,则视为钥匙盒,红黄蓝钥匙+1;若为false,则视为大黄门钥匙 ", - "enableNegativeDamage": " /****** 怪物相关 ******/ \n 是否支持负伤害(回血) ", - "zoneSquare": " 领域类型。如果此项为true则为九宫格伤害,为false则为十字伤害 ", - "startDirectly": " /****** 系统相关 ******/ \n 点击“开始游戏”后是否立刻开始游戏而不显示难度选择界面 ", - "canOpenBattleAnimate": " 是否允许用户开启战斗过程;如果此项为false,则下面两项均强制视为false ", - "showBattleAnimateConfirm": " 是否在游戏开始时提供“是否开启战斗动画”的选项 ", - "battleAnimate": " 是否默认显示战斗动画;用户可以手动在菜单栏中开关 ", - "displayEnemyDamage": " 是否地图怪物显伤;用户可以手动在菜单栏中开关 ", - "displayExtraDamage": " 是否地图高级显伤(领域、夹击等);用户可以手动在菜单栏中开关 ", - "enableGentleClick": " 是否允许轻触(获得面前物品) ", - "portalWithoutTrigger": " 经过楼梯、传送门时是否能“穿透”。穿透的意思是,自动寻路得到的的路径中间经过了楼梯,行走时是否触发楼层转换事件 ", - "potionWhileRouting": " 寻路算法是否经过血瓶;如果该项为false,则寻路算法会自动尽量绕过血瓶 " + "enableFloor": " 系统FLAG,在游戏运行中中请不要修改它。 /****** 状态栏相关 ******/ \n 是否在状态栏显示当前楼层 \n$select({\"values\":[true,false]})$end", + "enableLv": " 是否在状态栏显示当前等级 \n$select({\"values\":[true,false]})$end", + "enableMDef": " 是否在状态栏及战斗界面显示魔防(护盾) \n$select({\"values\":[true,false]})$end", + "enableMoney": " 是否在状态栏、怪物手册及战斗界面显示金币 \n$select({\"values\":[true,false]})$end", + "enableExperience": " 是否在状态栏、怪物手册及战斗界面显示经验 \n$select({\"values\":[true,false]})$end", + "enableLevelUp": " 是否允许等级提升(进阶);如果上面enableExperience为false,则此项恒视为false \n$select({\"values\":[true,false]})$end", + "enableDebuff": " 是否涉及毒衰咒;如果此项为false则不会在状态栏中显示毒衰咒的debuff ////// 上述的几个开关将直接影响状态栏的显示效果 ////// \n$select({\"values\":[true,false]})$end", + "flyNearStair": " /****** 道具相关 ******/ \n 是否需要在楼梯边使用传送器 \n$select({\"values\":[true,false]})$end", + "pickaxeFourDirections": " 使用破墙镐是否四个方向都破坏;如果false则只破坏面前的墙壁 \n$select({\"values\":[true,false]})$end", + "bombFourDirections": " 使用炸弹是否四个方向都会炸;如果false则只炸面前的怪物(即和圣锤等价) \n$select({\"values\":[true,false]})$end", + "bigKeyIsBox": " 如果此项为true,则视为钥匙盒,红黄蓝钥匙+1;若为false,则视为大黄门钥匙 \n$select({\"values\":[true,false]})$end", + "enableNegativeDamage": " /****** 怪物相关 ******/ \n 是否支持负伤害(回血) \n$select({\"values\":[true,false]})$end", + "zoneSquare": " 领域类型。如果此项为true则为九宫格伤害,为false则为十字伤害 \n$select({\"values\":[true,false]})$end", + "startDirectly": " /****** 系统相关 ******/ \n 点击“开始游戏”后是否立刻开始游戏而不显示难度选择界面 \n$select({\"values\":[true,false]})$end", + "canOpenBattleAnimate": " 是否允许用户开启战斗过程;如果此项为false,则下面两项均强制视为false \n$select({\"values\":[true,false]})$end", + "showBattleAnimateConfirm": " 是否在游戏开始时提供“是否开启战斗动画”的选项 \n$select({\"values\":[true,false]})$end", + "battleAnimate": " 是否默认显示战斗动画;用户可以手动在菜单栏中开关 \n$select({\"values\":[true,false]})$end", + "displayEnemyDamage": " 是否地图怪物显伤;用户可以手动在菜单栏中开关 \n$select({\"values\":[true,false]})$end", + "displayExtraDamage": " 是否地图高级显伤(领域、夹击等);用户可以手动在菜单栏中开关 \n$select({\"values\":[true,false]})$end", + "enableGentleClick": " 是否允许轻触(获得面前物品) \n$select({\"values\":[true,false]})$end", + "portalWithoutTrigger": " 经过楼梯、传送门时是否能“穿透”。穿透的意思是,自动寻路得到的的路径中间经过了楼梯,行走时是否触发楼层转换事件 \n$select({\"values\":[true,false]})$end", + "potionWhileRouting": " 寻路算法是否经过血瓶;如果该项为false,则寻路算法会自动尽量绕过血瓶 \n$select({\"values\":[true,false]})$end" } } \ No newline at end of file