diff --git a/public/libs/events.js b/public/libs/events.js index f3a57b7..9c15700 100644 --- a/public/libs/events.js +++ b/public/libs/events.js @@ -4425,19 +4425,19 @@ events.prototype.tryUseItem = function (itemId, noRoute, callback) { if (itemId == 'book') { core.ui.closePanel(); core.openBook(false); - callback(); + callback?.(); return; } if (itemId == 'fly') { core.ui.closePanel(); core.useFly(false); - callback(); + callback?.(); return; } if (itemId == 'centerFly') { core.ui.closePanel(); core.ui._drawCenterFly(); - callback(); + callback?.(); return; } if (core.canUseItem(itemId)) { @@ -4446,5 +4446,5 @@ events.prototype.tryUseItem = function (itemId, noRoute, callback) { core.playSound('操作失败'); core.drawTip('当前无法使用' + core.material.items[itemId].name, itemId); } - callback(); + callback?.(); }; diff --git a/public/project/functions.js b/public/project/functions.js index d7fe8a4..e0580fd 100644 --- a/public/project/functions.js +++ b/public/project/functions.js @@ -568,6 +568,12 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = { // 如需强行终止行走可以在这里条件判定: // core.stopAutomaticRoute(); + Mota.require('var', 'hook').emit( + 'moveOneStep', + nowx, + nowy, + core.status.floorId + ); }, moveDirectly: function (x, y, ignoreSteps) { // 瞬间移动;x,y为要瞬间移动的点;ignoreSteps为减少的步数,可能之前已经被计算过 diff --git a/src/core/main/custom/danmaku.ts b/src/core/main/custom/danmaku.ts index f58d21b..e13b0ed 100644 --- a/src/core/main/custom/danmaku.ts +++ b/src/core/main/custom/danmaku.ts @@ -6,6 +6,7 @@ import { deleteWith, ensureArray, parseCss, tip } from '@/plugin/utils'; import axios, { toFormData } from 'axios'; import { Component, VNode, h, ref, shallowReactive } from 'vue'; /* @__PURE__ */ import { id, password } from '../../../../user'; +import { mainSetting } from '../setting'; type CSSObj = Partial>; @@ -97,15 +98,26 @@ export class Danmaku extends EventEmitter { const form = toFormData(data); /* @__PURE__ */ form.append('userid', id); /* @__PURE__ */ form.append('password', password); - const res = await axios.post( - Danmaku.backend, - form - ); - this.id = res.data.id; - this.posting = false; + try { + const res = await axios.post( + Danmaku.backend, + form + ); - return res; + this.id = res.data.id; + this.posting = false; + + return res; + } catch (e) { + this.posted = false; + this.posting = false; + logger.error( + 3, + `Unexpected error when posting danmaku. Error info: ${e}` + ); + return Promise.resolve(); + } } /** @@ -425,6 +437,20 @@ Danmaku.registerSpecContent('i', content => { }); /* @__PURE__ */ Danmaku.backend = `/danmaku`; + Mota.require('var', 'hook').once('reset', () => { Danmaku.fetch(); }); + +// 勇士移动后显示弹幕 +Mota.require('var', 'hook').on('moveOneStep', (x, y, floor) => { + const enabled = mainSetting.getValue('ui.danmaku', true); + if (!enabled) return; + const f = Danmaku.allInPos[floor]; + if (f) { + const danmaku = f[`${x},${y}`]; + if (danmaku) { + danmaku.show(); + } + } +}); diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 84ff36e..5d3cee0 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -486,7 +486,7 @@ mainSetting .register('bookScale', '怪物手册缩放', 100, COM.Number, [10, 500, 10]) .setDisplayFunc('bookScale', value => `${value}%`) .register('danmaku', '显示弹幕', true, COM.Boolean) - .register('danmakuSpeed', '弹幕速度', 60, COM.Number, [10, 200, 5]) + .register('danmakuSpeed', '弹幕速度', 60, COM.Number, [10, 1000, 5]) ); const loading = Mota.require('var', 'loading'); @@ -521,7 +521,10 @@ loading.once('coreInit', () => { ), 'ui.bookScale': storage.getValue('ui.bookScale', isMobile ? 100 : 80), 'ui.danmaku': storage.getValue('ui.danmaku', true), - 'ui.danmakuSpeed': storage.getValue('ui.danmakuSpeed', 60), + 'ui.danmakuSpeed': storage.getValue( + 'ui.danmakuSpeed', + Math.floor(window.innerWidth / 25) * 5 + ), }); }); diff --git a/src/game/game.ts b/src/game/game.ts index aa9ab0c..eb24186 100644 --- a/src/game/game.ts +++ b/src/game/game.ts @@ -91,6 +91,7 @@ export interface GameEvent extends EmitableEvent { ) => void; afterOpenDoor: (doorId: AllIdsOf<'animates'>, x: number, y: number) => void; afterChangeFloor: (floorId: FloorIds) => void; + moveOneStep: (x: number, y: number, floorId: FloorIds) => void; } export const hook = new EventEmitter();