Commit 1a692983 authored by timel's avatar timel

fix: card animation

parent a33e91cc
...@@ -70,26 +70,22 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => { ...@@ -70,26 +70,22 @@ export const Card: FC<{ idx: number }> = React.memo(({ idx }) => {
const [shadowOpacity, setShadowOpacity] = useState(0); const [shadowOpacity, setShadowOpacity] = useState(0);
// >>> 动画 >>> // >>> 动画 >>>
/** 动画序列的promise,当不是undefined,就说明现在这个卡有动画 */ /** 动画序列的promise */
let animation: Promise<unknown> | null = null; let animation: Promise<unknown> = new Promise<void>((rs) => rs());
const play = (p: () => Promise<unknown>) => { const addToAnimation = (p: () => Promise<unknown>) => {
if (animation) { animation = animation.then(p);
animation = animation.then(p).then(() => (animation = null));
} else {
animation = p().then(() => (animation = null));
}
}; };
eventBus.on(Report.Move, (uuid: string) => { eventBus.on(Report.Move, (uuid: string) => {
if (uuid === state.uuid) { if (uuid === state.uuid) {
play(() => move(state.zone)); addToAnimation(() => move(state.zone));
} }
}); });
eventBus.on(Report.Chaining, (uuid: string) => { eventBus.on(Report.Chaining, (uuid: string) => {
if (uuid === state.uuid) { if (uuid === state.uuid) {
play(() => chaining({ card: state, api })); addToAnimation(() => chaining({ card: state, api }));
} }
}); });
// <<< 动画 <<< // <<< 动画 <<<
......
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