diff --git a/_server/data.comment.js b/_server/data.comment.js index 06ba1016..c3262c4d 100644 --- a/_server/data.comment.js +++ b/_server/data.comment.js @@ -281,7 +281,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_type": "event", "_event": "firstArrive", "_range": "thiseval==null || thiseval instanceof Array", - "_data": "使用画布绘制开始菜单。可以在这里自定义需要的标题界面等内容。" + "_data": "标题界面事件化,可以使用事件流的形式来绘制开始界面等。\n需要开启startUsingCanvas这个开关。\n详见文档-个性化-标题界面事件化。" }, "startText": { "_leaf": true, diff --git a/docs/event.md b/docs/event.md index 041d9547..91ddc83f 100644 --- a/docs/event.md +++ b/docs/event.md @@ -2113,7 +2113,7 @@ if (core.getFlag("door",0)==2) { core.stopReplay(); core.waitHeroToStop(function() { core.removeGlobalAnimate(0,0,true); - core.clearMap('all'); // 清空全地图 + core.clearMap('all'); core.clearMap('curtain'); // 清空全地图 core.drawText([ "\t[恭喜通关]你的分数是${status:hp}。" ], function () { diff --git a/docs/personalization.md b/docs/personalization.md index e8b6f810..30b65102 100644 --- a/docs/personalization.md +++ b/docs/personalization.md @@ -17,10 +17,10 @@ HTML5魔塔是使用画布(canvas)来绘制,存在若干个图层,它们 - fg:前景层;绘制前景图层素材fgmap,和前景贴图 - damage:显伤层;主要用来绘制怪物显伤和领域显伤 - animate:动画层;主要用来绘制动画。showImage事件绘制的图片也是在这一层。 -- image:图片层;主要用来绘制显示图片 - weather:天气层;主要用来绘制天气(雨/雪) - route:路线层;主要用来绘制勇士的行走路线图,也用来绘制图块的淡入/淡出效果,图块的移动等。 - curtain:色调层;用来控制当前楼层的画面色调 +- image:图片层;主要用来绘制显示图片;该层之所以在curtain层上是为了可以在全黑时贴大头像图 - ui:UI层;用来绘制一切UI窗口,如剧情文本、怪物手册、楼传器、系统菜单等等 - data:数据层;用来绘制一些顶层的或更新比较快的数据,如左上角的提示,战斗界面中数据的变化等等。 @@ -560,6 +560,23 @@ this.myfunc = function(x) { 通过这种,将脚本和自定义事件混用的方式,可以达到和RM中公共事件类似的效果,即一个调用触发一系列事件。 --> + +## 标题界面事件化 + +从V2.5.3开始,我们可以将标题界面的绘制和游戏开始用事件来完成。可以通过绘制画布、 + +全塔属性,flags中的startUsingCanvas可以决定是否开启标题界面事件化。 + +然后就可以使用“事件流”的形式来绘制标题界面、提供选项等等。 + +在这里可以调用任意事件。例如,可以贴若干个图,可以事件切换楼层到某个剧情层再执行若干事件,等等。 + +关于选项,样板默认给出的是最简单的choices事件;你也可以使用贴按钮图,循环处理+等待操作来定制自己的按钮点击效果。 + +!> 开始游戏、读取存档、录像回放的效果已经默认给出,请不要修改或删减这些内容,以免出现问题。 + +标题界面事件全部处理完后,将再继续执行startText事件。 + ## 自定义状态栏(新增显示项) 在V2.2以后,我们可以自定义状态栏背景图(全塔属性 - statusLeftBackground)等等。 diff --git a/libs/control.js b/libs/control.js index 7a282c86..893c7e08 100644 --- a/libs/control.js +++ b/libs/control.js @@ -221,6 +221,7 @@ control.prototype.showStartAnimate = function (noAnimate, callback) { core.status.played = false; core.clearStatus(); core.clearMap('all'); + core.clearMap('curtain'); if (core.flags.startUsingCanvas) { core.dom.startTop.style.display = 'none'; @@ -1033,7 +1034,7 @@ control.prototype.updateViewport = function() { ////// 绘制勇士 ////// control.prototype.drawHero = function (direction, x, y, status, offset) { - if (!core.isPlaying() || core.status.isStarting) return; + if (!core.isPlaying()) return; var scan = { 'up': {'x': 0, 'y': -1}, @@ -1510,16 +1511,13 @@ control.prototype.setFg = function(color, time, callback) { ////// 更新全地图显伤 ////// control.prototype.updateDamage = function (floorId, canvas) { - - if (!core.isset(floorId)) floorId = core.status.floorId; + floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return; if (!core.isset(canvas)) { canvas = core.canvas.damage; core.clearMap('damage'); } - // 正在开始游戏中 - if (core.status.isStarting) return; - // 更新显伤 var mapBlocks = core.status.maps[floorId].blocks; // 没有怪物手册 @@ -1673,7 +1671,6 @@ control.prototype.chooseReplayFile = function () { } if (core.flags.startUsingCanvas) { - core.status.isStarting = false; core.startGame('', obj.seed, core.decodeRoute(obj.route)); } else { diff --git a/libs/events.js b/libs/events.js index 8ffd23df..a2bc4e68 100644 --- a/libs/events.js +++ b/libs/events.js @@ -91,14 +91,12 @@ events.prototype.initGame = function () { ////// 游戏开始事件 ////// events.prototype.startGame = function (hard, seed, route, callback) { - if (core.status.isStarting) return; - core.status.isStarting = true; - var start = function () { console.log('开始游戏'); - core.resetStatus(core.firstData.hero, hard, core.firstData.floorId, null, core.initStatus.maps); - - core.status.isStarting = true; + core.resetStatus(core.firstData.hero, hard, null, null, core.initStatus.maps); + var nowLoc = core.clone(core.getHeroLoc()); + core.setHeroLoc('x', -1); + core.setHeroLoc('y', -1); if (core.isset(seed)) { core.setFlag('__seed__', seed); @@ -106,19 +104,15 @@ events.prototype.startGame = function (hard, seed, route, callback) { } else core.utils.__init_seed(); - if (!core.flags.startUsingCanvas) - core.events.setInitData(hard); - core.clearMap('all'); + core.clearMap('curtain'); core.clearStatusBar(); var post_start = function () { - core.status.isStarting = false; - core.control.triggerStatusBar('show'); - core.changeFloor(core.status.floorId, null, core.status.hero.loc, null, function() { + core.changeFloor(core.firstData.floorId, null, nowLoc, null, function() { if (core.isset(callback)) callback(); }, true); @@ -164,6 +158,7 @@ events.prototype.startGame = function (hard, seed, route, callback) { }); } else { + core.events.setInitData(hard); real_start(); } @@ -1334,6 +1329,7 @@ events.prototype.trigger = function (x, y) { events.prototype.setFloorName = function (floorId) { floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return; // 根据文字判断是否斜体 var floorName = core.status.maps[floorId].name || ""; if (typeof floorName == 'number') floorName = ""+floorName; @@ -1358,7 +1354,11 @@ events.prototype.setFloorName = function (floorId) { ////// 楼层切换 ////// events.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback, fromLoad) { - if (!core.isset(floorId)) floorId = core.status.floorId; + floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) { + if (core.isset(callback)) callback(); + return; + } if (floorId == ':before') { var index=core.floorIds.indexOf(core.status.floorId); diff --git a/libs/maps.js b/libs/maps.js index 229d6ebd..6caa54bd 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -211,6 +211,7 @@ maps.prototype.save = function(maps, floorId) { ////// 更改地图画布的尺寸 maps.prototype.resizeMap = function(floorId) { floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return; core.bigmap.width = core.floors[floorId].width || 13; core.bigmap.height = core.floors[floorId].height || 13; var cwidth = core.bigmap.width * 32; @@ -229,7 +230,7 @@ maps.prototype.resizeMap = function(floorId) { ////// 将存档中的地图信息重新读取出来 ////// maps.prototype.load = function (data, floorId) { - if (floorId == undefined) { + if (!core.isset(floorId)) { var map = {}; core.floorIds.forEach(function (id) { map[id] = core.maps.loadFloor(id, data[id]); @@ -266,7 +267,8 @@ maps.prototype.canMoveHero = function(x,y,direction,floorId) { if (!core.isset(x)) x=core.getHeroLoc('x'); if (!core.isset(y)) y=core.getHeroLoc('y'); if (!core.isset(direction)) direction=core.getHeroLoc('direction'); - if (!core.isset(floorId)) floorId=core.status.floorId; + floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return false; // 检查当前块的cannotMove if (core.isset(core.floors[floorId].cannotMove)) { @@ -394,6 +396,7 @@ maps.prototype.drawBlock = function (block, animate, dx, dy) { maps.prototype.getBgFgMapArray = function (floorId, name) { floorId = floorId||core.status.floorId; + if (!core.isset(floorId)) return []; var width = core.floors[floorId].width || 13; var height = core.floors[floorId].height || 13; @@ -417,6 +420,7 @@ maps.prototype.getBgFgMapArray = function (floorId, name) { ////// 背景/前景图块的绘制 ////// maps.prototype.drawBgFgMap = function (floorId, canvas, name) { floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return; var width = core.floors[floorId].width || 13; var height = core.floors[floorId].height || 13; @@ -455,6 +459,11 @@ maps.prototype.drawBgFgMap = function (floorId, canvas, name) { ////// 绘制某张地图 ////// maps.prototype.drawMap = function (mapName, callback) { mapName = mapName || core.status.floorId; + if (!core.isset(mapName)) { + if (core.isset(callback)) + callback(); + return; + } core.clearMap('all'); core.removeGlobalAnimate(null, null, true); @@ -707,7 +716,8 @@ maps.prototype.enemyExists = function (x, y, id,floorId) { ////// 获得某个点的block ////// maps.prototype.getBlock = function (x, y, floorId, showDisable) { - if (!core.isset(floorId)) floorId=core.status.floorId; + floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return null; var blocks = core.status.maps[floorId].blocks; for (var n=0;n=core.bigmap.width || y<0 || y>=core.bigmap.height) return; @@ -1187,6 +1205,7 @@ maps.prototype.setBlock = function (number, x, y, floorId) { ////// 改变图层块 ////// maps.prototype.setBgFgBlock = function (name, number, x, y, floorId) { floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return; if (!core.isset(number) || !core.isset(x) || !core.isset(y)) return; if (x<0 || x>=core.bigmap.width || y<0 || y>=core.bigmap.height) return; if (name!='bg' && name!='fg') return; @@ -1338,7 +1357,8 @@ maps.prototype.setFloorImage = function (type, loc, floorId, callback) { if (type!='show') type='hide'; if (typeof loc[0] == 'number' && typeof loc[1] == 'number') loc = [loc]; - floorId = floorId||core.status.floorId; + floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return; if (loc.length==0) return; loc.forEach(function (t) { @@ -1360,7 +1380,8 @@ maps.prototype.setBgFgMap = function (type, name, loc, floorId, callback) { if (name!='fg') name='bg'; if (typeof loc[0] == 'number' && typeof loc[1] == 'number') loc = [loc]; - floorId = floorId||core.status.floorId; + floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return; if (loc.length==0) return; loc.forEach(function (t) { @@ -1379,7 +1400,8 @@ maps.prototype.setBgFgMap = function (type, name, loc, floorId, callback) { } maps.prototype.resetMap = function(floorId) { - var floorId = floorId||core.status.floorId; + floorId = floorId || core.status.floorId; + if (!core.isset(floorId)) return; core.status.maps[floorId] = this.loadFloor(floorId); if (floorId==core.status.floorId) { this.drawMap(floorId, function () { diff --git a/project/data.js b/project/data.js index 28a1ff15..107c1140 100644 --- a/project/data.js +++ b/project/data.js @@ -104,6 +104,10 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "steps": 0 }, "startCanvas": [ + { + "type": "comment", + "text": "在这里可以用事件来自定义绘制标题界面的背景图等" + }, { "type": "showImage", "name": "bg.jpg", @@ -112,12 +116,24 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = 0 ] }, + { + "type": "comment", + "text": "给用户提供选择项,这里简单的使用了choices事件" + }, + { + "type": "comment", + "text": "也可以贴按钮图然后使用循环处理+等待操作来完成" + }, { "type": "choices", "choices": [ { "text": "开始游戏", "action": [ + { + "type": "comment", + "text": "检查bgm状态,下同" + }, { "type": "function", "function": "function(){\ncore.control.checkBgm()\n}" @@ -126,20 +142,32 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "type": "if", "condition": "core.flags.startDirectly", "true": [ + { + "type": "comment", + "text": "直接开始游戏,设置初始化数据" + }, { "type": "function", "function": "function(){\ncore.events.setInitData('')\n}" } ], "false": [ + { + "type": "comment", + "text": "动态生成难度选择项" + }, { "type": "function", - "function": "function(){\n// 动态生成难度选择项\nvar choices = [];\nmain.levelChoose.forEach(function (one) {\n\tchoices.push({\"text\": one[0], \"action\": [\n\t\t{\"type\": \"function\", \"function\": \"function() { core.status.hard = '\"+one[1]+\"'; core.events.setInitData('\"+one[1]+\"'); }\"}\n\t]});\n})\ncore.insertAction({\"type\": \"choices\", \"choices\": choices});\n}" + "function": "function(){\nvar choices = [];\nmain.levelChoose.forEach(function (one) {\n\tchoices.push({\"text\": one[0], \"action\": [\n\t\t{\"type\": \"function\", \"function\": \"function() { core.status.hard = '\"+one[1]+\"'; core.events.setInitData('\"+one[1]+\"'); }\"}\n\t]});\n})\ncore.insertAction({\"type\": \"choices\", \"choices\": choices});\n}" } ] }, { "type": "showImage" + }, + { + "type": "comment", + "text": "成功选择难度" } ] }, @@ -153,9 +181,17 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = { "type": "showImage" }, + { + "type": "comment", + "text": "这段代码会结束事件,打开读档页面,读取存档或重新开始" + }, { "type": "function", - "function": "function(){\ncore.insertAction([{\"type\": \"exit\"}], null, null, function() {\n\tcore.status.played = false;\n\tcore.status.isStarting = false;\n\tcore.load();\n})\n}" + "function": "function(){\ncore.insertAction([{\"type\": \"exit\"}], null, null, function() {\n\tcore.status.played = false;\n\tcore.load();\n})\n}" + }, + { + "type": "comment", + "text": "不管读档有没有成功,都会重新开始,这个地方不会被执行到" } ] }, @@ -166,13 +202,25 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "type": "function", "function": "function(){\ncore.control.checkBgm()\n}" }, + { + "type": "comment", + "text": "这段代码会结束事件,选择录像文件,播放录像或重新开始" + }, { "type": "function", "function": "function(){\ncore.insertAction([{\"type\": \"exit\"}], null, null, function() {\n\tcore.restart();\n\tcore.chooseReplayFile();\n})\n}" + }, + { + "type": "comment", + "text": "不管录像有没有成功,都会重新开始,这个地方不会被执行到" } ] } ] + }, + { + "type": "comment", + "text": "接下来会执行startText中的事件" } ], "startText": [ @@ -320,7 +368,7 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "hatredDecrease": true, "betweenAttackCeil": false, "useLoop": false, - "startUsingCanvas": true, + "startUsingCanvas": false, "startDirectly": false, "canOpenBattleAnimate": true, "showBattleAnimateConfirm": false, diff --git a/project/functions.js b/project/functions.js index c6ee7084..822856b8 100644 --- a/project/functions.js +++ b/project/functions.js @@ -59,7 +59,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.stopReplay(); core.waitHeroToStop(function() { core.removeGlobalAnimate(0,0,true); - core.clearMap('all'); // 清空全地图 + core.clearMap('all'); core.clearMap('curtain'); // 清空全地图 // 请注意: // 成绩统计时是按照hp进行上传并排名,因此光在这里改${status:hp}是无效的 // 如需按照其他的的分数统计方式,请先将hp设置为你的得分