editor_file savefloor
This commit is contained in:
parent
9861319734
commit
5f75a0ad6f
@ -4,7 +4,7 @@ editor_file_wrapper = function (editor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 这个函数之后挪到editor.table?
|
// 这个函数之后挪到editor.table?
|
||||||
editor_file_proto.prototype.loadCommentjs=function(callback){
|
editor_file_proto.prototype.loadCommentjs = function (callback) {
|
||||||
var commentjs = {
|
var commentjs = {
|
||||||
'comment': 'comment',
|
'comment': 'comment',
|
||||||
'data.comment': 'dataComment',
|
'data.comment': 'dataComment',
|
||||||
@ -33,5 +33,62 @@ editor_file_wrapper = function (editor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editor_file_proto.prototype.alertWhenCompress = function () {
|
||||||
|
if (editor.useCompress === true) {
|
||||||
|
editor.useCompress = 'alerted';
|
||||||
|
setTimeout("alert('当前游戏使用的是压缩文件,修改完成后请使用启动服务.exe->Js代码压缩工具重新压缩,或者把main.js的useCompress改成false来使用原始文件')", 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
editor_file_proto.prototype.formatMap = function (mapArr, trySimplify) {
|
||||||
|
if (!mapArr || JSON.stringify(mapArr) == JSON.stringify([])) return '';
|
||||||
|
if (trySimplify) {
|
||||||
|
//检查是否是全0二维数组
|
||||||
|
var jsoncheck = JSON.stringify(mapArr).replace(/\D/g, '');
|
||||||
|
if (jsoncheck == Array(jsoncheck.length + 1).join('0')) return '';
|
||||||
|
}
|
||||||
|
//把二维数组格式化
|
||||||
|
var formatArrStr = '';
|
||||||
|
var arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],[');
|
||||||
|
var si = mapArr.length - 1, sk = mapArr[0].length - 1;
|
||||||
|
for (var i = 0; i <= si; i++) {
|
||||||
|
var a = [];
|
||||||
|
formatArrStr += ' [';
|
||||||
|
if (i == 0 || i == si) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
|
||||||
|
else a = arr[i].split(/\D+/);
|
||||||
|
for (var k = 0; k <= sk; k++) {
|
||||||
|
var num = parseInt(a[k]);
|
||||||
|
formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == sk ? '' : ',');
|
||||||
|
}
|
||||||
|
formatArrStr += ']' + (i == si ? '' : ',\n');
|
||||||
|
}
|
||||||
|
return formatArrStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor_file_proto.prototype.saveFloor = function (floorData, callback) {
|
||||||
|
//callback(err:String)
|
||||||
|
var floorId = floorData.floorId;
|
||||||
|
var filename = 'project/floors/' + floorId + '.js';
|
||||||
|
var datastr = ['main.floors.', floorId, '=\n'];
|
||||||
|
|
||||||
|
// format 更改实现方式以支持undefined删除
|
||||||
|
var tempJsonObj = Object.assign({}, floorData);
|
||||||
|
var tempMap = [['map', editor.util.guid()], ['bgmap', editor.util.guid()], ['fgmap', editor.util.guid()]];
|
||||||
|
tempMap.forEach(function (v) {
|
||||||
|
v[2] = tempJsonObj[v[0]];
|
||||||
|
tempJsonObj[v[0]] = v[1];
|
||||||
|
});
|
||||||
|
var tempJson = JSON.stringify(tempJsonObj, null, 4);
|
||||||
|
tempMap.forEach(function (v) {
|
||||||
|
tempJson = tempJson.replace('"' + v[1] + '"', '[\n' + editor.file.formatMap(v[2], v[0] != 'map') + '\n]')
|
||||||
|
});
|
||||||
|
datastr = datastr.concat([tempJson]);
|
||||||
|
datastr = datastr.join('');
|
||||||
|
editor.file.alertWhenCompress();
|
||||||
|
editor.fs.writeFile(filename, encode(datastr), 'base64', function (err, data) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -5,16 +5,9 @@ editor_file = function (editor, callback) {
|
|||||||
|
|
||||||
editor.file.loadCommentjs(callback);
|
editor.file.loadCommentjs(callback);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
editor.file.saveFloorFile = function (callback) {
|
editor.file.saveFloorFile = function (callback) {
|
||||||
|
//callback(err:String)
|
||||||
checkCallback(callback);
|
checkCallback(callback);
|
||||||
/* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) {
|
|
||||||
callback('未选中文件或无数据');
|
|
||||||
} */
|
|
||||||
var filename = 'project/floors/' + editor.currentFloorId + '.js';
|
|
||||||
var datastr = ['main.floors.', editor.currentFloorId, '=\n'];
|
|
||||||
|
|
||||||
for(var ii=0,name;name=['map','bgmap','fgmap'][ii];ii++){
|
for(var ii=0,name;name=['map','bgmap','fgmap'][ii];ii++){
|
||||||
var mapArray=editor[name].map(function (v) {
|
var mapArray=editor[name].map(function (v) {
|
||||||
return v.map(function (v) {
|
return v.map(function (v) {
|
||||||
@ -23,26 +16,11 @@ editor_file = function (editor, callback) {
|
|||||||
});
|
});
|
||||||
editor.currentFloorData[name]=mapArray;
|
editor.currentFloorData[name]=mapArray;
|
||||||
}
|
}
|
||||||
|
editor.file.saveFloor(editor.currentFloorData)
|
||||||
// format 更改实现方式以支持undefined删除
|
|
||||||
var tempJsonObj=Object.assign({},editor.currentFloorData);
|
|
||||||
var tempMap=[['map',editor.util.guid()],['bgmap',editor.util.guid()],['fgmap',editor.util.guid()]];
|
|
||||||
tempMap.forEach(function(v){
|
|
||||||
v[2]=tempJsonObj[v[0]];
|
|
||||||
tempJsonObj[v[0]]=v[1];
|
|
||||||
});
|
|
||||||
var tempJson=JSON.stringify(tempJsonObj, null, 4);
|
|
||||||
tempMap.forEach(function(v){
|
|
||||||
tempJson=tempJson.replace('"'+v[1]+'"','[\n'+ formatMap(v[2],v[0]!='map')+ '\n]')
|
|
||||||
});
|
|
||||||
datastr = datastr.concat([tempJson]);
|
|
||||||
datastr = datastr.join('');
|
|
||||||
alertWhenCompress();
|
|
||||||
fs.writeFile(filename, encode(datastr), 'base64', function (err, data) {
|
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
//callback(err:String)
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
editor.file.saveNewFile = function (saveFilename, callback) {
|
editor.file.saveNewFile = function (saveFilename, callback) {
|
||||||
//saveAsFilename不含'/'不含'.js'
|
//saveAsFilename不含'/'不含'.js'
|
||||||
checkCallback(callback);
|
checkCallback(callback);
|
||||||
@ -132,7 +110,7 @@ editor_file = function (editor, callback) {
|
|||||||
delete data[t];
|
delete data[t];
|
||||||
else {
|
else {
|
||||||
if (t=='map') {
|
if (t=='map') {
|
||||||
datastr = datastr.concat(['\n"', t, '": [\n', formatMap(data[t]), '\n],']);
|
datastr = datastr.concat(['\n"', t, '": [\n', editor.file.formatMap(data[t]), '\n],']);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
datastr = datastr.concat(['\n"', t, '": ', JSON.stringify(data[t], null, 4), ',']);
|
datastr = datastr.concat(['\n"', t, '": ', JSON.stringify(data[t], null, 4), ',']);
|
||||||
@ -143,7 +121,7 @@ editor_file = function (editor, callback) {
|
|||||||
datastr = datastr.join('');
|
datastr = datastr.join('');
|
||||||
datas.push(encode(datastr));
|
datas.push(encode(datastr));
|
||||||
}
|
}
|
||||||
alertWhenCompress();
|
editor.file.alertWhenCompress();
|
||||||
fs.writeMultiFiles(filenames, datas, function (err, data) {
|
fs.writeMultiFiles(filenames, datas, function (err, data) {
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
@ -689,44 +667,12 @@ editor_file = function (editor, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var formatMap = function (mapArr,trySimplify) {
|
|
||||||
if(!mapArr || JSON.stringify(mapArr)==JSON.stringify([]))return '';
|
|
||||||
if(trySimplify){
|
|
||||||
//检查是否是全0二维数组
|
|
||||||
var jsoncheck=JSON.stringify(mapArr).replace(/\D/g,'');
|
|
||||||
if(jsoncheck==Array(jsoncheck.length+1).join('0'))return '';
|
|
||||||
}
|
|
||||||
//把二维数组格式化
|
|
||||||
var formatArrStr = '';
|
|
||||||
var arr = JSON.stringify(mapArr).replace(/\s+/g, '').split('],[');
|
|
||||||
var si=mapArr.length-1,sk=mapArr[0].length-1;
|
|
||||||
for (var i = 0; i <= si; i++) {
|
|
||||||
var a = [];
|
|
||||||
formatArrStr += ' [';
|
|
||||||
if (i == 0 || i == si) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
|
|
||||||
else a = arr[i].split(/\D+/);
|
|
||||||
for (var k = 0; k <= sk; k++) {
|
|
||||||
var num = parseInt(a[k]);
|
|
||||||
formatArrStr += Array(Math.max(4 - String(num).length, 0)).join(' ') + num + (k == sk ? '' : ',');
|
|
||||||
}
|
|
||||||
formatArrStr += ']' + (i == si ? '' : ',\n');
|
|
||||||
}
|
|
||||||
return formatArrStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
var encode = editor.util.encode64
|
var encode = editor.util.encode64
|
||||||
|
|
||||||
var alertWhenCompress = function(){
|
|
||||||
if(editor.useCompress===true){
|
|
||||||
editor.useCompress='alerted';
|
|
||||||
setTimeout("alert('当前游戏使用的是压缩文件,修改完成后请使用启动服务.exe->Js代码压缩工具重新压缩,或者把main.js的useCompress改成false来使用原始文件')",1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var saveSetting = function (file, actionList, callback) {
|
var saveSetting = function (file, actionList, callback) {
|
||||||
//console.log(file);
|
//console.log(file);
|
||||||
//console.log(actionList);
|
//console.log(actionList);
|
||||||
alertWhenCompress();
|
editor.file.alertWhenCompress();
|
||||||
|
|
||||||
if (file == 'icons') {
|
if (file == 'icons') {
|
||||||
actionList.forEach(function (value) {
|
actionList.forEach(function (value) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user