editor: import main.js

画图部分完美结合
This commit is contained in:
YouWei Zhao 2017-12-31 15:29:44 +08:00
parent ba7bbbc7be
commit 5438001ea0
3 changed files with 68 additions and 39 deletions

View File

@ -520,7 +520,7 @@ function editor() {
this.material = {}; this.material = {};
} }
// 重构这一堆回调 // 重构这一堆回调
editor.prototype.init = function(){ editor.prototype.init = function(callback){
var mapsdatajsUrl = 'libs/project/maps.js'; var mapsdatajsUrl = 'libs/project/maps.js';
var iconsdatajsUrl = 'libs/project/icons.js'; var iconsdatajsUrl = 'libs/project/icons.js';
var mapsjsUrl = 'libs/maps.js'; var mapsjsUrl = 'libs/maps.js';
@ -558,6 +558,7 @@ editor.prototype.init = function(){
editor.idsInit(maps, icons); // 初始化图片素材信息 editor.idsInit(maps, icons); // 初始化图片素材信息
editor.drawInitData(icons); // 初始化绘图 editor.drawInitData(icons); // 初始化绘图
editor.listen(); // 开始监听事件 editor.listen(); // 开始监听事件
if(Boolean(callback))callback();
}) })
}); });
@ -719,6 +720,10 @@ editor.prototype.mapInit = function(){
} }
editor.prototype.drawMapBg = function(){ editor.prototype.drawMapBg = function(){
var bgc = bg.getContext('2d'); var bgc = bg.getContext('2d');
if (editor.bgY == 0){
editor.main.editor.drawMapBg();
return;
}
for (var ii = 0; ii < 13; ii++) for (var ii = 0; ii < 13; ii++)
for (var jj = 0; jj < 13; jj++) { for (var jj = 0; jj < 13; jj++) {
@ -728,10 +733,13 @@ editor.prototype.drawMapBg = function(){
} }
editor.prototype.updateMap = function(){ editor.prototype.updateMap = function(){
var blocks = main.editor.mapIntoBlocks(editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})}),{'events':{},'changeFloor':{},'defaultGround':null});
core.status.thisMap.blocks = blocks;
main.editor.updateMap();
var drawTile = function(ctx, x, y, tileInfo){ // 绘制一个普通块 var drawTile = function(ctx, x, y, tileInfo){ // 绘制一个普通块
ctx.clearRect(x*32, y*32, 32, 32); //ctx.clearRect(x*32, y*32, 32, 32);
if(tileInfo == 0) return; if(tileInfo == 0) return;
if(typeof(tileInfo) == typeof([][0]) || !hasOwnProp(tileInfo, 'idnum')) {//未定义块画红块 if(typeof(tileInfo) == typeof([][0]) || !hasOwnProp(tileInfo, 'idnum')) {//未定义块画红块
@ -748,9 +756,9 @@ editor.prototype.updateMap = function(){
ctx.fillText("?", x*32+16, y*32+27); ctx.fillText("?", x*32+16, y*32+27);
return; return;
} }
ctx.drawImage(editor.material.images[tileInfo.images], 0, tileInfo.y*32, 32, 32, x*32, y*32, 32, 32); //ctx.drawImage(editor.material.images[tileInfo.images], 0, tileInfo.y*32, 32, 32, x*32, y*32, 32, 32);
} }
/*
// autotile的相关处理 // autotile的相关处理
var indexArrs = [ //16种组合的图块索引数组; // 将autotile分割成48块16*16的小块; 数组索引即对应各个小块 var indexArrs = [ //16种组合的图块索引数组; // 将autotile分割成48块16*16的小块; 数组索引即对应各个小块
// +----+----+----+----+----+----+ // +----+----+----+----+----+----+
@ -835,13 +843,13 @@ editor.prototype.updateMap = function(){
drawBlockByIndex(ctx, dx, dy, editor.material.images[info.images][info.id], index); drawBlockByIndex(ctx, dx, dy, editor.material.images[info.images][info.id], index);
} }
} }
*/
// 绘制地图 start // 绘制地图 start
var eventCtx = document.getElementById('event').getContext("2d"); var eventCtx = document.getElementById('event').getContext("2d");
for(var y=0; y<13; y++) for(var y=0; y<13; y++)
for(var x=0; x<13; x++){ for(var x=0; x<13; x++){
var tileInfo = editor.map[y][x]; var tileInfo = editor.map[y][x];
if(isAutotile(tileInfo)){ if(false && isAutotile(tileInfo)){
addIndexToAutotileInfo(x, y); addIndexToAutotileInfo(x, y);
drawAutotile(eventCtx, x, y, tileInfo); drawAutotile(eventCtx, x, y, tileInfo);
}else drawTile(eventCtx, x, y, tileInfo); }else drawTile(eventCtx, x, y, tileInfo);
@ -1060,14 +1068,19 @@ editor = new editor();
main.init('editor'); main.init('editor');
//main.listen(); //main.listen();
var afterMainInit = function(){ var afterMainInit = function(){
//main.editor.mapIntoBlocks(editor.map.map(function(v){return v.map(function(v){return v.idnum||v||0})}),{'events':{},'changeFloor':{},'defaultGround':null});
//main.editor.drawMapBg(); //main.editor.drawMapBg();
//main.editor.updateMap(); //main.editor.updateMap();
main.instance={}; main.instance={};
editor.main=main; editor.main=main;
editor.core=core; editor.core=core;
editor.fs=fs; editor.fs=fs;
editor.file=editor_file; editor.file=editor_file;
editor.init();
main.editor.disableGlobalAnimate=false;
//core.status.maps = core.clone(core.maps.initMaps(floorIds));
editor.init(editor.updateMap);
} }
var startgame = function(){ var startgame = function(){
var hard = 'Hard'; var hard = 'Hard';

View File

@ -1997,19 +1997,21 @@ core.prototype.drawMap = function (mapName, callback) {
} }
} }
} }
drawBg();
if (main.mode=='editor'){ if (main.mode=='editor'){
main.editor.drawMapBg = function(){ main.editor.drawMapBg = function(){
core.clearMap('bg', 0, 0, 416, 416); core.clearMap('bg', 0, 0, 416, 416);
drawBg(); drawBg();
} }
} else {
drawBg();
} }
core.status.floorId = mapName;
core.status.thisMap = core.status.maps[mapName];
var drawEvent = function(){ var drawEvent = function(){
var mapData = core.status.maps[mapName]; var mapData = core.status.maps[core.status.floorId];
var mapBlocks = mapData.blocks; var mapBlocks = mapData.blocks;
core.status.floorId = mapName;
core.status.thisMap = mapData;
var autotileMaps = []; var autotileMaps = [];
for (var b = 0; b < mapBlocks.length; b++) { for (var b = 0; b < mapBlocks.length; b++) {
// 事件启用 // 事件启用
@ -2030,12 +2032,16 @@ core.prototype.drawMap = function (mapName, callback) {
} }
core.drawAutotile(mapName, 'event', autotileMaps, 0, 0, 32); core.drawAutotile(mapName, 'event', autotileMaps, 0, 0, 32);
} }
drawEvent();
if (main.mode=='editor'){ if (main.mode=='editor'){
main.editor.updateMap = function(){ main.editor.updateMap = function(){
core.removeGlobalAnimate(null, null, true);
core.clearMap('event', 0, 0, 416, 416); core.clearMap('event', 0, 0, 416, 416);
drawEvent(); drawEvent();
core.setGlobalAnimate(core.values.animateSpeed);
} }
} else {
drawEvent();
} }
core.setGlobalAnimate(core.values.animateSpeed); core.setGlobalAnimate(core.values.animateSpeed);
@ -2467,11 +2473,13 @@ core.prototype.addGlobalAnimate = function (animateMore, x, y, loc, image) {
////// 删除一个或所有全局动画 ////// ////// 删除一个或所有全局动画 //////
core.prototype.removeGlobalAnimate = function (x, y, all) { core.prototype.removeGlobalAnimate = function (x, y, all) {
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
if (all == true) { if (all == true) {
core.status.twoAnimateObjs = []; core.status.twoAnimateObjs = [];
core.status.fourAnimateObjs = []; core.status.fourAnimateObjs = [];
} }
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
for (var t = 0; t < core.status.twoAnimateObjs.length; t++) { for (var t = 0; t < core.status.twoAnimateObjs.length; t++) {
if (core.status.twoAnimateObjs[t].x == x * 32 && core.status.twoAnimateObjs[t].y == y * 32) { if (core.status.twoAnimateObjs[t].x == x * 32 && core.status.twoAnimateObjs[t].y == y * 32) {
core.status.twoAnimateObjs.splice(t, 1); core.status.twoAnimateObjs.splice(t, 1);

View File

@ -13,38 +13,46 @@ maps.prototype.loadFloor = function (floorId, map) {
content['title'] = floor.title; content['title'] = floor.title;
content['canFlyTo'] = floor.canFlyTo; content['canFlyTo'] = floor.canFlyTo;
if (!core.isset(map)) map=floor.map; if (!core.isset(map)) map=floor.map;
var blocks = []; var mapIntoBlocks = function(map,maps,floor){
for (var i = 0; i < 13; i++) { var blocks = [];
for (var j = 0; j < 13; j++) { for (var i = 0; i < 13; i++) {
var block = this.getBlock(j, i, map[i][j]); for (var j = 0; j < 13; j++) {
if (block.event != undefined) { var block = maps.getBlock(j, i, map[i][j]);
if (block.event.cls == 'enemys' && block.event.trigger==undefined) { if (block.event != undefined) {
block.event.trigger = 'battle'; if (block.event.cls == 'enemys' && block.event.trigger==undefined) {
} block.event.trigger = 'battle';
if (block.event.cls == 'items' && block.event.trigger==undefined) { }
block.event.trigger = 'getItem'; if (block.event.cls == 'items' && block.event.trigger==undefined) {
} block.event.trigger = 'getItem';
if (block.event.noPass == undefined) { }
if (block.event.cls=='enemys' || block.event.cls=='terrains' || block.event.cls=='npcs') { if (block.event.noPass == undefined) {
block.event.noPass = true; if (block.event.cls=='enemys' || block.event.cls=='terrains' || block.event.cls=='npcs') {
} block.event.noPass = true;
} }
if (block.event.animate == undefined) { }
if (block.event.cls=='enemys' || block.event.cls=='npcs') { if (block.event.animate == undefined) {
block.event.animate = 2; if (block.event.cls=='enemys' || block.event.cls=='npcs') {
} block.event.animate = 2;
if (block.event.cls == 'animates') { }
block.event.animate = 4; if (block.event.cls == 'animates') {
block.event.animate = 4;
}
} }
} }
maps.addEvent(block,j,i,floor.events[j+","+i],floor.defaultGround || "ground")
maps.addChangeFloor(block,j,i,floor.changeFloor[j+","+i]);
if (core.isset(block.event)) blocks.push(block);
} }
this.addEvent(block,j,i,floor.events[j+","+i],floor.defaultGround || "ground") }
this.addChangeFloor(block,j,i,floor.changeFloor[j+","+i]); return blocks;
if (core.isset(block.event)) blocks.push(block); }
if (main.mode=='editor'){
main.editor.mapIntoBlocks = function(map,floor){
return mapIntoBlocks(map,core.maps,floor);
} }
} }
// 事件处理 // 事件处理
content['blocks'] = blocks; content['blocks'] = mapIntoBlocks(map,this,floor);
return content; return content;
} }