diff --git a/_docs/api.md b/_docs/api.md index 3efce8eb..8be9d072 100644 --- a/_docs/api.md +++ b/_docs/api.md @@ -776,7 +776,8 @@ core.getCurrentEnemys(floorId) core.hasEnemyLeft(enemyId, floorId) -检查某个楼层是否还有剩余的(指定)怪物。floorId为楼层ID,可忽略表示当前楼层。 +检查某个楼层是否还有剩余的(指定)怪物。 +floorId为楼层ID,可忽略表示当前楼层。也可以传数组如["MT0","MT1"]同时检测多个楼层。 enemyId如果不填或null则检查是否剩余任何怪物,否则只检查是否剩余指定的某类怪物。 ``` diff --git a/_server/table/data.comment.js b/_server/table/data.comment.js index 6b98a633..2a2addfd 100644 --- a/_server/table/data.comment.js +++ b/_server/table/data.comment.js @@ -32,7 +32,7 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_leaf": true, "_type": "textarea", "_range": "editor.mode.checkUnique(thiseval)", - "_data": "在此存放所有可能使用的动画,必须是animate格式,在这里不写后缀名 \n动画必须放在animates目录下;文件名不能使用中文,不能带空格或特殊字符 \n \"jianji\", \"thunder\" \n 根据需求自行添加" + "_data": "在此存放所有可能使用的动画,必须是animate格式,在这里不写后缀名 \n动画必须放在animates目录下;文件名不能使用中文,不能带空格或特殊字符 \n \"jianji\", \"thunder\" 根据需求自行添加" }, "bgms": { "_leaf": true, @@ -46,6 +46,11 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "_range": "editor.mode.checkUnique(thiseval)", "_data": "在此存放所有的SE,和文件名一致 \n音频名不能使用中文,不能带空格或特殊字符;可以直接改名拼音就好" }, + "nameMap": { + "_leaf": true, + "_type": "textarea", + "_data": "文件名映射,目前仅对images, animates, bgms, sounds有效。\n例如定义 {\"精灵石.mp3\":\"jinglingshi.mp3\"} 就可以使用\ncore.playBgm(\"精灵石.mp3\") 或对应的事件来播放该bgm。" + }, "startBackground": { "_leaf": true, "_type": "textarea", diff --git a/libs/control.js b/libs/control.js index d69cfac5..e89cf64b 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1966,6 +1966,10 @@ control.prototype.debug = function() { // ------ 天气,色调,BGM ------ // +control.prototype.getMappedName = function (name) { + return (main.nameMap || {})[name] || name; +} + ////// 更改天气效果 ////// control.prototype.setWeather = function (type, level) { // 非雨雪 @@ -2088,6 +2092,7 @@ control.prototype.screenFlash = function (color, time, times, callback) { ////// 播放背景音乐 ////// control.prototype.playBgm = function (bgm, startTime) { + bgm = core.getMappedName(bgm); if (main.mode!='play' || !core.material.bgms[bgm]) return; // 如果不允许播放 if (!core.musicStatus.bgmStatus) { @@ -2114,8 +2119,6 @@ control.prototype.playBgm = function (bgm, startTime) { } control.prototype._playBgm_play = function (bgm, startTime) { - // 缓存BGM - core.loader.loadBgm(bgm); // 如果当前正在播放,且和本BGM相同,直接忽略 if (core.musicStatus.playingBgm == bgm && !core.material.bgms[core.musicStatus.playingBgm].paused) { return; @@ -2124,6 +2127,8 @@ control.prototype._playBgm_play = function (bgm, startTime) { if (core.musicStatus.playingBgm) { core.material.bgms[core.musicStatus.playingBgm].pause(); } + // 缓存BGM + core.loader.loadBgm(bgm); // 播放当前BGM core.material.bgms[bgm].volume = core.musicStatus.volume; core.material.bgms[bgm].currentTime = startTime || 0; @@ -2152,7 +2157,7 @@ control.prototype.pauseBgm = function () { control.prototype.resumeBgm = function () { if (main.mode!='play')return; try { - core.playBgm(core.musicStatus.playingBgm || core.musicStatus.lastBgm); + core.playBgm(core.musicStatus.playingBgm || core.musicStatus.lastBgm || main.startBgm); } catch (e) { console.log("无法恢复BGM"); @@ -2182,6 +2187,7 @@ control.prototype.triggerBgm = function () { ////// 播放音频 ////// control.prototype.playSound = function (sound) { + sound = core.getMappedName(sound); if (main.mode!='play' || !core.musicStatus.soundStatus || !core.material.sounds[sound]) return; try { if (core.musicStatus.audioContext != null) { diff --git a/libs/enemys.js b/libs/enemys.js index 51ef8552..ad43a0f9 100644 --- a/libs/enemys.js +++ b/libs/enemys.js @@ -360,6 +360,14 @@ enemys.prototype._getCurrentEnemys_sort = function (enemys) { } enemys.prototype.hasEnemyLeft = function (enemyId, floorId) { + if (floorId == null) floorId = core.status.floorId; + if (floorId instanceof Array) { + for (var i = 0; i < floorId.length; ++i) { + if (core.hasEnemyLeft(enemyId, floorId[i])) + return true; + } + return false; + } return core.getCurrentEnemys(floorId).filter(function (enemy) { return enemyId == null || enemy.id == enemyId; }).length > 0; diff --git a/libs/events.js b/libs/events.js index dc88d9c9..6e46ee50 100644 --- a/libs/events.js +++ b/libs/events.js @@ -945,9 +945,10 @@ events.prototype._action_setText = function (data, x, y, prefix) { core.status.textAttribute[t] = data[t]; } if (t == 'background') { - var img = core.material.images.images[data[t]]; + var name = core.getMappedName(data[t]); + var img = core.material.images.images[name]; if (img && img.width == 192 && img.height == 128) { - core.status.textAttribute[t] = data[t]; + core.status.textAttribute[t] = name; } } }); @@ -1747,6 +1748,7 @@ events.prototype.hasAsync = function () { ////// 跟随 ////// events.prototype.follow = function (name) { core.status.hero.followers = core.status.hero.followers || []; + name = core.getMappedName(name); if (core.material.images.images[name] && core.material.images.images[name].width == 128) { core.status.hero.followers.push({"name": name}); @@ -1763,6 +1765,7 @@ events.prototype.unfollow = function (name) { core.status.hero.followers = []; } else { + name = core.getMappedName(name); for (var i = 0; i < core.status.hero.followers.length; i++) { if (core.status.hero.followers[i].name == name) { core.status.hero.followers.splice(i, 1); @@ -1887,7 +1890,10 @@ events.prototype.closeDoor = function (x, y, id, callback) { ////// 显示图片 ////// events.prototype.showImage = function (code, image, sloc, loc, opacityVal, time, callback) { - if (typeof image == 'string') image = core.material.images.images[image]; + if (typeof image == 'string') { + image = core.getMappedName(image); + image = core.material.images.images[image]; + } if (!image) { if (callback) callback(); return; @@ -1980,6 +1986,7 @@ events.prototype._moveImage_moving = function (name, moveInfo, callback) { ////// 绘制或取消一张gif图片 ////// events.prototype.showGif = function (name, x, y) { + name = core.getMappedName(name); var image = core.material.images.images[name]; if (image) { var gif = new Image(); @@ -2230,6 +2237,7 @@ events.prototype.canUseQuickShop = function (shopId) { ////// 设置角色行走图 ////// events.prototype.setHeroIcon = function (name, noDraw) { + name = core.getMappedName(name); var img = core.material.images.images[name]; if (!img || img.width != 128) return; core.setFlag("heroIcon", name); diff --git a/libs/loader.js b/libs/loader.js index b2da0c6e..74435cd6 100644 --- a/libs/loader.js +++ b/libs/loader.js @@ -238,6 +238,7 @@ loader.prototype.loadOneSound = function (name) { } loader.prototype.loadBgm = function (name) { + name = core.getMappedName(name); if (!core.material.bgms[name]) return; // 如果没开启音乐,则不预加载 if (!core.musicStatus.bgmStatus) return; @@ -265,6 +266,7 @@ loader.prototype._preloadBgm = function (bgm) { } loader.prototype.freeBgm = function (name) { + name = core.getMappedName(name); if (!core.material.bgms[name]) return; // 从cachedBgms中删除 core.musicStatus.cachedBgms = core.musicStatus.cachedBgms.filter(function (t) { diff --git a/libs/maps.js b/libs/maps.js index 52b540b4..0cdb1e6d 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -806,6 +806,7 @@ maps.prototype._drawFloorImages = function (floorId, ctx, name, images, currStat images.forEach(function (t) { if (typeof t == 'string') t = [0, 0, t]; var dx = parseInt(t[0]), dy = parseInt(t[1]), imageName = t[2], frame = core.clamp(parseInt(t[4]), 1, 8); + imageName = core.getMappedName(imageName); var image = core.material.images.images[imageName]; if (redraw && frame == 1) return; // 不重绘 @@ -1069,6 +1070,7 @@ maps.prototype._drawThumbnail_realDrawTempCanvas = function (floorId, blocks, op // 缩略图:勇士 if (options.heroLoc) { options.heroIcon = options.heroIcon || core.getFlag("heroIcon", "hero.png"); + options.heroIcon = core.getMappedName(options.heroIcon); var icon = core.material.icons.hero[options.heroLoc.direction]; var height = core.material.images.images[options.heroIcon].height / 4; tempCanvas.drawImage(core.material.images.images[options.heroIcon], icon.stop * 32, icon.loc * height, 32, height, @@ -1844,6 +1846,7 @@ maps.prototype.drawBoxAnimate = function () { ////// 绘制动画 ////// maps.prototype.drawAnimate = function (name, x, y, callback) { + name = core.getMappedName(name); // 正在播放录像:不显示动画 if (core.isReplaying()) { diff --git a/libs/ui.js b/libs/ui.js index 2372860a..34284a6e 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -226,6 +226,7 @@ ui.prototype.drawImage = function (name, image, x, y, w, h, x1, y1, w1, h1) { var ctx = this.getContextByName(name); if (!ctx) return; if (typeof image == 'string') { + image = core.getMappedName(image); image = core.material.images.images[image]; if (!image) return; } @@ -374,8 +375,10 @@ ui.prototype._getTitleAndIcon = function (content) { icon = 0; height = core.material.icons.hero.height; } - else if (/^[-\w.]+\.png$/.test(s4)) + else if (s4.endsWith(".png")) { + s4 = core.getMappedName(s4); image = core.material.images.images[s4]; + } else { var blockInfo = core.getBlockInfo(s4); if (blockInfo != null) { @@ -830,6 +833,7 @@ ui.prototype._drawTextBox_drawImages = function (content) { return content.replace(/(\f|\\f)\[(.*?)]/g, function (text, sympol, str) { var ss = str.split(","); if (ss.length!=3 && ss.length!=5 && ss.length!=9) return ""; + ss[0] = core.getMappedName(ss[0]); var img = core.material.images.images[ss[0]]; if (!img) return ""; // 绘制 diff --git a/libs/utils.js b/libs/utils.js index 9260a9c7..f9404e50 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -282,8 +282,10 @@ utils.prototype.clone = function (data, filter, recursion) { ////// 裁剪图片 ////// utils.prototype.splitImage = function (image, width, height) { - if (typeof image == "string") + if (typeof image == "string") { + image = core.getMappedName(image); image = core.material.images.images[image]; + } if (!image) return []; width = width || 32; height = height || width; diff --git a/project/data.js b/project/data.js index ff821cd8..6d732a08 100644 --- a/project/data.js +++ b/project/data.js @@ -35,6 +35,10 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "bomb.mp3", "centerFly.mp3" ], + "nameMap": { + "背景图.jpg": "bg.jpg", + "背景音乐.mp3": "bgm.mp3" + }, "startBackground": "bg.jpg", "startLogoStyle": "color: black", "levelChoose": [ diff --git a/project/floors/sample1.js b/project/floors/sample1.js index 92b3a0e8..f4fc8fd0 100644 --- a/project/floors/sample1.js +++ b/project/floors/sample1.js @@ -10,7 +10,7 @@ main.floors.sample1= [ 0, 0, - "bg.jpg", + "背景图", 0 ] ], diff --git a/project/functions.js b/project/functions.js index 1cee5278..764ce551 100644 --- a/project/functions.js +++ b/project/functions.js @@ -968,6 +968,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.events.setVolume(core.getFlag("__volume__", 1), 0); // 加载勇士图标 var icon = core.getFlag("heroIcon", "hero.png"); + icon = core.getMappedName(icon); if (core.material.images.images[icon]) { core.material.images.hero.src = core.material.images.images[icon].src; core.material.icons.hero.height = core.material.images.images[icon].height / 4;