Merge branch 'v2.x' of https://github.com/ckcz123/mota-js into v2.x
This commit is contained in:
commit
a0475745f2
@ -6,6 +6,197 @@ editor_datapanel_wrapper = function (editor) {
|
||||
//////////////////// 地图编辑 //////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 由于历史遗留原因, 以下变量作为全局变量使用
|
||||
// pout exportMap mapEditArea mapEditArea copyMap clearMapButton deleteMap
|
||||
window.pout = document.getElementById('pout')
|
||||
window.exportMap = document.getElementById('exportMap')
|
||||
exportMap.isExport=false
|
||||
exportMap.onclick=function(){
|
||||
editor.updateMap();
|
||||
var sx=editor.map.length-1,sy=editor.map[0].length-1;
|
||||
|
||||
var filestr = '';
|
||||
for (var yy = 0; yy <= sy; yy++) {
|
||||
filestr += '['
|
||||
for (var xx = 0; xx <= sx; xx++) {
|
||||
var mapxy = editor.map[yy][xx];
|
||||
if (typeof(mapxy) == typeof({})) {
|
||||
if ('idnum' in mapxy) mapxy = mapxy.idnum;
|
||||
else {
|
||||
// mapxy='!!?';
|
||||
tip.whichShow(3);
|
||||
return;
|
||||
}
|
||||
} else if (typeof(mapxy) == 'undefined') {
|
||||
tip.whichShow(3);
|
||||
return;
|
||||
}
|
||||
mapxy = String(mapxy);
|
||||
mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy;
|
||||
filestr += mapxy + (xx == sx ? '' : ',')
|
||||
}
|
||||
|
||||
filestr += ']' + (yy == sy ? '' : ',\n');
|
||||
}
|
||||
pout.value = filestr;
|
||||
mapEditArea.mapArr(filestr);
|
||||
exportMap.isExport = true;
|
||||
mapEditArea.error(0);
|
||||
tip.whichShow(2);
|
||||
}
|
||||
window.mapEditArea = document.getElementById('mapEditArea')
|
||||
mapEditArea.errors=[ // 编号1,2
|
||||
"格式错误!请使用正确格式(请使用地图生成器进行生成,且需要和本地图宽高完全一致)",
|
||||
"当前有未定义ID(在地图区域显示红块),请修改ID或者到icons.js和maps.js中进行定义!"
|
||||
]
|
||||
mapEditArea.formatTimer=null
|
||||
mapEditArea._mapArr=''
|
||||
mapEditArea.mapArr=function(value){
|
||||
if(value!=null){
|
||||
var val=value
|
||||
var oldval=mapEditArea._mapArr
|
||||
if (val==oldval) return;
|
||||
|
||||
if (exportMap.isExport) {
|
||||
exportMap.isExport = false;
|
||||
return;
|
||||
}
|
||||
if (mapEditArea.formatArr()) {
|
||||
mapEditArea.error(0);
|
||||
|
||||
setTimeout(function () {
|
||||
if (mapEditArea.formatArr())mapEditArea.mapArr(mapEditArea.formatArr());
|
||||
mapEditArea.drawMap();
|
||||
tip.whichShow(8)
|
||||
}, 1000);
|
||||
clearTimeout(mapEditArea.formatTimer);
|
||||
mapEditArea.formatTimer = setTimeout(function () {
|
||||
pout.value = mapEditArea.formatArr();
|
||||
}, 5000); //5s后再格式化,不然光标跳到最后很烦
|
||||
} else {
|
||||
mapEditArea.error(1);
|
||||
}
|
||||
|
||||
mapEditArea._mapArr=value
|
||||
}
|
||||
return mapEditArea._mapArr
|
||||
}
|
||||
pout.oninput=function(){
|
||||
mapEditArea.mapArr(pout.value)
|
||||
}
|
||||
mapEditArea._error=0
|
||||
mapEditArea.error=function(value){
|
||||
if(value!=null){
|
||||
mapEditArea._error=value
|
||||
if (value>0)
|
||||
printe(mapEditArea.errors[value-1])
|
||||
}
|
||||
return mapEditArea._error
|
||||
}
|
||||
mapEditArea.drawMap= function () {
|
||||
// var mapArray = mapEditArea.mapArr().split(/\D+/).join(' ').trim().split(' ');
|
||||
var mapArray = JSON.parse('[' + mapEditArea.mapArr() + ']');
|
||||
var sy=editor.map.length,sx=editor.map[0].length;
|
||||
for (var y = 0; y < sy; y++)
|
||||
for (var x = 0; x < sx; x++) {
|
||||
var num = mapArray[y][x];
|
||||
if (num == 0)
|
||||
editor.map[y][x] = 0;
|
||||
else if (typeof(editor.indexs[num][0]) == 'undefined') {
|
||||
mapEditArea.error(2);
|
||||
editor.map[y][x] = undefined;
|
||||
} else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]];
|
||||
}
|
||||
|
||||
editor.updateMap();
|
||||
|
||||
}
|
||||
mapEditArea.formatArr= function () {
|
||||
var formatArrStr = '';
|
||||
console.log(1)
|
||||
|
||||
var si=editor.map.length,sk=editor.map[0].length;
|
||||
if (mapEditArea.mapArr().split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false;
|
||||
var arr = mapEditArea.mapArr().replace(/\s+/g, '').split('],[');
|
||||
|
||||
if (arr.length != si) return;
|
||||
for (var i = 0; i < si; i++) {
|
||||
var a = [];
|
||||
formatArrStr += '[';
|
||||
if (i == 0 || i == si-1) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
|
||||
else a = arr[i].split(/\D+/);
|
||||
if (a.length != sk) {
|
||||
formatArrStr = '';
|
||||
return;
|
||||
}
|
||||
|
||||
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-1 ? '' : ',');
|
||||
}
|
||||
formatArrStr += ']' + (i == si-1 ? '' : ',\n');
|
||||
}
|
||||
return formatArrStr;
|
||||
}
|
||||
window.copyMap=document.getElementById('copyMap')
|
||||
copyMap.err=''
|
||||
copyMap.onclick=function(){
|
||||
tip.whichShow(0);
|
||||
if (pout.value.trim() != '') {
|
||||
if (mapEditArea.error()) {
|
||||
copyMap.err = mapEditArea.errors[mapEditArea.error() - 1];
|
||||
tip.whichShow(5)
|
||||
return;
|
||||
}
|
||||
try {
|
||||
pout.focus();
|
||||
pout.setSelectionRange(0, pout.value.length);
|
||||
document.execCommand("Copy");
|
||||
tip.whichShow(6);
|
||||
} catch (e) {
|
||||
copyMap.err = e;
|
||||
tip.whichShow(5);
|
||||
}
|
||||
} else {
|
||||
tip.whichShow(7);
|
||||
}
|
||||
}
|
||||
window.clearMapButton=document.getElementById('clearMapButton')
|
||||
clearMapButton.onclick=function () {
|
||||
editor.mapInit();
|
||||
editor_mode.onmode('');
|
||||
editor.file.saveFloorFile(function (err) {
|
||||
if (err) {
|
||||
printe(err);
|
||||
throw(err)
|
||||
}
|
||||
;printf('地图清除成功');
|
||||
});
|
||||
editor.updateMap();
|
||||
clearTimeout(mapEditArea.formatTimer);
|
||||
clearTimeout(tip.timer);
|
||||
pout.value = '';
|
||||
mapEditArea.mapArr('');
|
||||
tip.whichShow(4);
|
||||
mapEditArea.error(0);
|
||||
}
|
||||
window.deleteMap=document.getElementById('deleteMap')
|
||||
deleteMap.onclick=function () {
|
||||
editor_mode.onmode('');
|
||||
var index = core.floorIds.indexOf(editor.currentFloorId);
|
||||
if (index>=0) {
|
||||
core.floorIds.splice(index,1);
|
||||
editor.file.editTower([['change', "['main']['floorIds']", core.floorIds]], function (objs_) {//console.log(objs_);
|
||||
if (objs_.slice(-1)[0] != null) {
|
||||
printe(objs_.slice(-1)[0]);
|
||||
throw(objs_.slice(-1)[0])
|
||||
}
|
||||
;printe('删除成功,请F5刷新编辑器生效');
|
||||
});
|
||||
}
|
||||
else printe('删除成功,请F5刷新编辑器生效');
|
||||
}
|
||||
|
||||
|
||||
editor.uifunctions.newMap_func = function () {
|
||||
|
||||
|
||||
@ -8,6 +8,8 @@ editor_file_wrapper = function (editor) {
|
||||
* }
|
||||
* 的形式记录所有更改过的文件,save时写入
|
||||
* <obj>的内容暂时还没想好
|
||||
*
|
||||
* Mark相关的思路搁置
|
||||
*/
|
||||
this.fileMark = {}
|
||||
}
|
||||
@ -136,6 +138,7 @@ editor_file_wrapper = function (editor) {
|
||||
// 给追加素材使用
|
||||
}
|
||||
|
||||
// Mark相关的思路搁置
|
||||
editor_file_proto.prototype.addMark = function (name) {
|
||||
// 把name对应的文件在editor.file.fileMark添加标记
|
||||
}
|
||||
@ -143,6 +146,905 @@ editor_file_wrapper = function (editor) {
|
||||
editor_file_proto.prototype.save = function (callback) {
|
||||
// 根据 editor.file.fileMark 把游戏对象格式化写入文件
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
}
|
||||
editor_file = function (editor, callback) {
|
||||
|
||||
var editor_file = new editor_file_proto();
|
||||
editor.file=editor_file;
|
||||
|
||||
editor.file.loadCommentjs(callback);
|
||||
|
||||
editor.file.saveFloorFile = function (callback) {
|
||||
//callback(err:String)
|
||||
checkCallback(callback);
|
||||
/* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) {
|
||||
callback('未选中文件或无数据');
|
||||
} */
|
||||
var filename = 'project/floors/' + editor.currentFloorId + '.js';
|
||||
var datastr = ['main.floors.', editor.currentFloorId, '=\n'];
|
||||
|
||||
if (core.floorIds.indexOf(editor.currentFloorId) >= 0) {
|
||||
for(var ii=0,name;name=['map','bgmap','fgmap'][ii];ii++){
|
||||
var mapArray=editor[name].map(function (v) {
|
||||
return v.map(function (v) {
|
||||
return v.idnum || v || 0
|
||||
})
|
||||
});
|
||||
editor.currentFloorData[name]=mapArray;
|
||||
}
|
||||
}
|
||||
editor.file.saveFloor(editor.currentFloorData, callback)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.saveNewFile = function (saveFilename, callback) {
|
||||
//saveAsFilename不含'/'不含'.js'
|
||||
checkCallback(callback);
|
||||
var currData=editor.currentFloorData;
|
||||
var saveStatus = document.getElementById('newMapStatus').checked;
|
||||
|
||||
var title = saveStatus?currData.title:"新建楼层";
|
||||
var name = saveStatus?currData.name:"0";
|
||||
if (/^mt\d+$/i.test(saveFilename)) {
|
||||
name = saveFilename.substring(2);
|
||||
title = "主塔 "+name+" 层";
|
||||
}
|
||||
|
||||
var width = parseInt(document.getElementById('newMapWidth').value);
|
||||
var height = parseInt(document.getElementById('newMapHeight').value);
|
||||
var row = [], map = [];
|
||||
for (var i=0;i<width;i++) row.push(0);
|
||||
for (var i=0;i<height;i++) map.push(row);
|
||||
editor.currentFloorData = Object.assign(JSON.parse(JSON.stringify(editor.file.comment._data.floors_template)), {
|
||||
floorId: saveFilename,
|
||||
title: title,
|
||||
name: name,
|
||||
width: width,
|
||||
height: height,
|
||||
map: map,
|
||||
},saveStatus?{
|
||||
canFlyTo: currData.canFlyTo,
|
||||
canUseQuickShop: currData.canUseQuickShop,
|
||||
cannotViewMap: currData.cannotViewMap,
|
||||
cannotMoveDirectly: currData.cannotMoveDirectly,
|
||||
item_ratio: currData.item_ratio,
|
||||
defaultGround: currData.defaultGround,
|
||||
bgm: currData.bgm,
|
||||
color: currData.color,
|
||||
weather: currData.weather,
|
||||
}:{});
|
||||
|
||||
Object.keys(editor.currentFloorData).forEach(function (t) {
|
||||
if (editor.currentFloorData[t] == null)
|
||||
delete editor.currentFloorData[t];
|
||||
})
|
||||
editor.currentFloorId = saveFilename;
|
||||
editor.file.saveFloorFile(callback);
|
||||
}
|
||||
editor.file.saveNewFiles = function (floorIdList, from, to, callback) {
|
||||
checkCallback(callback);
|
||||
var currData=editor.currentFloorData;
|
||||
var saveStatus = document.getElementById('newMapsStatus').checked;
|
||||
|
||||
var calValue = function (text, i) {
|
||||
return text.replace(/\${(.*?)}/g, function (word, value) {
|
||||
return eval(value);
|
||||
});
|
||||
}
|
||||
|
||||
var width = parseInt(document.getElementById('newMapsWidth').value);
|
||||
var height = parseInt(document.getElementById('newMapsHeight').value);
|
||||
|
||||
var row = [], map = [];
|
||||
for (var i=0;i<width;i++) row.push(0);
|
||||
for (var i=0;i<height;i++) map.push(row);
|
||||
|
||||
var filenames = floorIdList.map(function (v) {return "project/floors/"+v+".js";});
|
||||
var datas = [];
|
||||
for (var i=from;i<=to;i++) {
|
||||
var datastr = ['main.floors.', floorIdList[i-from], '=\n{'];
|
||||
var data = Object.assign(JSON.parse(JSON.stringify(editor.file.comment._data.floors_template)), {
|
||||
floorId: floorIdList[i-from],
|
||||
title: calValue(document.getElementById('newFloorTitles').value, i),
|
||||
name: calValue(document.getElementById('newFloorNames').value, i),
|
||||
width: width,
|
||||
height: height,
|
||||
map: map,
|
||||
},saveStatus?{
|
||||
canFlyTo: currData.canFlyTo,
|
||||
canUseQuickShop: currData.canUseQuickShop,
|
||||
cannotViewMap: currData.cannotViewMap,
|
||||
cannotMoveDirectly: currData.cannotMoveDirectly,
|
||||
item_ratio: currData.item_ratio,
|
||||
defaultGround: currData.defaultGround,
|
||||
bgm: currData.bgm,
|
||||
color: currData.color,
|
||||
weather: currData.weather,
|
||||
}:{});
|
||||
Object.keys(data).forEach(function (t) {
|
||||
if (data[t] == null)
|
||||
delete data[t];
|
||||
else {
|
||||
if (t=='map') {
|
||||
datastr = datastr.concat(['\n"', t, '": [\n', editor.file.formatMap(data[t]), '\n],']);
|
||||
}
|
||||
else {
|
||||
datastr = datastr.concat(['\n"', t, '": ', JSON.stringify(data[t], null, 4), ',']);
|
||||
}
|
||||
}
|
||||
});
|
||||
datastr = datastr.concat(['\n}']);
|
||||
datastr = datastr.join('');
|
||||
datas.push(encode(datastr));
|
||||
}
|
||||
editor.file.alertWhenCompress();
|
||||
fs.writeMultiFiles(filenames, datas, function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
//callback(err:String)
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.autoRegister = function (info, callback) {
|
||||
|
||||
var iconActions = [];
|
||||
var mapActions = [];
|
||||
var templateActions = [];
|
||||
|
||||
var image = info.images;
|
||||
var bindFaceIds = false;
|
||||
|
||||
if (image=='autotile') {
|
||||
callback('不能对自动元件进行自动注册!');
|
||||
return;
|
||||
}
|
||||
if (image=='npc48' && confirm("你想绑定npc48的朝向么?\n如果是,则会连续四个一组的对npc48的faceIds进行自动绑定。")) {
|
||||
bindFaceIds = true;
|
||||
}
|
||||
var c=image.toUpperCase().charAt(0);
|
||||
|
||||
// terrains id
|
||||
var terrainsId = [];
|
||||
Object.keys(core.material.icons.terrains).forEach(function (id) {
|
||||
terrainsId[core.material.icons.terrains[id]]=id;
|
||||
})
|
||||
|
||||
var allIds = [];
|
||||
editor.ids.forEach(function (v) {
|
||||
if (v.images==image) {
|
||||
allIds[v.y]=v;
|
||||
}
|
||||
})
|
||||
|
||||
var per_height = image.endsWith('48')?48:32;
|
||||
|
||||
var faceIds = []; // down, left, right, up
|
||||
|
||||
var idnum=300;
|
||||
for (var y=0; y<editor.widthsX[image][3]/per_height;y++) {
|
||||
if (allIds[y] != null) {
|
||||
faceIds.push(allIds[y]);
|
||||
continue;
|
||||
}
|
||||
while (editor.core.maps.blocksInfo[idnum]) idnum++;
|
||||
|
||||
// get id num
|
||||
var id = c+idnum;
|
||||
|
||||
if (image=='terrains' && terrainsId[y] != null) {
|
||||
id=terrainsId[y];
|
||||
}
|
||||
else {
|
||||
iconActions.push(["add", "['" + image + "']['" + id + "']", y])
|
||||
}
|
||||
mapActions.push(["add", "['" + idnum + "']", {'cls': image, 'id': id}]);
|
||||
faceIds.push({idnum: idnum, id: id});
|
||||
if (image=='items')
|
||||
templateActions.push(["add", "['items']['" + id + "']", editor.file.comment._data.items_template]);
|
||||
else if (image.indexOf('enemy')==0)
|
||||
templateActions.push(["add", "['" + id + "']", editor.file.comment._data.enemys_template]);
|
||||
idnum++;
|
||||
}
|
||||
|
||||
if (bindFaceIds) {
|
||||
for (var i = 0; i < faceIds.length - 3; i+=4) {
|
||||
var down = faceIds[i], left = faceIds[i+1], right = faceIds[i+2], up = faceIds[i+3];
|
||||
var obj = {down: down.id, left: left.id, right: right.id, up: up.id};
|
||||
mapActions.push(["add", "['" + down.idnum + "']['faceIds']", obj]);
|
||||
mapActions.push(["add", "['" + left.idnum + "']['faceIds']", obj]);
|
||||
mapActions.push(["add", "['" + right.idnum + "']['faceIds']", obj]);
|
||||
mapActions.push(["add", "['" + up.idnum + "']['faceIds']", obj]);
|
||||
}
|
||||
}
|
||||
|
||||
if (mapActions.length==0) {
|
||||
callback("没有要注册的项!");
|
||||
return;
|
||||
}
|
||||
|
||||
var templist = [];
|
||||
var tempcallback = function (err) {
|
||||
templist.push(err);
|
||||
if (templist.length == 3) {
|
||||
if (templist[0] != null || templist[1] != null || templist[2] != null)
|
||||
callback((templist[0] || '') + '\n' + (templist[1] || '') + '\n' + (templist[2] || ''));
|
||||
//这里如果一个成功一个失败会出严重bug
|
||||
else
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
if (iconActions.length>0)
|
||||
saveSetting('icons', iconActions, tempcallback);
|
||||
else tempcallback(null);
|
||||
|
||||
saveSetting('maps', mapActions, tempcallback);
|
||||
|
||||
if (image=='items')
|
||||
saveSetting('items', templateActions, tempcallback);
|
||||
else if (image.indexOf('enemy')==0)
|
||||
saveSetting('enemys', templateActions, tempcallback);
|
||||
else tempcallback(null);
|
||||
}
|
||||
|
||||
editor.file.registerAutotile = function (filename, callback) {
|
||||
var idnum = 140;
|
||||
while (editor.core.maps.blocksInfo[idnum]) idnum++;
|
||||
|
||||
var iconActions = [];
|
||||
var mapActions = [];
|
||||
|
||||
iconActions.push(["add", "['autotile']['" + filename + "']", 0]);
|
||||
mapActions.push(["add", "['" + idnum + "']", {'cls': 'autotile', 'id': filename, 'noPass': true}]);
|
||||
|
||||
var templist = [];
|
||||
var tempcallback = function (err) {
|
||||
templist.push(err);
|
||||
if (templist.length == 2) {
|
||||
if (templist[0] != null || templist[1] != null)
|
||||
callback((templist[0] || '') + '\n' + (templist[1] || ''));
|
||||
//这里如果一个成功一个失败会出严重bug
|
||||
else
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
|
||||
saveSetting('icons', iconActions, tempcallback);
|
||||
saveSetting('maps', mapActions, tempcallback);
|
||||
}
|
||||
|
||||
editor.file.changeIdAndIdnum = function (id, idnum, info, callback) {
|
||||
checkCallback(callback);
|
||||
|
||||
var changeOrNew=core.isset(editor_mode.info.id)?'change':'new'
|
||||
if(changeOrNew=='new'){
|
||||
//检查maps中是否有重复的idnum或id
|
||||
for (var ii in editor.core.maps.blocksInfo) {
|
||||
if (ii == idnum) {
|
||||
callback('idnum重复了');
|
||||
return;
|
||||
}
|
||||
if (editor.core.maps.blocksInfo[ii].id == id) {
|
||||
callback('id重复了');
|
||||
return;
|
||||
}
|
||||
}
|
||||
var templist = [];
|
||||
var tempcallback = function (err) {
|
||||
templist.push(err);
|
||||
if (templist.length == 2) {
|
||||
if (templist[0] != null || templist[1] != null)
|
||||
callback((templist[0] || '') + '\n' + (templist[1] || ''));
|
||||
//这里如果一个成功一个失败会出严重bug
|
||||
else
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
saveSetting('maps', [["add", "['" + idnum + "']", {'cls': info.images, 'id': id}]], tempcallback);
|
||||
saveSetting('icons', [["add", "['" + info.images + "']['" + id + "']", info.y]], tempcallback);
|
||||
if (info.images === 'items') {
|
||||
saveSetting('items', [["add", "['items']['" + id + "']", editor.file.comment._data.items_template]], function (err) {
|
||||
if (err) {
|
||||
printe(err);
|
||||
throw(err)
|
||||
}
|
||||
});
|
||||
}
|
||||
if (info.images === 'enemys' || info.images === 'enemy48') {
|
||||
saveSetting('enemys', [["add", "['" + id + "']", editor.file.comment._data.enemys_template]], function (err) {
|
||||
if (err) {
|
||||
printe(err);
|
||||
throw(err)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
callback(null);
|
||||
|
||||
}else{
|
||||
//检查maps中是否有重复的idnum或id
|
||||
for (var ii in editor.core.maps.blocksInfo) {
|
||||
if (editor.core.maps.blocksInfo[ii].id == id) {
|
||||
callback('id重复了');
|
||||
return;
|
||||
}
|
||||
}
|
||||
idnum = info.idnum;
|
||||
|
||||
maps_90f36752_8815_4be8_b32b_d7fad1d0542e[idnum].id = id;
|
||||
|
||||
var arr=[icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1,items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a,{enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80:enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80}]
|
||||
arr.forEach(function (obj) {
|
||||
for(var jj in obj){
|
||||
var ii=obj[jj]
|
||||
if (ii.hasOwnProperty(info.id)){
|
||||
ii[id]=ii[info.id];
|
||||
delete(ii[info.id]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
editor.file.save_icons_maps_items_enemys(callback)
|
||||
|
||||
}
|
||||
}
|
||||
//callback(err:String)
|
||||
editor.file.editItem = function (id, actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['items']['name']","红宝石的新名字"],
|
||||
["add","['items']['新的和name同级的属性']",123],
|
||||
["change","['itemEffectTip']","',攻击力+'+editor.core.values.redJewel"],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
actionList.forEach(function (value) {
|
||||
var tempindex = value[1].indexOf(']') + 1;
|
||||
value[1] = [value[1].slice(0, tempindex), "['" + id + "']", value[1].slice(tempindex)].join('');
|
||||
});
|
||||
saveSetting('items', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj_ = {};
|
||||
Object.keys(editor.file.comment._data.items._data).forEach(function (v) {
|
||||
if (isset(editor.core.items[v][id]) && v !== 'items')
|
||||
locObj_[v] = editor.core.items[v][id];
|
||||
else
|
||||
locObj_[v] = null;
|
||||
});
|
||||
locObj_['items'] = (function () {
|
||||
var locObj = Object.assign({}, editor.core.items.items[id]);
|
||||
Object.keys(editor.file.comment._data.items._data.items._data).forEach(function (v) {
|
||||
if (!isset(editor.core.items.items[id][v]))
|
||||
locObj[v] = null;
|
||||
});
|
||||
return locObj;
|
||||
})();
|
||||
return locObj_;
|
||||
})(),
|
||||
editor.file.comment._data.items,
|
||||
null]);
|
||||
}
|
||||
//只有items.cls是items的才有itemEffect和itemEffectTip,keys和constants和tools只有items
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
editor.file.editEnemy = function (id, actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['name']","初级巫师的新名字"],
|
||||
["add","['新的和name同级的属性']",123],
|
||||
["change","['bomb']",null],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
actionList.forEach(function (value) {
|
||||
value[1] = "['" + id + "']" + value[1];
|
||||
});
|
||||
saveSetting('enemys', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = Object.assign({}, editor.core.enemys.enemys[id]);
|
||||
Object.keys(editor.file.comment._data.enemys._data).forEach(function (v) {
|
||||
if (!isset(editor.core.enemys.enemys[id][v]))
|
||||
/* locObj[v]=editor.core.enemys.enemys[id][v];
|
||||
else */
|
||||
locObj[v] = null;
|
||||
});
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.comment._data.enemys,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
editor.file.editMapBlocksInfo = function (idnum, actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['events']",["\t[老人,magician]领域、夹击。\n请注意领域怪需要设置value为伤害数值,可参见样板中初级巫师的写法。"]],
|
||||
["change","['afterBattle']",null],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
var tempmap=[];
|
||||
for(var ii=0;ii<actionList.length;ii++){
|
||||
var value=actionList[ii];
|
||||
// 是tilesets 且未定义 且在这里是第一次定义
|
||||
if(idnum>=editor.core.icons.tilesetStartOffset && !isset(editor.core.maps.blocksInfo[idnum]) && tempmap.indexOf(idnum)===-1){
|
||||
actionList.splice(ii,0,["add","['" + idnum + "']",{"cls": "tileset", "id": "X"+idnum, "noPass": true}]);
|
||||
tempmap.push(idnum);
|
||||
ii++;
|
||||
}
|
||||
value[1] = "['" + idnum + "']" + value[1];
|
||||
}
|
||||
saveSetting('maps', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var sourceobj=editor.core.maps.blocksInfo[idnum];
|
||||
if(!isset(sourceobj) && idnum>=editor.core.icons.tilesetStartOffset)sourceobj={"cls": "tileset", "id": "X"+idnum, "noPass": true}
|
||||
var locObj = Object.assign({}, sourceobj);
|
||||
Object.keys(editor.file.comment._data.maps._data).forEach(function (v) {
|
||||
if (!isset(sourceobj[v]))
|
||||
locObj[v] = null;
|
||||
});
|
||||
locObj.idnum = idnum;
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.comment._data.maps,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.editLoc = function (x, y, actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['events']",["\t[老人,magician]领域、夹击。\n请注意领域怪需要设置value为伤害数值,可参见样板中初级巫师的写法。"]],
|
||||
["change","['afterBattle']",null],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
actionList.forEach(function (value) {
|
||||
if(/\['autoEvent'\]\['\d+'\]$/.test(value[1]))value[1]=value[1].replace(/\['\d+'\]$/,function(v){return "['" + x + "," + y + "']"+v})
|
||||
else value[1] = value[1] + "['" + x + "," + y + "']";
|
||||
});
|
||||
saveSetting('floorloc', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = {};
|
||||
Object.keys(editor.file.comment._data.floors._data.loc._data).forEach(function (v) {
|
||||
if (isset(editor.currentFloorData[v][x + ',' + y]))
|
||||
locObj[v] = editor.currentFloorData[v][x + ',' + y];
|
||||
else
|
||||
locObj[v] = null;
|
||||
});
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.comment._data.floors._data.loc,
|
||||
null]);
|
||||
}
|
||||
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.editFloor = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['title']",'样板 3 层'],
|
||||
["change","['color']",null],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
saveSetting('floors', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = Object.assign({}, editor.currentFloorData);
|
||||
Object.keys(editor.file.comment._data.floors._data.floor._data).forEach(function (v) {
|
||||
if (!isset(editor.currentFloorData[v]))
|
||||
/* locObj[v]=editor.currentFloorData[v];
|
||||
else */
|
||||
locObj[v] = null;
|
||||
});
|
||||
Object.keys(editor.file.comment._data.floors._data.loc._data).forEach(function (v) {
|
||||
delete(locObj[v]);
|
||||
});
|
||||
delete(locObj.map);
|
||||
delete(locObj.bgmap);
|
||||
delete(locObj.fgmap);
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.comment._data.floors._data.floor,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.editTower = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['firstData']['version']",'Ver 1.0.1 (Beta)'],
|
||||
["change","['values']['lavaDamage']",200],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
var data_obj = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d;
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
saveSetting('data', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
//var locObj=Object.assign({'main':{}},editor.core.data);
|
||||
var locObj = Object.assign({}, data_obj, {'main': {}});
|
||||
Object.keys(editor.file.dataComment._data.main._data).forEach(function (v) {
|
||||
if (isset(editor.main[v]))
|
||||
locObj.main[v] = data_obj.main[v];
|
||||
else
|
||||
locObj.main[v] = null;
|
||||
});
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.dataComment,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
var fmap = {};
|
||||
var fjson = JSON.stringify(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a, function (k, v) {
|
||||
if (v instanceof Function) {
|
||||
var id_ = editor.util.guid();
|
||||
fmap[id_] = v.toString();
|
||||
return id_;
|
||||
} else return v
|
||||
}, 4);
|
||||
var fobj = JSON.parse(fjson);
|
||||
editor.file.functionsMap = fmap;
|
||||
editor.file.functionsJSON = fjson;
|
||||
var buildlocobj = function (locObj) {
|
||||
for (var key in locObj) {
|
||||
if (typeof(locObj[key]) !== typeof('')) buildlocobj(locObj[key]);
|
||||
else locObj[key] = fmap[locObj[key]];
|
||||
}
|
||||
};
|
||||
|
||||
editor.file.editFunctions = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['events']['afterChangeLight']","function(x,y){console.log(x,y)}"],
|
||||
["change","['ui']['drawAbout']","function(){...}"],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
saveSetting('functions', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = JSON.parse(fjson);
|
||||
buildlocobj(locObj);
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.functionsComment,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.editCommonEvent = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['test']",['123']],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
var data_obj = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent;
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
actionList.forEach(function (value) {
|
||||
value[1] = "['commonEvent']" + value[1];
|
||||
});
|
||||
saveSetting('events', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
Object.assign({},data_obj),
|
||||
editor.file.eventsComment._data.commonEvent,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
var plmap = {};
|
||||
var pljson = JSON.stringify(plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1, function (k, v) {
|
||||
if (v instanceof Function) {
|
||||
var id_ = editor.util.guid();
|
||||
plmap[id_] = v.toString();
|
||||
return id_;
|
||||
} else if(v===null){
|
||||
var id_ = editor.util.guid();
|
||||
plmap[id_] = null;
|
||||
return id_;
|
||||
} return v
|
||||
}, 4);
|
||||
var plobj = JSON.parse(pljson);
|
||||
editor.file.pluginsMap = plmap;
|
||||
editor.file.pluginsObj = plobj;
|
||||
var buildpllocobj = function (locObj) {
|
||||
for (var key in locObj) {
|
||||
if (typeof(locObj[key]) !== typeof('')) buildpllocobj(locObj[key]);
|
||||
else locObj[key] = plmap[locObj[key]];
|
||||
}
|
||||
};
|
||||
|
||||
editor.file.editPlugins = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['test']","function(x,y){console.log(x,y)}"],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
saveSetting('plugins', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = JSON.parse(JSON.stringify(plobj));
|
||||
buildpllocobj(locObj);
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.pluginsComment,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
var isset = function (val) {
|
||||
if (val == undefined || val == null) {
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var checkCallback=function(callback){
|
||||
if (!isset(callback)) {
|
||||
printe('未设置callback');
|
||||
throw('未设置callback')
|
||||
}
|
||||
}
|
||||
|
||||
var encode = editor.util.encode64;
|
||||
|
||||
editor.file.save_icons_maps_items_enemys=function(callback){
|
||||
var check=[]
|
||||
saveSetting('icons',[],function(err){
|
||||
if(err){callback(err);return;}
|
||||
check.push('icons')
|
||||
if(check.length==4)callback(null);
|
||||
})
|
||||
saveSetting('maps',[],function(err){
|
||||
if(err){callback(err);return;}
|
||||
check.push('maps')
|
||||
if(check.length==4)callback(null);
|
||||
})
|
||||
saveSetting('items',[],function(err){
|
||||
if(err){callback(err);return;}
|
||||
check.push('items')
|
||||
if(check.length==4)callback(null);
|
||||
})
|
||||
saveSetting('enemys',[],function(err){
|
||||
if(err){callback(err);return;}
|
||||
check.push('enemys')
|
||||
if(check.length==4)callback(null);
|
||||
})
|
||||
}
|
||||
|
||||
var saveSetting = function (file, actionList, callback) {
|
||||
//console.log(file);
|
||||
//console.log(actionList);
|
||||
editor.file.alertWhenCompress();
|
||||
|
||||
if (file == 'icons') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var datastr = 'var icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1 = \n';
|
||||
datastr += JSON.stringify(icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1, null, '\t');
|
||||
fs.writeFile('project/icons.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'maps') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("maps_90f36752_8815_4be8_b32b_d7fad1d0542e" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var datastr = 'var maps_90f36752_8815_4be8_b32b_d7fad1d0542e = \n';
|
||||
//datastr+=JSON.stringify(maps_90f36752_8815_4be8_b32b_d7fad1d0542e,null,4);
|
||||
|
||||
var emap = {};
|
||||
var estr = JSON.stringify(maps_90f36752_8815_4be8_b32b_d7fad1d0542e, function (k, v) {
|
||||
if (v.id != null) {
|
||||
var id_ = editor.util.guid();
|
||||
emap[id_] = JSON.stringify(v);
|
||||
return id_;
|
||||
} else return v
|
||||
}, '\t');
|
||||
for (var id_ in emap) {
|
||||
estr = estr.replace('"' + id_ + '"', emap[id_])
|
||||
}
|
||||
datastr += estr;
|
||||
|
||||
fs.writeFile('project/maps.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'items') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var datastr = 'var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = \n';
|
||||
datastr += JSON.stringify(items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a, null, '\t');
|
||||
fs.writeFile('project/items.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'enemys') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var datastr = 'var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 = \n';
|
||||
var emap = {};
|
||||
var estr = JSON.stringify(enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80, function (k, v) {
|
||||
if (v.hp != null) {
|
||||
var id_ = editor.util.guid();
|
||||
emap[id_] = JSON.stringify(v);
|
||||
return id_;
|
||||
} else return v
|
||||
}, '\t');
|
||||
for (var id_ in emap) {
|
||||
estr = estr.replace('"' + id_ + '"', emap[id_])
|
||||
}
|
||||
datastr += estr;
|
||||
fs.writeFile('project/enemys.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'data') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
if (data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds.indexOf(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.floorId) < 0)
|
||||
data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.floorId = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds[0];
|
||||
var datastr = 'var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = \n';
|
||||
datastr += JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, null, '\t');
|
||||
fs.writeFile('project/data.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'functions') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("fmap[fobj" + value[1] + ']=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var fraw = fjson;
|
||||
for (var id_ in fmap) {
|
||||
fraw = fraw.replace('"' + id_ + '"', fmap[id_])
|
||||
}
|
||||
var datastr = 'var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = \n';
|
||||
datastr += fraw;
|
||||
fs.writeFile('project/functions.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'floorloc') {
|
||||
actionList.forEach(function (value) {
|
||||
// 检测null/undefined
|
||||
if(/\['autoEvent'\]\['\d+,\d+'\]\['\d+'\]$/.test(value[1])){
|
||||
var tempvalue=value[1].replace(/\['\d+'\]$/,'')
|
||||
tempvalue="editor.currentFloorData" +tempvalue
|
||||
tempvalue=tempvalue+'='+tempvalue+'||{}'
|
||||
eval(tempvalue)
|
||||
}
|
||||
if (value[2]==null && value[0]!=='add')
|
||||
eval("delete editor.currentFloorData" + value[1]);
|
||||
else
|
||||
eval("editor.currentFloorData" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
editor.file.saveFloorFile(callback);
|
||||
return;
|
||||
}
|
||||
if (file == 'floors') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("editor.currentFloorData" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
editor.file.saveFloorFile(callback);
|
||||
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;
|
||||
}
|
||||
if (file == 'plugins') {
|
||||
actionList.forEach(function (value) {
|
||||
if(value[0]==='add'){
|
||||
eval("plobj" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
} else {
|
||||
eval("plmap[plobj" + value[1] + ']=' + JSON.stringify(value[2]));
|
||||
}
|
||||
});
|
||||
var plraw = JSON.stringify(plobj,null,4);
|
||||
for (var id_ in plmap) {
|
||||
plraw = plraw.replace('"' + id_ + '"', plmap[id_])
|
||||
}
|
||||
var datastr = 'var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = \n';
|
||||
datastr += plraw;
|
||||
fs.writeFile('project/plugins.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
callback('出错了,要设置的文件名不识别');
|
||||
}
|
||||
|
||||
editor.file.saveSetting = saveSetting;
|
||||
|
||||
return editor_file;
|
||||
}
|
||||
//editor_file = editor_file(editor);
|
||||
@ -1,904 +0,0 @@
|
||||
editor_file = function (editor, callback) {
|
||||
|
||||
var editor_file = new editor_file_proto();
|
||||
editor.file=editor_file;
|
||||
|
||||
editor.file.loadCommentjs(callback);
|
||||
|
||||
editor.file.saveFloorFile = function (callback) {
|
||||
//callback(err:String)
|
||||
checkCallback(callback);
|
||||
/* if (!isset(editor.currentFloorId) || !isset(editor.currentFloorData)) {
|
||||
callback('未选中文件或无数据');
|
||||
} */
|
||||
var filename = 'project/floors/' + editor.currentFloorId + '.js';
|
||||
var datastr = ['main.floors.', editor.currentFloorId, '=\n'];
|
||||
|
||||
if (core.floorIds.indexOf(editor.currentFloorId) >= 0) {
|
||||
for(var ii=0,name;name=['map','bgmap','fgmap'][ii];ii++){
|
||||
var mapArray=editor[name].map(function (v) {
|
||||
return v.map(function (v) {
|
||||
return v.idnum || v || 0
|
||||
})
|
||||
});
|
||||
editor.currentFloorData[name]=mapArray;
|
||||
}
|
||||
}
|
||||
editor.file.saveFloor(editor.currentFloorData, callback)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.saveNewFile = function (saveFilename, callback) {
|
||||
//saveAsFilename不含'/'不含'.js'
|
||||
checkCallback(callback);
|
||||
var currData=editor.currentFloorData;
|
||||
var saveStatus = document.getElementById('newMapStatus').checked;
|
||||
|
||||
var title = saveStatus?currData.title:"新建楼层";
|
||||
var name = saveStatus?currData.name:"0";
|
||||
if (/^mt\d+$/i.test(saveFilename)) {
|
||||
name = saveFilename.substring(2);
|
||||
title = "主塔 "+name+" 层";
|
||||
}
|
||||
|
||||
var width = parseInt(document.getElementById('newMapWidth').value);
|
||||
var height = parseInt(document.getElementById('newMapHeight').value);
|
||||
var row = [], map = [];
|
||||
for (var i=0;i<width;i++) row.push(0);
|
||||
for (var i=0;i<height;i++) map.push(row);
|
||||
editor.currentFloorData = Object.assign(JSON.parse(JSON.stringify(editor.file.comment._data.floors_template)), {
|
||||
floorId: saveFilename,
|
||||
title: title,
|
||||
name: name,
|
||||
width: width,
|
||||
height: height,
|
||||
map: map,
|
||||
},saveStatus?{
|
||||
canFlyTo: currData.canFlyTo,
|
||||
canUseQuickShop: currData.canUseQuickShop,
|
||||
cannotViewMap: currData.cannotViewMap,
|
||||
cannotMoveDirectly: currData.cannotMoveDirectly,
|
||||
item_ratio: currData.item_ratio,
|
||||
defaultGround: currData.defaultGround,
|
||||
bgm: currData.bgm,
|
||||
color: currData.color,
|
||||
weather: currData.weather,
|
||||
}:{});
|
||||
|
||||
Object.keys(editor.currentFloorData).forEach(function (t) {
|
||||
if (editor.currentFloorData[t] == null)
|
||||
delete editor.currentFloorData[t];
|
||||
})
|
||||
editor.currentFloorId = saveFilename;
|
||||
editor.file.saveFloorFile(callback);
|
||||
}
|
||||
editor.file.saveNewFiles = function (floorIdList, from, to, callback) {
|
||||
checkCallback(callback);
|
||||
var currData=editor.currentFloorData;
|
||||
var saveStatus = document.getElementById('newMapsStatus').checked;
|
||||
|
||||
var calValue = function (text, i) {
|
||||
return text.replace(/\${(.*?)}/g, function (word, value) {
|
||||
return eval(value);
|
||||
});
|
||||
}
|
||||
|
||||
var width = parseInt(document.getElementById('newMapsWidth').value);
|
||||
var height = parseInt(document.getElementById('newMapsHeight').value);
|
||||
|
||||
var row = [], map = [];
|
||||
for (var i=0;i<width;i++) row.push(0);
|
||||
for (var i=0;i<height;i++) map.push(row);
|
||||
|
||||
var filenames = floorIdList.map(function (v) {return "project/floors/"+v+".js";});
|
||||
var datas = [];
|
||||
for (var i=from;i<=to;i++) {
|
||||
var datastr = ['main.floors.', floorIdList[i-from], '=\n{'];
|
||||
var data = Object.assign(JSON.parse(JSON.stringify(editor.file.comment._data.floors_template)), {
|
||||
floorId: floorIdList[i-from],
|
||||
title: calValue(document.getElementById('newFloorTitles').value, i),
|
||||
name: calValue(document.getElementById('newFloorNames').value, i),
|
||||
width: width,
|
||||
height: height,
|
||||
map: map,
|
||||
},saveStatus?{
|
||||
canFlyTo: currData.canFlyTo,
|
||||
canUseQuickShop: currData.canUseQuickShop,
|
||||
cannotViewMap: currData.cannotViewMap,
|
||||
cannotMoveDirectly: currData.cannotMoveDirectly,
|
||||
item_ratio: currData.item_ratio,
|
||||
defaultGround: currData.defaultGround,
|
||||
bgm: currData.bgm,
|
||||
color: currData.color,
|
||||
weather: currData.weather,
|
||||
}:{});
|
||||
Object.keys(data).forEach(function (t) {
|
||||
if (data[t] == null)
|
||||
delete data[t];
|
||||
else {
|
||||
if (t=='map') {
|
||||
datastr = datastr.concat(['\n"', t, '": [\n', editor.file.formatMap(data[t]), '\n],']);
|
||||
}
|
||||
else {
|
||||
datastr = datastr.concat(['\n"', t, '": ', JSON.stringify(data[t], null, 4), ',']);
|
||||
}
|
||||
}
|
||||
});
|
||||
datastr = datastr.concat(['\n}']);
|
||||
datastr = datastr.join('');
|
||||
datas.push(encode(datastr));
|
||||
}
|
||||
editor.file.alertWhenCompress();
|
||||
fs.writeMultiFiles(filenames, datas, function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
//callback(err:String)
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.autoRegister = function (info, callback) {
|
||||
|
||||
var iconActions = [];
|
||||
var mapActions = [];
|
||||
var templateActions = [];
|
||||
|
||||
var image = info.images;
|
||||
var bindFaceIds = false;
|
||||
|
||||
if (image=='autotile') {
|
||||
callback('不能对自动元件进行自动注册!');
|
||||
return;
|
||||
}
|
||||
if (image=='npc48' && confirm("你想绑定npc48的朝向么?\n如果是,则会连续四个一组的对npc48的faceIds进行自动绑定。")) {
|
||||
bindFaceIds = true;
|
||||
}
|
||||
var c=image.toUpperCase().charAt(0);
|
||||
|
||||
// terrains id
|
||||
var terrainsId = [];
|
||||
Object.keys(core.material.icons.terrains).forEach(function (id) {
|
||||
terrainsId[core.material.icons.terrains[id]]=id;
|
||||
})
|
||||
|
||||
var allIds = [];
|
||||
editor.ids.forEach(function (v) {
|
||||
if (v.images==image) {
|
||||
allIds[v.y]=v;
|
||||
}
|
||||
})
|
||||
|
||||
var per_height = image.endsWith('48')?48:32;
|
||||
|
||||
var faceIds = []; // down, left, right, up
|
||||
|
||||
var idnum=300;
|
||||
for (var y=0; y<editor.widthsX[image][3]/per_height;y++) {
|
||||
if (allIds[y] != null) {
|
||||
faceIds.push(allIds[y]);
|
||||
continue;
|
||||
}
|
||||
while (editor.core.maps.blocksInfo[idnum]) idnum++;
|
||||
|
||||
// get id num
|
||||
var id = c+idnum;
|
||||
|
||||
if (image=='terrains' && terrainsId[y] != null) {
|
||||
id=terrainsId[y];
|
||||
}
|
||||
else {
|
||||
iconActions.push(["add", "['" + image + "']['" + id + "']", y])
|
||||
}
|
||||
mapActions.push(["add", "['" + idnum + "']", {'cls': image, 'id': id}]);
|
||||
faceIds.push({idnum: idnum, id: id});
|
||||
if (image=='items')
|
||||
templateActions.push(["add", "['items']['" + id + "']", editor.file.comment._data.items_template]);
|
||||
else if (image.indexOf('enemy')==0)
|
||||
templateActions.push(["add", "['" + id + "']", editor.file.comment._data.enemys_template]);
|
||||
idnum++;
|
||||
}
|
||||
|
||||
if (bindFaceIds) {
|
||||
for (var i = 0; i < faceIds.length - 3; i+=4) {
|
||||
var down = faceIds[i], left = faceIds[i+1], right = faceIds[i+2], up = faceIds[i+3];
|
||||
var obj = {down: down.id, left: left.id, right: right.id, up: up.id};
|
||||
mapActions.push(["add", "['" + down.idnum + "']['faceIds']", obj]);
|
||||
mapActions.push(["add", "['" + left.idnum + "']['faceIds']", obj]);
|
||||
mapActions.push(["add", "['" + right.idnum + "']['faceIds']", obj]);
|
||||
mapActions.push(["add", "['" + up.idnum + "']['faceIds']", obj]);
|
||||
}
|
||||
}
|
||||
|
||||
if (mapActions.length==0) {
|
||||
callback("没有要注册的项!");
|
||||
return;
|
||||
}
|
||||
|
||||
var templist = [];
|
||||
var tempcallback = function (err) {
|
||||
templist.push(err);
|
||||
if (templist.length == 3) {
|
||||
if (templist[0] != null || templist[1] != null || templist[2] != null)
|
||||
callback((templist[0] || '') + '\n' + (templist[1] || '') + '\n' + (templist[2] || ''));
|
||||
//这里如果一个成功一个失败会出严重bug
|
||||
else
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
if (iconActions.length>0)
|
||||
saveSetting('icons', iconActions, tempcallback);
|
||||
else tempcallback(null);
|
||||
|
||||
saveSetting('maps', mapActions, tempcallback);
|
||||
|
||||
if (image=='items')
|
||||
saveSetting('items', templateActions, tempcallback);
|
||||
else if (image.indexOf('enemy')==0)
|
||||
saveSetting('enemys', templateActions, tempcallback);
|
||||
else tempcallback(null);
|
||||
}
|
||||
|
||||
editor.file.registerAutotile = function (filename, callback) {
|
||||
var idnum = 140;
|
||||
while (editor.core.maps.blocksInfo[idnum]) idnum++;
|
||||
|
||||
var iconActions = [];
|
||||
var mapActions = [];
|
||||
|
||||
iconActions.push(["add", "['autotile']['" + filename + "']", 0]);
|
||||
mapActions.push(["add", "['" + idnum + "']", {'cls': 'autotile', 'id': filename, 'noPass': true}]);
|
||||
|
||||
var templist = [];
|
||||
var tempcallback = function (err) {
|
||||
templist.push(err);
|
||||
if (templist.length == 2) {
|
||||
if (templist[0] != null || templist[1] != null)
|
||||
callback((templist[0] || '') + '\n' + (templist[1] || ''));
|
||||
//这里如果一个成功一个失败会出严重bug
|
||||
else
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
|
||||
saveSetting('icons', iconActions, tempcallback);
|
||||
saveSetting('maps', mapActions, tempcallback);
|
||||
}
|
||||
|
||||
editor.file.changeIdAndIdnum = function (id, idnum, info, callback) {
|
||||
checkCallback(callback);
|
||||
|
||||
var changeOrNew=core.isset(editor_mode.info.id)?'change':'new'
|
||||
if(changeOrNew=='new'){
|
||||
//检查maps中是否有重复的idnum或id
|
||||
for (var ii in editor.core.maps.blocksInfo) {
|
||||
if (ii == idnum) {
|
||||
callback('idnum重复了');
|
||||
return;
|
||||
}
|
||||
if (editor.core.maps.blocksInfo[ii].id == id) {
|
||||
callback('id重复了');
|
||||
return;
|
||||
}
|
||||
}
|
||||
var templist = [];
|
||||
var tempcallback = function (err) {
|
||||
templist.push(err);
|
||||
if (templist.length == 2) {
|
||||
if (templist[0] != null || templist[1] != null)
|
||||
callback((templist[0] || '') + '\n' + (templist[1] || ''));
|
||||
//这里如果一个成功一个失败会出严重bug
|
||||
else
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
saveSetting('maps', [["add", "['" + idnum + "']", {'cls': info.images, 'id': id}]], tempcallback);
|
||||
saveSetting('icons', [["add", "['" + info.images + "']['" + id + "']", info.y]], tempcallback);
|
||||
if (info.images === 'items') {
|
||||
saveSetting('items', [["add", "['items']['" + id + "']", editor.file.comment._data.items_template]], function (err) {
|
||||
if (err) {
|
||||
printe(err);
|
||||
throw(err)
|
||||
}
|
||||
});
|
||||
}
|
||||
if (info.images === 'enemys' || info.images === 'enemy48') {
|
||||
saveSetting('enemys', [["add", "['" + id + "']", editor.file.comment._data.enemys_template]], function (err) {
|
||||
if (err) {
|
||||
printe(err);
|
||||
throw(err)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
callback(null);
|
||||
|
||||
}else{
|
||||
//检查maps中是否有重复的idnum或id
|
||||
for (var ii in editor.core.maps.blocksInfo) {
|
||||
if (editor.core.maps.blocksInfo[ii].id == id) {
|
||||
callback('id重复了');
|
||||
return;
|
||||
}
|
||||
}
|
||||
idnum = info.idnum;
|
||||
|
||||
maps_90f36752_8815_4be8_b32b_d7fad1d0542e[idnum].id = id;
|
||||
|
||||
var arr=[icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1,items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a,{enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80:enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80}]
|
||||
arr.forEach(function (obj) {
|
||||
for(var jj in obj){
|
||||
var ii=obj[jj]
|
||||
if (ii.hasOwnProperty(info.id)){
|
||||
ii[id]=ii[info.id];
|
||||
delete(ii[info.id]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
editor.file.save_icons_maps_items_enemys(callback)
|
||||
|
||||
}
|
||||
}
|
||||
//callback(err:String)
|
||||
editor.file.editItem = function (id, actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['items']['name']","红宝石的新名字"],
|
||||
["add","['items']['新的和name同级的属性']",123],
|
||||
["change","['itemEffectTip']","',攻击力+'+editor.core.values.redJewel"],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
actionList.forEach(function (value) {
|
||||
var tempindex = value[1].indexOf(']') + 1;
|
||||
value[1] = [value[1].slice(0, tempindex), "['" + id + "']", value[1].slice(tempindex)].join('');
|
||||
});
|
||||
saveSetting('items', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj_ = {};
|
||||
Object.keys(editor.file.comment._data.items._data).forEach(function (v) {
|
||||
if (isset(editor.core.items[v][id]) && v !== 'items')
|
||||
locObj_[v] = editor.core.items[v][id];
|
||||
else
|
||||
locObj_[v] = null;
|
||||
});
|
||||
locObj_['items'] = (function () {
|
||||
var locObj = Object.assign({}, editor.core.items.items[id]);
|
||||
Object.keys(editor.file.comment._data.items._data.items._data).forEach(function (v) {
|
||||
if (!isset(editor.core.items.items[id][v]))
|
||||
locObj[v] = null;
|
||||
});
|
||||
return locObj;
|
||||
})();
|
||||
return locObj_;
|
||||
})(),
|
||||
editor.file.comment._data.items,
|
||||
null]);
|
||||
}
|
||||
//只有items.cls是items的才有itemEffect和itemEffectTip,keys和constants和tools只有items
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
editor.file.editEnemy = function (id, actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['name']","初级巫师的新名字"],
|
||||
["add","['新的和name同级的属性']",123],
|
||||
["change","['bomb']",null],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
actionList.forEach(function (value) {
|
||||
value[1] = "['" + id + "']" + value[1];
|
||||
});
|
||||
saveSetting('enemys', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = Object.assign({}, editor.core.enemys.enemys[id]);
|
||||
Object.keys(editor.file.comment._data.enemys._data).forEach(function (v) {
|
||||
if (!isset(editor.core.enemys.enemys[id][v]))
|
||||
/* locObj[v]=editor.core.enemys.enemys[id][v];
|
||||
else */
|
||||
locObj[v] = null;
|
||||
});
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.comment._data.enemys,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
editor.file.editMapBlocksInfo = function (idnum, actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['events']",["\t[老人,magician]领域、夹击。\n请注意领域怪需要设置value为伤害数值,可参见样板中初级巫师的写法。"]],
|
||||
["change","['afterBattle']",null],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
var tempmap=[];
|
||||
for(var ii=0;ii<actionList.length;ii++){
|
||||
var value=actionList[ii];
|
||||
// 是tilesets 且未定义 且在这里是第一次定义
|
||||
if(idnum>=editor.core.icons.tilesetStartOffset && !isset(editor.core.maps.blocksInfo[idnum]) && tempmap.indexOf(idnum)===-1){
|
||||
actionList.splice(ii,0,["add","['" + idnum + "']",{"cls": "tileset", "id": "X"+idnum, "noPass": true}]);
|
||||
tempmap.push(idnum);
|
||||
ii++;
|
||||
}
|
||||
value[1] = "['" + idnum + "']" + value[1];
|
||||
}
|
||||
saveSetting('maps', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var sourceobj=editor.core.maps.blocksInfo[idnum];
|
||||
if(!isset(sourceobj) && idnum>=editor.core.icons.tilesetStartOffset)sourceobj={"cls": "tileset", "id": "X"+idnum, "noPass": true}
|
||||
var locObj = Object.assign({}, sourceobj);
|
||||
Object.keys(editor.file.comment._data.maps._data).forEach(function (v) {
|
||||
if (!isset(sourceobj[v]))
|
||||
locObj[v] = null;
|
||||
});
|
||||
locObj.idnum = idnum;
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.comment._data.maps,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.editLoc = function (x, y, actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['events']",["\t[老人,magician]领域、夹击。\n请注意领域怪需要设置value为伤害数值,可参见样板中初级巫师的写法。"]],
|
||||
["change","['afterBattle']",null],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
actionList.forEach(function (value) {
|
||||
if(/\['autoEvent'\]\['\d+'\]$/.test(value[1]))value[1]=value[1].replace(/\['\d+'\]$/,function(v){return "['" + x + "," + y + "']"+v})
|
||||
else value[1] = value[1] + "['" + x + "," + y + "']";
|
||||
});
|
||||
saveSetting('floorloc', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = {};
|
||||
Object.keys(editor.file.comment._data.floors._data.loc._data).forEach(function (v) {
|
||||
if (isset(editor.currentFloorData[v][x + ',' + y]))
|
||||
locObj[v] = editor.currentFloorData[v][x + ',' + y];
|
||||
else
|
||||
locObj[v] = null;
|
||||
});
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.comment._data.floors._data.loc,
|
||||
null]);
|
||||
}
|
||||
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.editFloor = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['title']",'样板 3 层'],
|
||||
["change","['color']",null],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
saveSetting('floors', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = Object.assign({}, editor.currentFloorData);
|
||||
Object.keys(editor.file.comment._data.floors._data.floor._data).forEach(function (v) {
|
||||
if (!isset(editor.currentFloorData[v]))
|
||||
/* locObj[v]=editor.currentFloorData[v];
|
||||
else */
|
||||
locObj[v] = null;
|
||||
});
|
||||
Object.keys(editor.file.comment._data.floors._data.loc._data).forEach(function (v) {
|
||||
delete(locObj[v]);
|
||||
});
|
||||
delete(locObj.map);
|
||||
delete(locObj.bgmap);
|
||||
delete(locObj.fgmap);
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.comment._data.floors._data.floor,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.editTower = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['firstData']['version']",'Ver 1.0.1 (Beta)'],
|
||||
["change","['values']['lavaDamage']",200],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
var data_obj = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d;
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
saveSetting('data', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
//var locObj=Object.assign({'main':{}},editor.core.data);
|
||||
var locObj = Object.assign({}, data_obj, {'main': {}});
|
||||
Object.keys(editor.file.dataComment._data.main._data).forEach(function (v) {
|
||||
if (isset(editor.main[v]))
|
||||
locObj.main[v] = data_obj.main[v];
|
||||
else
|
||||
locObj.main[v] = null;
|
||||
});
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.dataComment,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
var fmap = {};
|
||||
var fjson = JSON.stringify(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a, function (k, v) {
|
||||
if (v instanceof Function) {
|
||||
var id_ = editor.util.guid();
|
||||
fmap[id_] = v.toString();
|
||||
return id_;
|
||||
} else return v
|
||||
}, 4);
|
||||
var fobj = JSON.parse(fjson);
|
||||
editor.file.functionsMap = fmap;
|
||||
editor.file.functionsJSON = fjson;
|
||||
var buildlocobj = function (locObj) {
|
||||
for (var key in locObj) {
|
||||
if (typeof(locObj[key]) !== typeof('')) buildlocobj(locObj[key]);
|
||||
else locObj[key] = fmap[locObj[key]];
|
||||
}
|
||||
};
|
||||
|
||||
editor.file.editFunctions = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['events']['afterChangeLight']","function(x,y){console.log(x,y)}"],
|
||||
["change","['ui']['drawAbout']","function(){...}"],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
saveSetting('functions', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = JSON.parse(fjson);
|
||||
buildlocobj(locObj);
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.functionsComment,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
editor.file.editCommonEvent = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['test']",['123']],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
var data_obj = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent;
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
actionList.forEach(function (value) {
|
||||
value[1] = "['commonEvent']" + value[1];
|
||||
});
|
||||
saveSetting('events', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
Object.assign({},data_obj),
|
||||
editor.file.eventsComment._data.commonEvent,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
var plmap = {};
|
||||
var pljson = JSON.stringify(plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1, function (k, v) {
|
||||
if (v instanceof Function) {
|
||||
var id_ = editor.util.guid();
|
||||
plmap[id_] = v.toString();
|
||||
return id_;
|
||||
} else if(v===null){
|
||||
var id_ = editor.util.guid();
|
||||
plmap[id_] = null;
|
||||
return id_;
|
||||
} return v
|
||||
}, 4);
|
||||
var plobj = JSON.parse(pljson);
|
||||
editor.file.pluginsMap = plmap;
|
||||
editor.file.pluginsObj = plobj;
|
||||
var buildpllocobj = function (locObj) {
|
||||
for (var key in locObj) {
|
||||
if (typeof(locObj[key]) !== typeof('')) buildpllocobj(locObj[key]);
|
||||
else locObj[key] = plmap[locObj[key]];
|
||||
}
|
||||
};
|
||||
|
||||
editor.file.editPlugins = function (actionList, callback) {
|
||||
/*actionList:[
|
||||
["change","['test']","function(x,y){console.log(x,y)}"],
|
||||
]
|
||||
为[]时只查询不修改
|
||||
*/
|
||||
checkCallback(callback);
|
||||
if (isset(actionList) && actionList.length > 0) {
|
||||
saveSetting('plugins', actionList, function (err) {
|
||||
callback([err]);
|
||||
});
|
||||
} else {
|
||||
callback([
|
||||
(function () {
|
||||
var locObj = JSON.parse(JSON.stringify(plobj));
|
||||
buildpllocobj(locObj);
|
||||
return locObj;
|
||||
})(),
|
||||
editor.file.pluginsComment,
|
||||
null]);
|
||||
}
|
||||
}
|
||||
//callback([obj,commentObj,err:String])
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
var isset = function (val) {
|
||||
if (val == undefined || val == null) {
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var checkCallback=function(callback){
|
||||
if (!isset(callback)) {
|
||||
printe('未设置callback');
|
||||
throw('未设置callback')
|
||||
}
|
||||
}
|
||||
|
||||
var encode = editor.util.encode64;
|
||||
|
||||
var alertWhenCompress = function(){
|
||||
if(editor.useCompress===true){
|
||||
editor.useCompress='alerted';
|
||||
setTimeout("alert('当前游戏使用的是压缩文件,修改完成后请使用启动服务.exe->Js代码压缩工具重新压缩,或者把main.js的useCompress改成false来使用原始文件')",1000)
|
||||
}
|
||||
}
|
||||
|
||||
editor.file.save_icons_maps_items_enemys=function(callback){
|
||||
var check=[]
|
||||
saveSetting('icons',[],function(err){
|
||||
if(err){callback(err);return;}
|
||||
check.push('icons')
|
||||
if(check.length==4)callback(null);
|
||||
})
|
||||
saveSetting('maps',[],function(err){
|
||||
if(err){callback(err);return;}
|
||||
check.push('maps')
|
||||
if(check.length==4)callback(null);
|
||||
})
|
||||
saveSetting('items',[],function(err){
|
||||
if(err){callback(err);return;}
|
||||
check.push('items')
|
||||
if(check.length==4)callback(null);
|
||||
})
|
||||
saveSetting('enemys',[],function(err){
|
||||
if(err){callback(err);return;}
|
||||
check.push('enemys')
|
||||
if(check.length==4)callback(null);
|
||||
})
|
||||
}
|
||||
|
||||
var saveSetting = function (file, actionList, callback) {
|
||||
//console.log(file);
|
||||
//console.log(actionList);
|
||||
editor.file.alertWhenCompress();
|
||||
|
||||
if (file == 'icons') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var datastr = 'var icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1 = \n';
|
||||
datastr += JSON.stringify(icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1, null, '\t');
|
||||
fs.writeFile('project/icons.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'maps') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("maps_90f36752_8815_4be8_b32b_d7fad1d0542e" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var datastr = 'var maps_90f36752_8815_4be8_b32b_d7fad1d0542e = \n';
|
||||
//datastr+=JSON.stringify(maps_90f36752_8815_4be8_b32b_d7fad1d0542e,null,4);
|
||||
|
||||
var emap = {};
|
||||
var estr = JSON.stringify(maps_90f36752_8815_4be8_b32b_d7fad1d0542e, function (k, v) {
|
||||
if (v.id != null) {
|
||||
var id_ = editor.util.guid();
|
||||
emap[id_] = JSON.stringify(v);
|
||||
return id_;
|
||||
} else return v
|
||||
}, '\t');
|
||||
for (var id_ in emap) {
|
||||
estr = estr.replace('"' + id_ + '"', emap[id_])
|
||||
}
|
||||
datastr += estr;
|
||||
|
||||
fs.writeFile('project/maps.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'items') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var datastr = 'var items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a = \n';
|
||||
datastr += JSON.stringify(items_296f5d02_12fd_4166_a7c1_b5e830c9ee3a, null, '\t');
|
||||
fs.writeFile('project/items.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'enemys') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var datastr = 'var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 = \n';
|
||||
var emap = {};
|
||||
var estr = JSON.stringify(enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80, function (k, v) {
|
||||
if (v.hp != null) {
|
||||
var id_ = editor.util.guid();
|
||||
emap[id_] = JSON.stringify(v);
|
||||
return id_;
|
||||
} else return v
|
||||
}, '\t');
|
||||
for (var id_ in emap) {
|
||||
estr = estr.replace('"' + id_ + '"', emap[id_])
|
||||
}
|
||||
datastr += estr;
|
||||
fs.writeFile('project/enemys.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'data') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
if (data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds.indexOf(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.floorId) < 0)
|
||||
data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.floorId = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds[0];
|
||||
var datastr = 'var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = \n';
|
||||
datastr += JSON.stringify(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d, null, '\t');
|
||||
fs.writeFile('project/data.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'functions') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("fmap[fobj" + value[1] + ']=' + JSON.stringify(value[2]));
|
||||
});
|
||||
var fraw = fjson;
|
||||
for (var id_ in fmap) {
|
||||
fraw = fraw.replace('"' + id_ + '"', fmap[id_])
|
||||
}
|
||||
var datastr = 'var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = \n';
|
||||
datastr += fraw;
|
||||
fs.writeFile('project/functions.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (file == 'floorloc') {
|
||||
actionList.forEach(function (value) {
|
||||
// 检测null/undefined
|
||||
if(/\['autoEvent'\]\['\d+,\d+'\]\['\d+'\]$/.test(value[1])){
|
||||
var tempvalue=value[1].replace(/\['\d+'\]$/,'')
|
||||
tempvalue="editor.currentFloorData" +tempvalue
|
||||
tempvalue=tempvalue+'='+tempvalue+'||{}'
|
||||
eval(tempvalue)
|
||||
}
|
||||
if (value[2]==null && value[0]!=='add')
|
||||
eval("delete editor.currentFloorData" + value[1]);
|
||||
else
|
||||
eval("editor.currentFloorData" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
editor.file.saveFloorFile(callback);
|
||||
return;
|
||||
}
|
||||
if (file == 'floors') {
|
||||
actionList.forEach(function (value) {
|
||||
eval("editor.currentFloorData" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
});
|
||||
editor.file.saveFloorFile(callback);
|
||||
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;
|
||||
}
|
||||
if (file == 'plugins') {
|
||||
actionList.forEach(function (value) {
|
||||
if(value[0]==='add'){
|
||||
eval("plobj" + value[1] + '=' + JSON.stringify(value[2]));
|
||||
} else {
|
||||
eval("plmap[plobj" + value[1] + ']=' + JSON.stringify(value[2]));
|
||||
}
|
||||
});
|
||||
var plraw = JSON.stringify(plobj,null,4);
|
||||
for (var id_ in plmap) {
|
||||
plraw = plraw.replace('"' + id_ + '"', plmap[id_])
|
||||
}
|
||||
var datastr = 'var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = \n';
|
||||
datastr += plraw;
|
||||
fs.writeFile('project/plugins.js', encode(datastr), 'base64', function (err, data) {
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
callback('出错了,要设置的文件名不识别');
|
||||
}
|
||||
|
||||
editor.file.saveSetting = saveSetting;
|
||||
|
||||
return editor_file;
|
||||
}
|
||||
//editor_file = editor_file(editor);
|
||||
@ -1,379 +0,0 @@
|
||||
// 由于历史遗留原因, 以下变量作为全局变量使用
|
||||
// exportMap mapEditArea pout mapEditArea copyMap clearMapButton deleteMap printf printe tip selectBox
|
||||
// 除对这些量的功能修改外, 误在此文件中增加新变量或函数
|
||||
exportMap = document.getElementById('exportMap')
|
||||
exportMap.isExport=false
|
||||
exportMap.onclick=function(){
|
||||
editor.updateMap();
|
||||
var sx=editor.map.length-1,sy=editor.map[0].length-1;
|
||||
|
||||
var filestr = '';
|
||||
for (var yy = 0; yy <= sy; yy++) {
|
||||
filestr += '['
|
||||
for (var xx = 0; xx <= sx; xx++) {
|
||||
var mapxy = editor.map[yy][xx];
|
||||
if (typeof(mapxy) == typeof({})) {
|
||||
if ('idnum' in mapxy) mapxy = mapxy.idnum;
|
||||
else {
|
||||
// mapxy='!!?';
|
||||
tip.whichShow(3);
|
||||
return;
|
||||
}
|
||||
} else if (typeof(mapxy) == 'undefined') {
|
||||
tip.whichShow(3);
|
||||
return;
|
||||
}
|
||||
mapxy = String(mapxy);
|
||||
mapxy = Array(Math.max(4 - mapxy.length, 0)).join(' ') + mapxy;
|
||||
filestr += mapxy + (xx == sx ? '' : ',')
|
||||
}
|
||||
|
||||
filestr += ']' + (yy == sy ? '' : ',\n');
|
||||
}
|
||||
pout.value = filestr;
|
||||
mapEditArea.mapArr(filestr);
|
||||
exportMap.isExport = true;
|
||||
mapEditArea.error(0);
|
||||
tip.whichShow(2);
|
||||
}
|
||||
mapEditArea = document.getElementById('mapEditArea')
|
||||
mapEditArea.errors=[ // 编号1,2
|
||||
"格式错误!请使用正确格式(请使用地图生成器进行生成,且需要和本地图宽高完全一致)",
|
||||
"当前有未定义ID(在地图区域显示红块),请修改ID或者到icons.js和maps.js中进行定义!"
|
||||
]
|
||||
mapEditArea.formatTimer=null
|
||||
mapEditArea._mapArr=''
|
||||
mapEditArea.mapArr=function(value){
|
||||
if(value!=null){
|
||||
var val=value
|
||||
var oldval=mapEditArea._mapArr
|
||||
if (val==oldval) return;
|
||||
|
||||
if (exportMap.isExport) {
|
||||
exportMap.isExport = false;
|
||||
return;
|
||||
}
|
||||
if (mapEditArea.formatArr()) {
|
||||
mapEditArea.error(0);
|
||||
|
||||
setTimeout(function () {
|
||||
if (mapEditArea.formatArr())mapEditArea.mapArr(mapEditArea.formatArr());
|
||||
mapEditArea.drawMap();
|
||||
tip.whichShow(8)
|
||||
}, 1000);
|
||||
clearTimeout(mapEditArea.formatTimer);
|
||||
mapEditArea.formatTimer = setTimeout(function () {
|
||||
pout.value = mapEditArea.formatArr();
|
||||
}, 5000); //5s后再格式化,不然光标跳到最后很烦
|
||||
} else {
|
||||
mapEditArea.error(1);
|
||||
}
|
||||
|
||||
mapEditArea._mapArr=value
|
||||
}
|
||||
return mapEditArea._mapArr
|
||||
}
|
||||
pout.oninput=function(){
|
||||
mapEditArea.mapArr(pout.value)
|
||||
}
|
||||
mapEditArea._error=0
|
||||
mapEditArea.error=function(value){
|
||||
if(value!=null){
|
||||
mapEditArea._error=value
|
||||
if (value>0)
|
||||
printe(mapEditArea.errors[value-1])
|
||||
}
|
||||
return mapEditArea._error
|
||||
}
|
||||
mapEditArea.drawMap= function () {
|
||||
// var mapArray = mapEditArea.mapArr().split(/\D+/).join(' ').trim().split(' ');
|
||||
var mapArray = JSON.parse('[' + mapEditArea.mapArr() + ']');
|
||||
var sy=editor.map.length,sx=editor.map[0].length;
|
||||
for (var y = 0; y < sy; y++)
|
||||
for (var x = 0; x < sx; x++) {
|
||||
var num = mapArray[y][x];
|
||||
if (num == 0)
|
||||
editor.map[y][x] = 0;
|
||||
else if (typeof(editor.indexs[num][0]) == 'undefined') {
|
||||
mapEditArea.error(2);
|
||||
editor.map[y][x] = undefined;
|
||||
} else editor.map[y][x] = editor.ids[[editor.indexs[num][0]]];
|
||||
}
|
||||
|
||||
editor.updateMap();
|
||||
|
||||
}
|
||||
mapEditArea.formatArr= function () {
|
||||
var formatArrStr = '';
|
||||
console.log(1)
|
||||
|
||||
var si=editor.map.length,sk=editor.map[0].length;
|
||||
if (mapEditArea.mapArr().split(/\D+/).join(' ').trim().split(' ').length != si*sk) return false;
|
||||
var arr = mapEditArea.mapArr().replace(/\s+/g, '').split('],[');
|
||||
|
||||
if (arr.length != si) return;
|
||||
for (var i = 0; i < si; i++) {
|
||||
var a = [];
|
||||
formatArrStr += '[';
|
||||
if (i == 0 || i == si-1) a = arr[i].split(/\D+/).join(' ').trim().split(' ');
|
||||
else a = arr[i].split(/\D+/);
|
||||
if (a.length != sk) {
|
||||
formatArrStr = '';
|
||||
return;
|
||||
}
|
||||
|
||||
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-1 ? '' : ',');
|
||||
}
|
||||
formatArrStr += ']' + (i == si-1 ? '' : ',\n');
|
||||
}
|
||||
return formatArrStr;
|
||||
}
|
||||
copyMap=document.getElementById('copyMap')
|
||||
copyMap.err=''
|
||||
copyMap.onclick=function(){
|
||||
tip.whichShow(0);
|
||||
if (pout.value.trim() != '') {
|
||||
if (mapEditArea.error()) {
|
||||
copyMap.err = mapEditArea.errors[mapEditArea.error() - 1];
|
||||
tip.whichShow(5)
|
||||
return;
|
||||
}
|
||||
try {
|
||||
pout.focus();
|
||||
pout.setSelectionRange(0, pout.value.length);
|
||||
document.execCommand("Copy");
|
||||
tip.whichShow(6);
|
||||
} catch (e) {
|
||||
copyMap.err = e;
|
||||
tip.whichShow(5);
|
||||
}
|
||||
} else {
|
||||
tip.whichShow(7);
|
||||
}
|
||||
}
|
||||
clearMapButton=document.getElementById('clearMapButton')
|
||||
clearMapButton.onclick=function () {
|
||||
editor.mapInit();
|
||||
editor_mode.onmode('');
|
||||
editor.file.saveFloorFile(function (err) {
|
||||
if (err) {
|
||||
printe(err);
|
||||
throw(err)
|
||||
}
|
||||
;printf('地图清除成功');
|
||||
});
|
||||
editor.updateMap();
|
||||
clearTimeout(mapEditArea.formatTimer);
|
||||
clearTimeout(tip.timer);
|
||||
pout.value = '';
|
||||
mapEditArea.mapArr('');
|
||||
tip.whichShow(4);
|
||||
mapEditArea.error(0);
|
||||
}
|
||||
deleteMap=document.getElementById('deleteMap')
|
||||
deleteMap.onclick=function () {
|
||||
editor_mode.onmode('');
|
||||
var index = core.floorIds.indexOf(editor.currentFloorId);
|
||||
if (index>=0) {
|
||||
core.floorIds.splice(index,1);
|
||||
editor.file.editTower([['change', "['main']['floorIds']", core.floorIds]], function (objs_) {//console.log(objs_);
|
||||
if (objs_.slice(-1)[0] != null) {
|
||||
printe(objs_.slice(-1)[0]);
|
||||
throw(objs_.slice(-1)[0])
|
||||
}
|
||||
;printe('删除成功,请F5刷新编辑器生效');
|
||||
});
|
||||
}
|
||||
else printe('删除成功,请F5刷新编辑器生效');
|
||||
}
|
||||
printf = function (str_, type) {
|
||||
selectBox.isSelected(false);
|
||||
if (!type) {
|
||||
tip.whichShow(11);
|
||||
} else {
|
||||
tip.whichShow(12);
|
||||
}
|
||||
setTimeout(function () {
|
||||
if (!type) {
|
||||
tip.msgs[11] = String(str_);
|
||||
tip.whichShow(12);
|
||||
} else {
|
||||
tip.msgs[10] = String(str_);
|
||||
tip.whichShow(11);
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
printe = function (str_) {
|
||||
printf(str_, 'error')
|
||||
}
|
||||
tip=document.getElementById('tip')
|
||||
tip.showHelp = function(value) {
|
||||
var tips = [
|
||||
'表格的文本域可以双击进行编辑',
|
||||
'双击地图可以选中素材,右键可以弹出菜单',
|
||||
'双击事件编辑器的图块可以进行长文本编辑/脚本编辑/地图选点/UI绘制预览等操作',
|
||||
'ESC或点击空白处可以自动保存当前修改',
|
||||
'H键可以打开操作帮助哦',
|
||||
'tileset贴图模式可以在地图上拖动来一次绘制一个区域;右键额外素材也可以绑定宽高',
|
||||
'可以拖动地图上的图块和事件,或按Ctrl+C, Ctrl+X和Ctrl+V进行复制,剪切和粘贴,Delete删除',
|
||||
'Alt+数字键保存图块,数字键读取保存的图块',
|
||||
];
|
||||
if (value == null) value = Math.floor(Math.random() * tips.length);
|
||||
printf('tips: ' + tips[value])
|
||||
}
|
||||
tip._infos= {}
|
||||
tip.infos=function(value){
|
||||
if(value!=null){
|
||||
var val=value
|
||||
var oldval=tip._infos
|
||||
|
||||
tip.isClearBlock(false);
|
||||
tip.isAirwall(false);
|
||||
if (typeof(val) != 'undefined') {
|
||||
if (val == 0) {
|
||||
tip.isClearBlock(true);
|
||||
return;
|
||||
}
|
||||
if ('id' in val) {
|
||||
if (val.idnum == 17) {
|
||||
tip.isAirwall(true);
|
||||
return;
|
||||
}
|
||||
tip.hasId = true;
|
||||
} else {
|
||||
tip.hasId = false;
|
||||
}
|
||||
tip.isAutotile = false;
|
||||
if (val.images == "autotile" && tip.hasId) tip.isAutotile = true;
|
||||
document.getElementById('isAirwall-else').innerHTML=(tip.hasId?`<p>图块编号:<span class="infoText">${ value['idnum'] }</span></p>
|
||||
<p>图块ID:<span class="infoText">${ value['id'] }</span></p>`:`
|
||||
<p class="warnText">该图块无对应的数字或ID存在,请先前往icons.js和maps.js中进行定义!</p>`)+`
|
||||
<p>图块所在素材:<span class="infoText">${ value['images'] + (tip.isAutotile ? '( '+value['id']+' )' : '') }</span>
|
||||
</p>
|
||||
<p>图块索引:<span class="infoText">${ value['y'] }</span></p>`
|
||||
}
|
||||
|
||||
tip._infos=value
|
||||
}
|
||||
return tip._infos
|
||||
}
|
||||
tip.hasId= true
|
||||
tip.isAutotile= false
|
||||
tip._isSelectedBlock= false
|
||||
tip.isSelectedBlock=function(value){
|
||||
if(value!=null){
|
||||
var dshow=document.getElementById('isSelectedBlock-if')
|
||||
var dhide=document.getElementById('isSelectedBlock-else')
|
||||
if(!value){
|
||||
var dtemp=dshow
|
||||
dshow=dhide
|
||||
dhide=dtemp
|
||||
}
|
||||
dshow.style.display=''
|
||||
dhide.style.display='none'
|
||||
tip._isSelectedBlock=value
|
||||
}
|
||||
return tip._isSelectedBlock
|
||||
}
|
||||
tip._isClearBlock= false
|
||||
tip.isClearBlock=function(value){
|
||||
if(value!=null){
|
||||
var dshow=document.getElementById('isClearBlock-if')
|
||||
var dhide=document.getElementById('isClearBlock-else')
|
||||
if(!value){
|
||||
var dtemp=dshow
|
||||
dshow=dhide
|
||||
dhide=dtemp
|
||||
}
|
||||
dshow.style.display=''
|
||||
dhide.style.display='none'
|
||||
tip._isClearBlock=value
|
||||
}
|
||||
return tip._isClearBlock
|
||||
}
|
||||
tip._isAirwall= false
|
||||
tip.isAirwall=function(value){
|
||||
if(value!=null){
|
||||
var dshow=document.getElementById('isAirwall-if')
|
||||
var dhide=document.getElementById('isAirwall-else')
|
||||
if(!value){
|
||||
var dtemp=dshow
|
||||
dshow=dhide
|
||||
dhide=dtemp
|
||||
}
|
||||
dshow.style.display=''
|
||||
dhide.style.display='none'
|
||||
tip._isAirwall=value
|
||||
}
|
||||
return tip._isAirwall
|
||||
}
|
||||
tip.geneMapSuccess= false
|
||||
tip.timer= null
|
||||
tip.msgs= [ //分别编号1,2,3,4,5,6,7,8,9,10;奇数警告,偶数成功
|
||||
"当前未选择任何图块,请先在右边选择要画的图块!",
|
||||
"生成地图成功!可点击复制按钮复制地图数组到剪切板",
|
||||
"生成失败! 地图中有未定义的图块,建议先用其他有效图块覆盖或点击清除地图!",
|
||||
"地图清除成功!",
|
||||
"复制失败!",
|
||||
"复制成功!可直接粘贴到楼层文件的地图数组中。",
|
||||
"复制失败!当前还没有数据",
|
||||
"修改成功!可点击复制按钮复制地图数组到剪切板",
|
||||
"选择背景图片失败!文件名格式错误或图片不存在!",
|
||||
"更新背景图片成功!",
|
||||
"11:警告",
|
||||
"12:成功"
|
||||
]
|
||||
tip._mapMsg= ''
|
||||
tip.mapMsg=function(value){
|
||||
if(value!=null){
|
||||
document.getElementById('whichShow-if').innerText=value
|
||||
tip._mapMsg=value
|
||||
}
|
||||
return tip._mapMsg
|
||||
}
|
||||
tip._whichShow= 0
|
||||
tip.whichShow=function(value){
|
||||
if(value!=null){
|
||||
|
||||
var dshow=document.getElementById('whichShow-if')
|
||||
var dhide=null
|
||||
if(!value){
|
||||
var dtemp=dshow
|
||||
dshow=dhide
|
||||
dhide=dtemp
|
||||
}
|
||||
if(dshow)dshow.style.display=''
|
||||
if(dhide)dhide.style.display='none'
|
||||
|
||||
if(dshow)dshow.setAttribute('class',(value%2) ? 'warnText' : 'successText')
|
||||
|
||||
tip.mapMsg('');
|
||||
tip.msgs[4] = "复制失败!" + editTip.err;
|
||||
clearTimeout(tip.timer);
|
||||
if (value) {
|
||||
tip.mapMsg(tip.msgs[value - 1]);
|
||||
tip.timer = setTimeout(function () {
|
||||
if (!(value % 2))
|
||||
value = 0;
|
||||
}, 5000); //5秒后自动清除success,warn不清除
|
||||
}
|
||||
tip._whichShow=value
|
||||
}
|
||||
return tip._whichShow
|
||||
}
|
||||
selectBox=document.getElementById('selectBox')
|
||||
selectBox._isSelected=false
|
||||
selectBox.isSelected=function(value){
|
||||
if(value!=null){
|
||||
selectBox._isSelected=value;
|
||||
tip.isSelectedBlock(value);
|
||||
tip.whichShow(0);
|
||||
clearTimeout(tip.timer);
|
||||
editor.dom.dataSelection.style.display=value?'':'none'
|
||||
}
|
||||
return selectBox._isSelected
|
||||
}
|
||||
|
||||
// 修改此文件前先看文件开头的说明
|
||||
@ -1,5 +1,21 @@
|
||||
editor_materialpanel_wrapper = function (editor) {
|
||||
|
||||
// 由于历史遗留原因, 以下变量作为全局变量使用
|
||||
// selectBox
|
||||
|
||||
window.selectBox=document.getElementById('selectBox')
|
||||
selectBox._isSelected=false
|
||||
selectBox.isSelected=function(value){
|
||||
if(value!=null){
|
||||
selectBox._isSelected=value;
|
||||
tip.isSelectedBlock(value);
|
||||
tip.whichShow(0);
|
||||
clearTimeout(tip.timer);
|
||||
editor.dom.dataSelection.style.display=value?'':'none'
|
||||
}
|
||||
return selectBox._isSelected
|
||||
}
|
||||
|
||||
editor.uifunctions.getScrollBarHeight = function () {
|
||||
var outer = document.createElement("div");
|
||||
outer.style.visibility = "hidden";
|
||||
|
||||
@ -97,12 +97,14 @@ editor_mode = function (editor) {
|
||||
}
|
||||
|
||||
editor_mode.prototype.onmode = function (mode, callback) {
|
||||
if (editor_mode.mode != mode) {
|
||||
if (mode === 'save') editor_mode.doActionList(editor_mode.mode, editor_mode.actionList, callback);
|
||||
if (editor_mode.mode === 'nextChange' && mode) editor_mode.showMode(mode);
|
||||
if (mode !== 'save') editor_mode.mode = mode;
|
||||
editor_mode.actionList = [];
|
||||
}
|
||||
setTimeout(function(){
|
||||
if (editor_mode.mode != mode) {
|
||||
if (mode === 'save') editor_mode.doActionList(editor_mode.mode, editor_mode.actionList, callback);
|
||||
if (editor_mode.mode === 'nextChange' && mode) editor_mode.showMode(mode);
|
||||
if (mode !== 'save') editor_mode.mode = mode;
|
||||
editor_mode.actionList = [];
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
editor_mode.prototype.showMode = function (mode) {
|
||||
|
||||
@ -1,5 +1,183 @@
|
||||
editor_ui_wrapper = function (editor) {
|
||||
|
||||
// 由于历史遗留原因, 以下变量作为全局变量使用
|
||||
// printf printe tip
|
||||
window.printf = function (str_, type) {
|
||||
selectBox.isSelected(false);
|
||||
if (!type) {
|
||||
tip.whichShow(11);
|
||||
} else {
|
||||
tip.whichShow(12);
|
||||
}
|
||||
setTimeout(function () {
|
||||
if (!type) {
|
||||
tip.msgs[11] = String(str_);
|
||||
tip.whichShow(12);
|
||||
} else {
|
||||
tip.msgs[10] = String(str_);
|
||||
tip.whichShow(11);
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
window.printe = function (str_) {
|
||||
printf(str_, 'error')
|
||||
}
|
||||
window.tip=document.getElementById('tip')
|
||||
tip.showHelp = function(value) {
|
||||
var tips = [
|
||||
'表格的文本域可以双击进行编辑',
|
||||
'双击地图可以选中素材,右键可以弹出菜单',
|
||||
'双击事件编辑器的图块可以进行长文本编辑/脚本编辑/地图选点/UI绘制预览等操作',
|
||||
'ESC或点击空白处可以自动保存当前修改',
|
||||
'H键可以打开操作帮助哦',
|
||||
'tileset贴图模式可以在地图上拖动来一次绘制一个区域;右键额外素材也可以绑定宽高',
|
||||
'可以拖动地图上的图块和事件,或按Ctrl+C, Ctrl+X和Ctrl+V进行复制,剪切和粘贴,Delete删除',
|
||||
'Alt+数字键保存图块,数字键读取保存的图块',
|
||||
];
|
||||
if (value == null) value = Math.floor(Math.random() * tips.length);
|
||||
printf('tips: ' + tips[value])
|
||||
}
|
||||
tip._infos= {}
|
||||
tip.infos=function(value){
|
||||
if(value!=null){
|
||||
var val=value
|
||||
var oldval=tip._infos
|
||||
|
||||
tip.isClearBlock(false);
|
||||
tip.isAirwall(false);
|
||||
if (typeof(val) != 'undefined') {
|
||||
if (val == 0) {
|
||||
tip.isClearBlock(true);
|
||||
return;
|
||||
}
|
||||
if ('id' in val) {
|
||||
if (val.idnum == 17) {
|
||||
tip.isAirwall(true);
|
||||
return;
|
||||
}
|
||||
tip.hasId = true;
|
||||
} else {
|
||||
tip.hasId = false;
|
||||
}
|
||||
tip.isAutotile = false;
|
||||
if (val.images == "autotile" && tip.hasId) tip.isAutotile = true;
|
||||
document.getElementById('isAirwall-else').innerHTML=(tip.hasId?`<p>图块编号:<span class="infoText">${ value['idnum'] }</span></p>
|
||||
<p>图块ID:<span class="infoText">${ value['id'] }</span></p>`:`
|
||||
<p class="warnText">该图块无对应的数字或ID存在,请先前往icons.js和maps.js中进行定义!</p>`)+`
|
||||
<p>图块所在素材:<span class="infoText">${ value['images'] + (tip.isAutotile ? '( '+value['id']+' )' : '') }</span>
|
||||
</p>
|
||||
<p>图块索引:<span class="infoText">${ value['y'] }</span></p>`
|
||||
}
|
||||
|
||||
tip._infos=value
|
||||
}
|
||||
return tip._infos
|
||||
}
|
||||
tip.hasId= true
|
||||
tip.isAutotile= false
|
||||
tip._isSelectedBlock= false
|
||||
tip.isSelectedBlock=function(value){
|
||||
if(value!=null){
|
||||
var dshow=document.getElementById('isSelectedBlock-if')
|
||||
var dhide=document.getElementById('isSelectedBlock-else')
|
||||
if(!value){
|
||||
var dtemp=dshow
|
||||
dshow=dhide
|
||||
dhide=dtemp
|
||||
}
|
||||
dshow.style.display=''
|
||||
dhide.style.display='none'
|
||||
tip._isSelectedBlock=value
|
||||
}
|
||||
return tip._isSelectedBlock
|
||||
}
|
||||
tip._isClearBlock= false
|
||||
tip.isClearBlock=function(value){
|
||||
if(value!=null){
|
||||
var dshow=document.getElementById('isClearBlock-if')
|
||||
var dhide=document.getElementById('isClearBlock-else')
|
||||
if(!value){
|
||||
var dtemp=dshow
|
||||
dshow=dhide
|
||||
dhide=dtemp
|
||||
}
|
||||
dshow.style.display=''
|
||||
dhide.style.display='none'
|
||||
tip._isClearBlock=value
|
||||
}
|
||||
return tip._isClearBlock
|
||||
}
|
||||
tip._isAirwall= false
|
||||
tip.isAirwall=function(value){
|
||||
if(value!=null){
|
||||
var dshow=document.getElementById('isAirwall-if')
|
||||
var dhide=document.getElementById('isAirwall-else')
|
||||
if(!value){
|
||||
var dtemp=dshow
|
||||
dshow=dhide
|
||||
dhide=dtemp
|
||||
}
|
||||
dshow.style.display=''
|
||||
dhide.style.display='none'
|
||||
tip._isAirwall=value
|
||||
}
|
||||
return tip._isAirwall
|
||||
}
|
||||
tip.geneMapSuccess= false
|
||||
tip.timer= null
|
||||
tip.msgs= [ //分别编号1,2,3,4,5,6,7,8,9,10;奇数警告,偶数成功
|
||||
"当前未选择任何图块,请先在右边选择要画的图块!",
|
||||
"生成地图成功!可点击复制按钮复制地图数组到剪切板",
|
||||
"生成失败! 地图中有未定义的图块,建议先用其他有效图块覆盖或点击清除地图!",
|
||||
"地图清除成功!",
|
||||
"复制失败!",
|
||||
"复制成功!可直接粘贴到楼层文件的地图数组中。",
|
||||
"复制失败!当前还没有数据",
|
||||
"修改成功!可点击复制按钮复制地图数组到剪切板",
|
||||
"选择背景图片失败!文件名格式错误或图片不存在!",
|
||||
"更新背景图片成功!",
|
||||
"11:警告",
|
||||
"12:成功"
|
||||
]
|
||||
tip._mapMsg= ''
|
||||
tip.mapMsg=function(value){
|
||||
if(value!=null){
|
||||
document.getElementById('whichShow-if').innerText=value
|
||||
tip._mapMsg=value
|
||||
}
|
||||
return tip._mapMsg
|
||||
}
|
||||
tip._whichShow= 0
|
||||
tip.whichShow=function(value){
|
||||
if(value!=null){
|
||||
|
||||
var dshow=document.getElementById('whichShow-if')
|
||||
var dhide=null
|
||||
if(!value){
|
||||
var dtemp=dshow
|
||||
dshow=dhide
|
||||
dhide=dtemp
|
||||
}
|
||||
if(dshow)dshow.style.display=''
|
||||
if(dhide)dhide.style.display='none'
|
||||
|
||||
if(dshow)dshow.setAttribute('class',(value%2) ? 'warnText' : 'successText')
|
||||
|
||||
tip.mapMsg('');
|
||||
tip.msgs[4] = "复制失败!" + editTip.err;
|
||||
clearTimeout(tip.timer);
|
||||
if (value) {
|
||||
tip.mapMsg(tip.msgs[value - 1]);
|
||||
tip.timer = setTimeout(function () {
|
||||
if (!(value % 2))
|
||||
value = 0;
|
||||
}, 5000); //5秒后自动清除success,warn不清除
|
||||
}
|
||||
tip._whichShow=value
|
||||
}
|
||||
return tip._whichShow
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据鼠标点击, 得到从元素向上到body的所有id
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# 重构
|
||||
|
||||
> 目前状态: 按功能分类已基本完成, 未完成file/game的重写
|
||||
> 目前状态: 按功能分类, 维持稳定状态, 在3.0中重写
|
||||
|
||||
总体思路
|
||||
+ 按功能拆分文件
|
||||
|
||||
@ -588,7 +588,6 @@
|
||||
<script src='_server/editor_util.js'></script>
|
||||
<script src='_server/editor_game.js'></script>
|
||||
<script src='_server/editor_file.js'></script>
|
||||
<script src='_server/editor_file_unsorted.js'></script>
|
||||
<script src='_server/editor_table.js'></script>
|
||||
<script src='_server/editor_mode.js'></script>
|
||||
<script src='_server/editor_ui.js'></script>
|
||||
@ -596,7 +595,6 @@
|
||||
<script src='_server/editor_datapanel.js'></script>
|
||||
<script src='_server/editor_materialpanel.js'></script>
|
||||
<script src='_server/editor_listen.js'></script>
|
||||
<script src='_server/editor_legacy.js'></script>
|
||||
<script src='libs/thirdparty/lz-string.min.js'></script>
|
||||
<script src='libs/thirdparty/localforage.min.js'></script>
|
||||
<script src='libs/thirdparty/zip.min.js'></script>
|
||||
|
||||
@ -572,7 +572,6 @@
|
||||
<script src='_server/editor_util.js'></script>
|
||||
<script src='_server/editor_game.js'></script>
|
||||
<script src='_server/editor_file.js'></script>
|
||||
<script src='_server/editor_file_unsorted.js'></script>
|
||||
<script src='_server/editor_table.js'></script>
|
||||
<script src='_server/editor_mode.js'></script>
|
||||
<script src='_server/editor_ui.js'></script>
|
||||
@ -580,7 +579,6 @@
|
||||
<script src='_server/editor_datapanel.js'></script>
|
||||
<script src='_server/editor_materialpanel.js'></script>
|
||||
<script src='_server/editor_listen.js'></script>
|
||||
<script src='_server/editor_legacy.js'></script>
|
||||
<script src='libs/thirdparty/lz-string.min.js'></script>
|
||||
<script src='libs/thirdparty/localforage.min.js'></script>
|
||||
<script src='libs/thirdparty/zip.min.js'></script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user