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 = {};
}
// 重构这一堆回调
editor.prototype.init = function(){
editor.prototype.init = function(callback){
var mapsdatajsUrl = 'libs/project/maps.js';
var iconsdatajsUrl = 'libs/project/icons.js';
var mapsjsUrl = 'libs/maps.js';
@ -558,6 +558,7 @@ editor.prototype.init = function(){
editor.idsInit(maps, icons); // 初始化图片素材信息
editor.drawInitData(icons); // 初始化绘图
editor.listen(); // 开始监听事件
if(Boolean(callback))callback();
})
});
@ -719,6 +720,10 @@ editor.prototype.mapInit = function(){
}
editor.prototype.drawMapBg = function(){
var bgc = bg.getContext('2d');
if (editor.bgY == 0){
editor.main.editor.drawMapBg();
return;
}
for (var ii = 0; ii < 13; ii++)
for (var jj = 0; jj < 13; jj++) {
@ -728,10 +733,13 @@ editor.prototype.drawMapBg = 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){ // 绘制一个普通块
ctx.clearRect(x*32, y*32, 32, 32);
//ctx.clearRect(x*32, y*32, 32, 32);
if(tileInfo == 0) return;
if(typeof(tileInfo) == typeof([][0]) || !hasOwnProp(tileInfo, 'idnum')) {//未定义块画红块
@ -748,9 +756,9 @@ editor.prototype.updateMap = function(){
ctx.fillText("?", x*32+16, y*32+27);
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的相关处理
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);
}
}
*/
// 绘制地图 start
var eventCtx = document.getElementById('event').getContext("2d");
for(var y=0; y<13; y++)
for(var x=0; x<13; x++){
var tileInfo = editor.map[y][x];
if(isAutotile(tileInfo)){
if(false && isAutotile(tileInfo)){
addIndexToAutotileInfo(x, y);
drawAutotile(eventCtx, x, y, tileInfo);
}else drawTile(eventCtx, x, y, tileInfo);
@ -1060,14 +1068,19 @@ editor = new editor();
main.init('editor');
//main.listen();
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.updateMap();
main.instance={};
editor.main=main;
editor.core=core;
editor.fs=fs;
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 hard = 'Hard';

View File

@ -1997,19 +1997,21 @@ core.prototype.drawMap = function (mapName, callback) {
}
}
}
drawBg();
if (main.mode=='editor'){
main.editor.drawMapBg = function(){
core.clearMap('bg', 0, 0, 416, 416);
drawBg();
}
} else {
drawBg();
}
core.status.floorId = mapName;
core.status.thisMap = core.status.maps[mapName];
var drawEvent = function(){
var mapData = core.status.maps[mapName];
var mapData = core.status.maps[core.status.floorId];
var mapBlocks = mapData.blocks;
core.status.floorId = mapName;
core.status.thisMap = mapData;
var autotileMaps = [];
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);
}
drawEvent();
if (main.mode=='editor'){
main.editor.updateMap = function(){
core.removeGlobalAnimate(null, null, true);
core.clearMap('event', 0, 0, 416, 416);
drawEvent();
core.setGlobalAnimate(core.values.animateSpeed);
}
} else {
drawEvent();
}
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) {
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
if (all == true) {
core.status.twoAnimateObjs = [];
core.status.fourAnimateObjs = [];
}
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
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) {
core.status.twoAnimateObjs.splice(t, 1);

View File

@ -13,38 +13,46 @@ maps.prototype.loadFloor = function (floorId, map) {
content['title'] = floor.title;
content['canFlyTo'] = floor.canFlyTo;
if (!core.isset(map)) map=floor.map;
var blocks = [];
for (var i = 0; i < 13; i++) {
for (var j = 0; j < 13; j++) {
var block = this.getBlock(j, i, map[i][j]);
if (block.event != undefined) {
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.noPass == undefined) {
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') {
block.event.animate = 2;
}
if (block.event.cls == 'animates') {
block.event.animate = 4;
var mapIntoBlocks = function(map,maps,floor){
var blocks = [];
for (var i = 0; i < 13; i++) {
for (var j = 0; j < 13; j++) {
var block = maps.getBlock(j, i, map[i][j]);
if (block.event != undefined) {
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.noPass == undefined) {
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') {
block.event.animate = 2;
}
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]);
if (core.isset(block.event)) blocks.push(block);
}
return blocks;
}
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;
}