This commit is contained in:
YouWei Zhao 2018-01-09 23:45:16 +08:00
parent bb08b1fb61
commit 0c24e662c9
5 changed files with 117 additions and 23 deletions

View File

@ -12,8 +12,10 @@
+ 重命名为`editor.html`
* 需要相应的修改本地服务的按钮打开的网址,为了兼容,临时加了个内容为`<html><body><script>window.location='editor.html'</script></body></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
渲染成<select>,选项为数组eval(evalstr)['values']
$input
渲染成<input>,此为默认选项
$input(evalstr)$end
渲染成<input>
$textarea(evalstr)$end
渲染成<textarea>,行数为正整数eval(evalstr)['rows']
渲染成<textarea>
默认选项为$textarea()$end
// ]
```
目前只出现了以下5种
```
$range(thiseval in ['keys','items','constants','tools'])$end
$range(thiseval==~~thiseval &&thiseval>0)$end
$range(thiseval in [true,false])$end
$range(false)$end
$leaf(true)$end
```
# todo
# todo & 目前的bug
+ editor的5个编辑模式(标签页)`map|item & enemy|loc|floor|tower`
+ replay模式
+ 把js压缩工具改为一键生成发布版
+ `event`,`after...`在地图上没有标记,可以在右下角加类似于无`id`的红问号类似的绿色星号小标记
+ 添加新图块只对地形好使,添加的新物品还是需要手动在`project/items.js`中加东西
+ 目前未做$range(evalstr:thiseval)$end的检查
+ 通过`core.values.redJewel`的方式设置物品加的数值,在全GUI下反而会不直观
+ `idnum`上限改到`999`,不需要在`.js`中手动设置`idnum`的话,根据数字范围来约定类型意义不大,而且`400`内随便输个数就发现已经被占了,体验极差
+ `editor.html`中独立换背景的功能不再需要,待移除
+ 全GUI下编辑要经常保存修改后F5
+ 目前的报错只是throw,如果不开F12注意不到有错误发生,修改没有生效
+ 有待美化,以及做成标签页式的模式切换
+ replay模式,这个功能对于魔塔网站以及贴吧活动很有意义
前三条我会尽快修复(添加)

View File

@ -144,6 +144,13 @@ editor.prototype.mapInit = function(){
editor.map[y][x] = 0;
}
}
editor.currentFloorData.map=editor.map;
editor.currentFloorData.firstArrive=[];
editor.currentFloorData.events={};
editor.currentFloorData.changeFloor={};
editor.currentFloorData.afterBattle={};
editor.currentFloorData.afterGetItem={};
editor.currentFloorData.afterOpenDoor={};
}
editor.prototype.drawMapBg = function(img){
var bgc = bg.getContext('2d');
@ -288,6 +295,7 @@ editor.prototype.updateMap = function(){
}
editor.prototype.changeFloor = function(floorId,callback) {
editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})});
core.changeFloor(floorId, null, core.firstData.hero.loc, null, function(){
editor.drawMapBg();
var mapArray = core.maps.getMapArray(core.status.maps, core.status.floorId);

View File

@ -70,6 +70,7 @@
} */
var filename = 'project/floors/' + editor.currentFloorId + '.js';
var datastr = ['main.floors.' , editor.currentFloorId , '=\n{'];
editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})});
for(var ii in editor.currentFloorData)
if (editor.currentFloorData.hasOwnProperty(ii)) {
if (ii=='map')
@ -90,6 +91,7 @@
if (!isset(editor.currentFloorData)) {
callback('无数据');
}
editor.currentFloorData.map = editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})});
editor.currentFloorData=JSON.parse(JSON.stringify(editor.currentFloorData));
editor.currentFloorData.floorId=saveAsFilename;
editor.currentFloorId=saveAsFilename;
@ -396,7 +398,6 @@
if (value[0]!='change' && file!='icons' && file!='maps') throw('目前只支持change');
});
//throw('尚未实现');
if (file=='icons') {
actionList.forEach(function (value) {
if (value[0]!='add')return;

View File

@ -58,7 +58,7 @@ editor_mode.prototype.objToTable = function(obj,commentObj){
}
editor_mode.onmode(editor_mode._ids[node.getAttribute('id')]);
editor_mode.addAction(['change',field,JSON.parse(input.value)]);
//尚未完成,目前没做$range的检查
//尚未完成,不完善,目前没做$range的检查
};
});
}
@ -192,8 +192,10 @@ editor_mode.prototype.emenyitem = function(callback){
if (!core.isset(editor_mode.info.id)){
document.getElementById('table_a3f03d4c_55b8_4ef6_b362_b345783acd72').innerHTML='';
document.getElementById('newIdIdnum').style.display='';
return;
}//尚未完成,此处要设置成允许添加新的id 和 idnum
}
document.getElementById('newIdIdnum').style.display='none';
var objs=[];
if (editor_mode.info.images=='enemys'){
@ -232,5 +234,51 @@ editor_mode.prototype.tower = function(callback){
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(["<option value='",floor,"'>",floor,'</option>\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();

View File

@ -16,6 +16,10 @@
<p class="warnText" v-if="error">{{ errors[error-1] }}</p>
</div>
<div id="editTip" v-cloak>
<select id="selectFloor"></select><br>
<input id='saveAsName' placeholder="输入新楼层id"/>
<input class='btn' type="button" value="save" id='saveFloor'/>
<input class='btn' type="button" value="saveAs" id='saveFloorAs'/>
<input class='btn' type="button" value="复制地图" v-on:click="copyMap"/>
</div>
</div>
@ -73,8 +77,9 @@
</div></div>
<div id="left3" class='leftTab'><div><!-- emenyitem -->
<h3>图块属性</h3>
<div><!-- id and idnum -->
<!-- 尚未完成 -->
<div id='newIdIdnum'><!-- id and idnum -->
<input placeholder="输入新id"/>
<input placeholder="输入新idnum"/>
</div>
<div><!-- enemy and item -->
<div class='etable'>
@ -306,6 +311,7 @@ editor.init(function(){
editor_mode.emenyitem();
editor_mode.floor();
editor_mode.tower();
editor_mode.listen();
});
//main.listen();
//core.setHeroMoveTriggerInterval();