From 627bcee8c4e5a7ff7712fef8d85ca7cfd5bc714e Mon Sep 17 00:00:00 2001 From: YouWei Zhao Date: Sat, 30 Dec 2017 21:18:58 +0800 Subject: [PATCH] main.init('editor') --- .gitignore | 1 + _server/editor_file.js | 2 +- drawMapGUI.html | 2 +- libs/core.js | 89 +++++++++++++++++++++++++++--------------- main.js | 7 +++- 5 files changed, 67 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index d742b1fc..359a1962 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode +*ce5eec52_2fa1_447b_8dad_764e267a7fab* # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 diff --git a/_server/editor_file.js b/_server/editor_file.js index f245b77a..943dc71d 100644 --- a/_server/editor_file.js +++ b/_server/editor_file.js @@ -14,7 +14,7 @@ if (isset(callback)) callback(null); } //callback(err:String) - editor_file.saveFloorFile = function(editor,saveAsFilename,callback){ + editor_file.saveFloorFileAs = function(editor,saveAsFilename,callback){ if (isset(callback)) callback(null); } //callback(err:String) diff --git a/drawMapGUI.html b/drawMapGUI.html index c49a6b66..be032623 100644 --- a/drawMapGUI.html +++ b/drawMapGUI.html @@ -421,7 +421,7 @@ editor.prototype.init = function() { editor.prototype.loadMod = function (callback) { main={'instance':{}}; var loadedNum=0; - ['libs/floors/icons.js','libs/floors/maps.js','libs/icons.js','libs/maps.js'].forEach( function (value,ii,aa) { + ['libs/project/icons.js','libs/project/maps.js','libs/icons.js','libs/maps.js'].forEach( function (value,ii,aa) { var script = document.createElement('script'); script.src = value + '?' + editor.version; document.body.appendChild(script); diff --git a/libs/core.js b/libs/core.js index fb84f7b0..8200765e 100644 --- a/libs/core.js +++ b/libs/core.js @@ -1778,39 +1778,62 @@ core.prototype.setFillStyle = function (map, style) { * @param callback 绘制完毕后的回调函数 */ core.prototype.drawMap = function (mapName, callback) { - var mapData = core.status.maps[mapName]; - var mapBlocks = mapData.blocks; - core.status.floorId = mapName; - core.status.thisMap = mapData; core.clearMap('all'); core.removeGlobalAnimate(null, null, true); - var groundId = core.floors[mapName].defaultGround || "ground"; - var blockIcon = core.material.icons.terrains[groundId]; - var blockImage = core.material.images.terrains; - for (var x = 0; x < 13; x++) { - for (var y = 0; y < 13; y++) { - core.canvas.bg.drawImage(blockImage, 0, blockIcon * 32, 32, 32, x * 32, y * 32, 32, 32); - } - } - var autotileMaps = []; - for (var b = 0; b < mapBlocks.length; b++) { - // 事件启用 - var block = mapBlocks[b]; - if (core.isset(block.event) && !(core.isset(block.enable) && !block.enable)) { - if (block.event.cls == 'autotile') { - // core.drawAutotile(); - autotileMaps[13*block.x + block.y] = block.event.id; - continue; - } - else { - blockIcon = core.material.icons[block.event.cls][block.event.id]; - blockImage = core.material.images[block.event.cls]; - core.canvas.event.drawImage(core.material.images[block.event.cls], 0, blockIcon * 32, 32, 32, block.x * 32, block.y * 32, 32, 32); - core.addGlobalAnimate(block.event.animate, block.x * 32, block.y * 32, blockIcon, blockImage); + var drawBg = function(){ + var groundId = core.floors[mapName].defaultGround || "ground"; + var blockIcon = core.material.icons.terrains[groundId]; + var blockImage = core.material.images.terrains; + for (var x = 0; x < 13; x++) { + for (var y = 0; y < 13; y++) { + core.canvas.bg.drawImage(blockImage, 0, blockIcon * 32, 32, 32, x * 32, y * 32, 32, 32); } } } - core.drawAutotile(mapName, 'event', autotileMaps, 0, 0, 32); + + if (main.mode=='editor'){ + main.editor.drawMapBg = function(){ + core.clearMap('bg', 0, 0, 416, 416); + drawBg(); + } + } else { + drawBg(); + } + + var drawEvent = function(){ + var mapData = core.status.maps[mapName]; + var mapBlocks = mapData.blocks; + core.status.floorId = mapName; + core.status.thisMap = mapData; + var autotileMaps = []; + for (var b = 0; b < mapBlocks.length; b++) { + // 事件启用 + var block = mapBlocks[b]; + if (core.isset(block.event) && !(core.isset(block.enable) && !block.enable)) { + if (block.event.cls == 'autotile') { + // core.drawAutotile(); + autotileMaps[13*block.x + block.y] = block.event.id; + continue; + } + else { + var blockIcon = core.material.icons[block.event.cls][block.event.id]; + var blockImage = core.material.images[block.event.cls]; + core.canvas.event.drawImage(core.material.images[block.event.cls], 0, blockIcon * 32, 32, 32, block.x * 32, block.y * 32, 32, 32); + core.addGlobalAnimate(block.event.animate, block.x * 32, block.y * 32, blockIcon, blockImage); + } + } + } + core.drawAutotile(mapName, 'event', autotileMaps, 0, 0, 32); + } + + if (main.mode=='editor'){ + main.editor.updateMap = function(){ + core.clearMap('event', 0, 0, 416, 416); + drawEvent(); + } + } else { + drawEvent(); + } core.setGlobalAnimate(core.values.animateSpeed); if (core.isset(callback)) @@ -2023,8 +2046,8 @@ core.prototype.moveBlock = function(x,y,steps,time,immediateHide,callback) { core.setAlpha('ui', 1.0); block=block.block; - blockIcon = core.material.icons[block.event.cls][block.event.id]; - blockImage = core.material.images[block.event.cls]; + var blockIcon = core.material.icons[block.event.cls][block.event.id]; + var blockImage = core.material.images[block.event.cls]; // 绘制data层 var opacityVal = 1; @@ -2215,6 +2238,7 @@ core.prototype.removeBlockByIds = function (floorId, ids) { } core.prototype.addGlobalAnimate = function (animateMore, x, y, loc, image) { + if (main.mode=='editor') return; if (animateMore == 2) { core.status.twoAnimateObjs.push({ 'x': x, @@ -2236,6 +2260,7 @@ core.prototype.addGlobalAnimate = function (animateMore, x, y, loc, image) { } core.prototype.removeGlobalAnimate = function (x, y, all) { + if (main.mode=='editor') return; if (all == true) { core.status.twoAnimateObjs = []; core.status.fourAnimateObjs = []; @@ -2255,6 +2280,7 @@ core.prototype.removeGlobalAnimate = function (x, y, all) { } core.prototype.setGlobalAnimate = function (speed) { + if (main.mode=='editor') return; clearInterval(core.interval.twoAnimate); clearInterval(core.interval.fourAnimate); var animateClose = false; @@ -3419,7 +3445,8 @@ core.prototype.checkLvUp = function () { } core.prototype.resize = function(clientWidth, clientHeight) { - + if (main.mode=='editor')return; + // 默认画布大小 var DEFAULT_CANVAS_WIDTH = 422; // 默认边栏宽度 diff --git a/main.js b/main.js index 7653d2cf..e0535ce5 100644 --- a/main.js +++ b/main.js @@ -40,6 +40,7 @@ function main() { 'debuffCol': document.getElementById('debuffCol'), 'hard': document.getElementById('hard'), }; + this.mode = 'play'; this.loadList = [ 'items', 'icons', 'maps', 'enemys', 'events', 'data', 'ui', 'core' ]; @@ -100,10 +101,14 @@ function main() { this.canvas = {}; } -main.prototype.init = function () { +main.prototype.init = function (mode) { for (var i = 0; i < main.dom.gameCanvas.length; i++) { main.canvas[main.dom.gameCanvas[i].id] = main.dom.gameCanvas[i].getContext('2d'); } + if (({"editor":0,"replay":0}).hasOwnProperty(mode)) { + main.mode = mode; + if (mode === 'editor')main.editor = {}; + } main.loadPureData(function(){ main.useCompress=data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.useCompress; main.floorIds=data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.main.floorIds;