This commit is contained in:
YouWei Zhao 2019-04-21 17:59:50 -04:00
parent da5c2a2590
commit c73d16c1b9
5 changed files with 89 additions and 118 deletions

View File

@ -32,11 +32,7 @@ editor_file = function (editor, callback) {
editor_file.getFloorFileList = function (callback) {
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
/* var fs = editor.fs;
fs.readdir('project/floors',function(err, data){
callback([data,err]);
@ -46,22 +42,14 @@ editor_file = function (editor, callback) {
//callback([Array<String>,err:String])
editor_file.loadFloorFile = function (filename, callback) {
//filename不含'/'不含'.js'
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
editor.currentFloorId = editor.core.status.floorId;
editor.currentFloorData = editor.core.floors[editor.currentFloorId];
}
//callback(err:String)
editor_file.saveFloorFile = function (callback) {
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
/* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) {
callback('未选中文件或无数据');
} */
@ -113,10 +101,7 @@ editor_file = function (editor, callback) {
//callback(err:String)
editor_file.saveNewFile = function (saveFilename, callback) {
//saveAsFilename不含'/'不含'.js'
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
};
checkCallback(callback);
var currData=editor.currentFloorData;
var saveStatus = document.getElementById('newMapStatus').checked;
@ -163,10 +148,7 @@ editor_file = function (editor, callback) {
editor_file.saveFloorFile(callback);
}
editor_file.saveNewFiles = function (floorIdList, from, to, callback) {
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
};
checkCallback(callback);
var currData=editor.currentFloorData;
var saveStatus = document.getElementById('newMapsStatus').checked;
@ -349,11 +331,7 @@ editor_file = function (editor, callback) {
}
editor_file.changeIdAndIdnum = function (id, idnum, info, callback) {
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
//检查maps中是否有重复的idnum或id
var change = -1;
for (var ii in editor.core.maps.blocksInfo) {
@ -428,11 +406,7 @@ editor_file = function (editor, callback) {
]
[]时只查询不修改
*/
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) {
var tempindex = value[1].indexOf(']') + 1;
@ -475,11 +449,7 @@ editor_file = function (editor, callback) {
]
[]时只查询不修改
*/
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) {
value[1] = "['" + id + "']" + value[1];
@ -512,11 +482,7 @@ editor_file = function (editor, callback) {
]
[]时只查询不修改
*/
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
var tempmap=[];
for(var ii=0;ii<actionList.length;ii++){
@ -560,11 +526,7 @@ editor_file = function (editor, callback) {
]
[]时只查询不修改
*/
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) {
value[1] = value[1] + "['" + x + "," + y + "']";
@ -600,11 +562,7 @@ editor_file = function (editor, callback) {
]
[]时只查询不修改
*/
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
saveSetting('floors', actionList, function (err) {
callback([err]);
@ -643,11 +601,7 @@ editor_file = function (editor, callback) {
[]时只查询不修改
*/
var data_obj = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d;
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
saveSetting('data', actionList, function (err) {
callback([err]);
@ -698,11 +652,7 @@ editor_file = function (editor, callback) {
]
[]时只查询不修改
*/
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
saveSetting('functions', actionList, function (err) {
callback([err]);
@ -729,11 +679,7 @@ editor_file = function (editor, callback) {
[]时只查询不修改
*/
var data_obj = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent;
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
actionList.forEach(function (value) {
value[1] = "['commonEvent']" + value[1];
@ -780,11 +726,7 @@ editor_file = function (editor, callback) {
]
[]时只查询不修改
*/
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
;
checkCallback(callback);
if (isset(actionList) && actionList.length > 0) {
saveSetting('plugins', actionList, function (err) {
callback([err]);
@ -811,6 +753,13 @@ editor_file = function (editor, callback) {
return true
}
var checkCallback=function(callback){
if (!isset(callback)) {
printe('未设置callback');
throw('未设置callback')
}
}
var formatMap = function (mapArr,trySimplify) {
if(!mapArr || JSON.stringify(mapArr)==JSON.stringify([]))return '';
if(trySimplify){

View File

@ -1,37 +1,56 @@
editor_game_wrapper = function (editor, main, core) {
editor_game = function () {
this.replacerRecord = {}
}
// 三个 replacer 和 replacerRecord 暂时放在此处
editor_game.prototype.replacerForLoading = function (_key, value) {
var rmap = editor.game.replacerRecord;
if (value instanceof Function) {
var guid_ = editor.util.guid()
rmap[guid_] = value.toString()
return guid_
} else if (value === null) {
// 为了包含functions的新建, 不使用'null'是否有问题待测
var guid_ = editor.util.guid()
rmap[guid_] = null
return guid_
}
return value
}
editor_game.prototype.replacerForSaving = function (_key, value) {
var rmap = editor.game.replacerRecord;
if (rmap.hasOwnProperty(value)) {
return rmap[value]
}
return value
}
editor_game.prototype.replacerWithoutRecord = function (_key, value) {
if (value instanceof Function) {
return value.toString()
} else return value
}
editor_game.prototype.fixFunctionInGameData = function () {
core.floors = JSON.parse(JSON.stringify(core.floors, function (_k, v) {
if (v instanceof Function) {
return v.toString()
} else return v
}));
core.data = JSON.parse(JSON.stringify(core.data, function (_k, v) {
if (v instanceof Function) {
return v.toString()
} else return v
}));
data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = JSON.parse(JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, function (_k, v) {
if (v instanceof Function) {
return v.toString()
} else return v
}));
var rf = editor.game.replacerWithoutRecord
core.floors = JSON.parse(JSON.stringify(core.floors, rf));
core.data = JSON.parse(JSON.stringify(core.data, rf));
data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = JSON.parse(JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, rf));
}
editor_game.prototype.idsInit = function (maps, icons) {
editor.ids = [0];
editor.indexs = [];
var MAX_NUM = 0;
var keys=Object.keys(maps_90f36752_8815_4be8_b32b_d7fad1d0542e);
for(var ii=0;ii<keys.length;ii++){
var v=~~keys[ii];
if(v>MAX_NUM && v<core.icons.tilesetStartOffset)MAX_NUM=v;
var keys = Object.keys(maps_90f36752_8815_4be8_b32b_d7fad1d0542e);
for (var ii = 0; ii < keys.length; ii++) {
var v = ~~keys[ii];
if (v > MAX_NUM && v < core.icons.tilesetStartOffset) MAX_NUM = v;
}
editor.MAX_NUM=MAX_NUM;
editor.MAX_NUM = MAX_NUM;
var getInfoById = function (id) {
var block = maps.initBlock(0, 0, id);
if (Object.prototype.hasOwnProperty.call(block, 'event')) {
@ -46,15 +65,15 @@ editor_game_wrapper = function (editor, main, core) {
var id = indexBlock.event.id;
var indexId = indexBlock.id;
var allCls = Object.keys(icons);
if(i==17){
editor.ids.push({'idnum': 17, 'id': id, 'images': 'terrains'});
if (i == 17) {
editor.ids.push({ 'idnum': 17, 'id': id, 'images': 'terrains' });
point++;
editor.indexs[i].push(point);
continue;
}
for (var j = 0; j < allCls.length; j++) {
if (id in icons[allCls[j]]) {
editor.ids.push({'idnum': indexId, 'id': id, 'images': allCls[j], 'y': icons[allCls[j]][id]});
editor.ids.push({ 'idnum': indexId, 'id': id, 'images': allCls[j], 'y': icons[allCls[j]][id] });
point++;
editor.indexs[i].push(point);
}
@ -62,36 +81,36 @@ editor_game_wrapper = function (editor, main, core) {
}
}
editor.indexs[0] = [0];
var startOffset = core.icons.tilesetStartOffset;
for (var i in core.tilesets) {
var imgName = core.tilesets[i];
var img = core.material.images.tilesets[imgName];
var width = Math.floor(img.width/32), height = Math.floor(img.height/32);
if(img.width%32 || img.height%32){
alert(imgName+'的长或宽不是32的整数倍, 请修改后刷新页面');
var width = Math.floor(img.width / 32), height = Math.floor(img.height / 32);
if (img.width % 32 || img.height % 32) {
alert(imgName + '的长或宽不是32的整数倍, 请修改后刷新页面');
}
if(img.width*img.height > 32*32*3000){
alert(imgName+'上的图块数量超过了3000请修改后刷新页面');
if (img.width * img.height > 32 * 32 * 3000) {
alert(imgName + '上的图块数量超过了3000请修改后刷新页面');
}
for (var id=startOffset; id<startOffset+width*height;id++) {
var x = (id-startOffset)%width, y = parseInt((id-startOffset)/width);
for (var id = startOffset; id < startOffset + width * height; id++) {
var x = (id - startOffset) % width, y = parseInt((id - startOffset) / width);
var indexBlock = getInfoById(id);
editor.ids.push({'idnum': id, 'id': indexBlock.event.id, 'images': imgName, "x": x, "y": y, isTile: true});
editor.ids.push({ 'idnum': id, 'id': indexBlock.event.id, 'images': imgName, "x": x, "y": y, isTile: true });
point++;
editor.indexs[id]=[point];
editor.indexs[id] = [point];
}
startOffset += core.icons.tilesetStartOffset;
}
}
editor_game.prototype.fetchMapFromCore = function(){
editor_game.prototype.fetchMapFromCore = function () {
var mapArray = core.maps.saveMap(core.status.floorId);
editor.map = mapArray.map(function (v) {
return v.map(function (v) {
var x = parseInt(v), y = editor.indexs[x];
if (y == null) {
printe("素材数字"+x+"未定义。是不是忘了注册或者接档时没有覆盖icons.js和maps.js");
printe("素材数字" + x + "未定义。是不是忘了注册或者接档时没有覆盖icons.js和maps.js");
y = [0];
}
return editor.ids[y[0]]
@ -99,17 +118,17 @@ editor_game_wrapper = function (editor, main, core) {
});
editor.currentFloorId = core.status.floorId;
editor.currentFloorData = core.floors[core.status.floorId];
for(var ii=0,name;name=['bgmap','fgmap'][ii];ii++){
for (var ii = 0, name; name = ['bgmap', 'fgmap'][ii]; ii++) {
var mapArray = editor.currentFloorData[name];
if(!mapArray || JSON.stringify(mapArray)==JSON.stringify([])){//未设置或空数组
if (!mapArray || JSON.stringify(mapArray) == JSON.stringify([])) {//未设置或空数组
//与editor.map同形的全0
mapArray=eval('['+Array(editor.map.length+1).join('['+Array(editor.map[0].length+1).join('0,')+'],')+']');
mapArray = eval('[' + Array(editor.map.length + 1).join('[' + Array(editor.map[0].length + 1).join('0,') + '],') + ']');
}
editor[name]=mapArray.map(function (v) {
editor[name] = mapArray.map(function (v) {
return v.map(function (v) {
var x = parseInt(v), y = editor.indexs[x];
if (y == null) {
printe("素材数字"+x+"未定义。是不是忘了注册或者接档时没有覆盖icons.js和maps.js");
printe("素材数字" + x + "未定义。是不是忘了注册或者接档时没有覆盖icons.js和maps.js");
y = [0];
}
return editor.ids[y[0]]
@ -118,7 +137,6 @@ editor_game_wrapper = function (editor, main, core) {
}
}
editor.constructor.prototype.game = new editor_game();
}
//editor_game_wrapper(editor);

View File

@ -11,7 +11,7 @@
+ [ ] editor_multi 多行文本编辑器
+ [x] editor_table 处理表格的生成, 及其响应的事件, 从原editor\_mode中分离
+ [ ] editor_file 调用fs.js编辑文件, 把原editor\_file模块化
+ [ ] editor_game 处理来自core的数据, 导入为editor的数据, 从原editor中分离
+ [ ] editor_game 处理来自core的数据, 导入为editor的数据, 从原editor中分离. **只有此文件允许`\b(main|core)`形式的调用**(以及其初始化`editor_game_wrapper(editor, main, core);`)
+ [x] editor_util 生成guid等函数, 从editor分离
+ [ ] editor 执行初始化流程加组合各组件
+ [ ] 原editor_mode 移除
@ -51,7 +51,7 @@ editor: {
+ 地图的编辑与其他(如全塔属性和楼层属性), 现在的文件操作的模式是完全不同的
楼层文件的储存与其他不同
+ editor.file在修改时不再返回obj和commentobj,只在查询时返回
+ [x] editor.file在修改时不再返回obj和commentobj,只在查询时返回
+ editor.file中的各个条目, 非常相似, 但是细节的不同处理非常麻烦. 是类似的代码复制后修改一部分, 尝试模块化(或者重写)
@ -61,6 +61,8 @@ editor: {
+ 目前editor.map中储存的是info\<object\>, 准备改为和core一致只储存数字
+ editor.widthX特别不直观
## 功能改进
+ [ ] 大地图
@ -103,6 +105,8 @@ editor: {
+ [ ] `显示文章`以及`选项`等方块, 把`标题`和`图像`从字符串提取出填回相应的空
+ [ ] blockly中某些需要选点的填空, 增加按钮, 点击后从缩略图中点击位置
## 左侧页面模式
标题? 保存按钮? 添加按钮? 删除按钮?

View File

@ -523,8 +523,8 @@
<!-- <script src='_server/vendor/polyfill.min.js'></script> -->
<script src='_server/fs.js'></script>
<script src='_server/editor_util.js'></script>
<script src='_server/editor_file.js'></script>
<script src='_server/editor_game.js'></script>
<script src='_server/editor_file.js'></script>
<script src='_server/editor_table.js'></script>
<script src='_server/editor_mode.js'></script>
<script src='_server/editor_unsorted_1.js'></script>

View File

@ -506,8 +506,8 @@
<!-- <script src='_server/vendor/polyfill.min.js'></script> -->
<script src='_server/fs.js'></script>
<script src='_server/editor_util.js'></script>
<script src='_server/editor_file.js'></script>
<script src='_server/editor_game.js'></script>
<script src='_server/editor_file.js'></script>
<script src='_server/editor_table.js'></script>
<script src='_server/editor_mode.js'></script>
<script src='_server/editor_unsorted_1.js'></script>