mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-25 10:36:32 +08:00
fix: 弹幕发送与接受
This commit is contained in:
1 parent
27230b3d47
commit
e38f4ed224
5 files changed
+49
-13
No files matched your search
@@ -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<Record<CanParseCss, string>>;
|
||||
|
||||
@@ -97,15 +98,26 @@ export class Danmaku extends EventEmitter<DanmakuEvent> {
|
||||
const form = toFormData(data);
|
||||
/* @__PURE__ */ form.append('userid', id);
|
||||
/* @__PURE__ */ form.append('password', password);
|
||||
const res = await axios.post<PostDanmakuResponse>(
|
||||
Danmaku.backend,
|
||||
form
|
||||
);
|
||||
|
||||
this.id = res.data.id;
|
||||
this.posting = false;
|
||||
try {
|
||||
const res = await axios.post<PostDanmakuResponse>(
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -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
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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<GameEvent>();
|
||||
|
||||
Reference in new issue
Block a user