Commit 7365a6b2 authored by timel's avatar timel Committed by Chunchi Che

refactor: eventbus

parent a65180b6
......@@ -17,4 +17,7 @@ import { EventEmitter } from "eventemitter3";
declare global {
var eventBus: EventEmitter;
var myExtraDeckCodes: number[];
export enum Report {
Move = "move",
}
}
import { EventEmitter } from "eventemitter3";
window.eventBus = new EventEmitter();
enum Report {
Move = "move",
}
// @ts-ignore
window.Report = Report;
......@@ -2,3 +2,4 @@
export * from "./sleep";
export * from "./stream";
export * from "./eventbus";
......@@ -27,10 +27,6 @@ import { BrowserRouter } from "react-router-dom";
import Neos from "./ui/Neos";
import { EventEmitter } from "eventemitter3";
window.eventBus = new EventEmitter();
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
......
......@@ -2,7 +2,6 @@ import { sleep } from "@/infra";
import { fetchCard, ygopro } from "@/api";
import { fetchEsHintMeta, matStore, cardStore } from "@/stores";
import { zip } from "@/ui/Duel/utils";
import { ReportEnum } from "@/ui/Duel/NewPlayMat/Card/springs/types";
export default async (draw: ygopro.StocGameMessage.MsgDraw) => {
fetchEsHintMeta({ originMsg: "玩家抽卡时" });
......@@ -40,5 +39,5 @@ export default async (draw: ygopro.StocGameMessage.MsgDraw) => {
// 抽卡动画
cardStore
.at(ygopro.CardZone.HAND, draw.player)
.forEach((card) => eventBus.emit(ReportEnum.Move, card.uuid));
.forEach((card) => eventBus.emit(Report.Move, card.uuid));
};
......@@ -7,7 +7,6 @@ import { useConfig } from "@/config";
import { sleep } from "@/infra";
import { REASON_MATERIAL } from "../../common";
import { ReportEnum } from "@/ui/Duel/NewPlayMat/Card/springs/types";
const { matStore } = store;
const NeosConfig = useConfig();
......@@ -187,9 +186,9 @@ export default async (move: MsgMove) => {
console.warn("overlay", from.overlay_sequence, to.overlay_sequence);
})();
// 处理token
let target: CardType;
// 处理token
if (fromZone === TZONE) {
// 召唤 token
target = cardStore.at(TZONE, from.controler)[0]; // 必有,随便取一个没用到的token
......@@ -202,6 +201,7 @@ export default async (move: MsgMove) => {
target = cardStore.at(fromZone, from.controler, from.sequence);
}
// 超量
if (toZone === OVERLAY) {
// 准备超量召唤,超量素材入栈
if (reason == REASON_MATERIAL) overlayStack.push(target);
......@@ -231,14 +231,11 @@ export default async (move: MsgMove) => {
target.position = to.position;
// 维护完了之后,开始动画
eventBus.emit(ReportEnum.Move, target.uuid);
eventBus.emit(Report.Move, target.uuid);
// 如果from或者to是手卡,那么需要刷新除了这张卡之外,这个玩家的所有手卡
if ([fromZone, toZone].includes(HAND)) {
cardStore.at(HAND, target.controller).forEach((card) => {
if (card.uuid !== target.uuid) {
console.log("refresh hand", card.uuid);
eventBus.emit(ReportEnum.Move, card.uuid);
}
if (card.uuid !== target.uuid) eventBus.emit(Report.Move, card.uuid);
});
}
......
......@@ -6,7 +6,6 @@ import { useSpring, animated, to } from "@react-spring/web";
import { ygopro } from "@/api";
import { useConfig } from "@/config";
import { moveToDeck, moveToGround, moveToHand, moveToOutside } from "./springs";
import { ReportEnum } from "./springs/types";
import { interactTypeToString } from "../../utils";
import classnames from "classnames";
......@@ -57,7 +56,7 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => {
const [highlight, setHighlight] = useState(false);
const [shadowOpacity, setShadowOpacity] = useState(0);
eventBus.on(ReportEnum.Move, (uuid) => {
eventBus.on(Report.Move, (uuid) => {
if (uuid === state.uuid) reload(state.zone);
});
......
import { isMe, type CardType, cardStore } from "@/stores";
import { SpringApi, ReportEnum } from "./types";
import { SpringApi } from "./types";
import { matConfig } from "../../utils";
import { ygopro } from "@/api";
import { easings } from "@react-spring/web";
......
......@@ -10,7 +10,3 @@ export type SpringApi = SpringRef<{
zIndex: number;
height: number;
}>;
export enum ReportEnum {
Move = "move",
}
// import { EventEmitter } from "eventemitter3";
// window.eventBus = new EventEmitter();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment