fix: 弹幕发送与接受

This commit is contained in:
unanmed 2024-04-22 23:27:23 +08:00
parent 27230b3d47
commit e38f4ed224
5 changed files with 49 additions and 13 deletions

View File

@ -4425,19 +4425,19 @@ events.prototype.tryUseItem = function (itemId, noRoute, callback) {
if (itemId == 'book') { if (itemId == 'book') {
core.ui.closePanel(); core.ui.closePanel();
core.openBook(false); core.openBook(false);
callback(); callback?.();
return; return;
} }
if (itemId == 'fly') { if (itemId == 'fly') {
core.ui.closePanel(); core.ui.closePanel();
core.useFly(false); core.useFly(false);
callback(); callback?.();
return; return;
} }
if (itemId == 'centerFly') { if (itemId == 'centerFly') {
core.ui.closePanel(); core.ui.closePanel();
core.ui._drawCenterFly(); core.ui._drawCenterFly();
callback(); callback?.();
return; return;
} }
if (core.canUseItem(itemId)) { if (core.canUseItem(itemId)) {
@ -4446,5 +4446,5 @@ events.prototype.tryUseItem = function (itemId, noRoute, callback) {
core.playSound('操作失败'); core.playSound('操作失败');
core.drawTip('当前无法使用' + core.material.items[itemId].name, itemId); core.drawTip('当前无法使用' + core.material.items[itemId].name, itemId);
} }
callback(); callback?.();
}; };

View File

@ -568,6 +568,12 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = {
// 如需强行终止行走可以在这里条件判定: // 如需强行终止行走可以在这里条件判定:
// core.stopAutomaticRoute(); // core.stopAutomaticRoute();
Mota.require('var', 'hook').emit(
'moveOneStep',
nowx,
nowy,
core.status.floorId
);
}, },
moveDirectly: function (x, y, ignoreSteps) { moveDirectly: function (x, y, ignoreSteps) {
// 瞬间移动x,y为要瞬间移动的点ignoreSteps为减少的步数可能之前已经被计算过 // 瞬间移动x,y为要瞬间移动的点ignoreSteps为减少的步数可能之前已经被计算过

View File

@ -6,6 +6,7 @@ import { deleteWith, ensureArray, parseCss, tip } from '@/plugin/utils';
import axios, { toFormData } from 'axios'; import axios, { toFormData } from 'axios';
import { Component, VNode, h, ref, shallowReactive } from 'vue'; import { Component, VNode, h, ref, shallowReactive } from 'vue';
/* @__PURE__ */ import { id, password } from '../../../../user'; /* @__PURE__ */ import { id, password } from '../../../../user';
import { mainSetting } from '../setting';
type CSSObj = Partial<Record<CanParseCss, string>>; type CSSObj = Partial<Record<CanParseCss, string>>;
@ -97,6 +98,8 @@ export class Danmaku extends EventEmitter<DanmakuEvent> {
const form = toFormData(data); const form = toFormData(data);
/* @__PURE__ */ form.append('userid', id); /* @__PURE__ */ form.append('userid', id);
/* @__PURE__ */ form.append('password', password); /* @__PURE__ */ form.append('password', password);
try {
const res = await axios.post<PostDanmakuResponse>( const res = await axios.post<PostDanmakuResponse>(
Danmaku.backend, Danmaku.backend,
form form
@ -106,6 +109,15 @@ export class Danmaku extends EventEmitter<DanmakuEvent> {
this.posting = false; this.posting = false;
return res; 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`; /* @__PURE__ */ Danmaku.backend = `/danmaku`;
Mota.require('var', 'hook').once('reset', () => { Mota.require('var', 'hook').once('reset', () => {
Danmaku.fetch(); 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();
}
}
});

View File

@ -486,7 +486,7 @@ mainSetting
.register('bookScale', '怪物手册缩放', 100, COM.Number, [10, 500, 10]) .register('bookScale', '怪物手册缩放', 100, COM.Number, [10, 500, 10])
.setDisplayFunc('bookScale', value => `${value}%`) .setDisplayFunc('bookScale', value => `${value}%`)
.register('danmaku', '显示弹幕', true, COM.Boolean) .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'); const loading = Mota.require('var', 'loading');
@ -521,7 +521,10 @@ loading.once('coreInit', () => {
), ),
'ui.bookScale': storage.getValue('ui.bookScale', isMobile ? 100 : 80), 'ui.bookScale': storage.getValue('ui.bookScale', isMobile ? 100 : 80),
'ui.danmaku': storage.getValue('ui.danmaku', true), '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
),
}); });
}); });

View File

@ -91,6 +91,7 @@ export interface GameEvent extends EmitableEvent {
) => void; ) => void;
afterOpenDoor: (doorId: AllIdsOf<'animates'>, x: number, y: number) => void; afterOpenDoor: (doorId: AllIdsOf<'animates'>, x: number, y: number) => void;
afterChangeFloor: (floorId: FloorIds) => void; afterChangeFloor: (floorId: FloorIds) => void;
moveOneStep: (x: number, y: number, floorId: FloorIds) => void;
} }
export const hook = new EventEmitter<GameEvent>(); export const hook = new EventEmitter<GameEvent>();