Commit 128d5827 authored by chechunchi's avatar chechunchi Committed by Chunchi Che

refactor store with placeStore

parent e1c66ce2
import { ygopro } from "@/api";
import { cardStore, matStore, placeStore } from "@/stores";
import { Container } from "@/container";
import { cardStore, matStore } from "@/stores";
export default (_chainEnd: ygopro.StocGameMessage.MsgChainEnd) => {
export default (
container: Container,
_chainEnd: ygopro.StocGameMessage.MsgChainEnd,
) => {
console.info(`<ChainEnd>chain has been end`);
const context = container.context;
while (true) {
const chain = matStore.chains.pop();
......@@ -10,7 +15,7 @@ export default (_chainEnd: ygopro.StocGameMessage.MsgChainEnd) => {
break;
}
const block = placeStore.of(chain);
const block = context.placeStore.of(context, chain);
if (block) {
block.chainIndex.pop();
} else {
......
import { ygopro } from "@/api";
import { matStore, placeStore } from "@/stores";
import { Container } from "@/container";
import { matStore } from "@/stores";
// FIXME: 处理连锁会存在三种结果:
// 1. Solved - 已处理;
......@@ -9,15 +10,19 @@ import { matStore, placeStore } from "@/stores";
// 第一种MSG后端会在每一个连锁点处理完(不管是无效还是禁用)发给前端,
// 第二第三种只会在特定情况下发,用于UI展示。
// 这里暂时只处理第一种。
export default async (chainSolved: ygopro.StocGameMessage.MsgChainSolved) => {
export default async (
container: Container,
chainSolved: ygopro.StocGameMessage.MsgChainSolved,
) => {
console.info(`<ChainSolved>solved_index = ${chainSolved.solved_index}`);
const context = container.context;
const location = matStore.chains
.splice(chainSolved.solved_index - 1, 1)
.at(0);
if (location) {
// 设置被连锁状态为空,解除连锁
const block = placeStore.of(location);
const block = context.placeStore.of(context, location);
if (block) {
block.chainIndex.pop();
} else {
......
import { fetchCard, ygopro } from "@/api";
import { Container } from "@/container";
import { AudioActionType, playEffect } from "@/infra/audio";
import { cardStore, fetchEsHintMeta, matStore, placeStore } from "@/stores";
import { cardStore, fetchEsHintMeta, matStore } from "@/stores";
import { callCardFocus } from "@/ui/Duel/PlayMat/Card";
export default async (chaining: ygopro.StocGameMessage.MsgChaining) => {
export default async (
container: Container,
chaining: ygopro.StocGameMessage.MsgChaining,
) => {
playEffect(AudioActionType.SOUND_ACTIVATE);
fetchEsHintMeta({
originMsg: "「[?]」被发动时",
cardID: chaining.code,
});
const context = container.context;
const location = chaining.location;
// 将`location`添加到连锁栈
......@@ -18,7 +23,7 @@ export default async (chaining: ygopro.StocGameMessage.MsgChaining) => {
const target = cardStore.find(location);
if (target) {
// 设置连锁序号
const block = placeStore.of(location);
const block = context.placeStore.of(context, location);
if (block) {
block.chainIndex.push(matStore.chains.length);
} else {
......
import { ygopro } from "@/api";
import { placeStore } from "@/stores";
import MsgFieldDisabled = ygopro.StocGameMessage.MsgFieldDisabled;
import { Container } from "@/container";
export default (fieldDisabled: MsgFieldDisabled) => {
export default (container: Container, fieldDisabled: MsgFieldDisabled) => {
const context = container.context;
for (const action of fieldDisabled.actions) {
switch (action.zone) {
case ygopro.CardZone.MZONE:
case ygopro.CardZone.SZONE:
const block = placeStore.of(action);
const block = context.placeStore.of(context, action);
if (block) {
block.disabled = action.disabled;
} else {
......
......@@ -273,16 +273,16 @@ export default async function handleGameMsg(
break;
}
case "chaining": {
await onMsgChaining(msg.chaining);
await onMsgChaining(container, msg.chaining);
break;
}
case "chain_solved": {
await onMsgChainSolved(msg.chain_solved);
await onMsgChainSolved(container, msg.chain_solved);
break;
}
case "chain_end": {
onMsgChainEnd(msg.chain_end);
onMsgChainEnd(container, msg.chain_end);
break;
}
......@@ -346,7 +346,7 @@ export default async function handleGameMsg(
break;
}
case "field_disabled": {
onMsgFieldDisabled(msg.field_disabled);
onMsgFieldDisabled(container, msg.field_disabled);
break;
}
......
import { sendSelectPlaceResponse, ygopro } from "@/api";
import { Container } from "@/container";
import { InteractType, placeStore } from "@/stores";
import { InteractType } from "@/stores";
type MsgSelectPlace = ygopro.StocGameMessage.MsgSelectPlace;
export default async (container: Container, selectPlace: MsgSelectPlace) => {
const conn = container.conn;
const context = container.context;
if (selectPlace.count !== 1) {
console.warn(`Unhandled case: ${selectPlace}`);
return;
......@@ -26,7 +27,7 @@ export default async (container: Container, selectPlace: MsgSelectPlace) => {
switch (place.zone) {
case ygopro.CardZone.MZONE:
case ygopro.CardZone.SZONE:
const block = placeStore.of(place);
const block = context.placeStore.of(context, place);
if (block) {
block.interactivity = {
interactType: InteractType.PLACE_SELECTABLE,
......
......@@ -2,7 +2,7 @@ import { cloneDeep } from "lodash-es";
import { proxy } from "valtio";
import { ygopro } from "@/api";
import { matStore } from "@/stores";
import { Context } from "@/container";
import type { Interactivity } from "./matStore/types";
import { type NeosStore } from "./shared";
......@@ -65,14 +65,16 @@ export class PlaceStore implements NeosStore {
op: BlockState[];
};
} = initialState;
of(location: {
zone: ygopro.CardZone;
controller: number;
sequence: number;
}): BlockState | undefined {
of(
context: Context,
location: {
zone: ygopro.CardZone;
controller: number;
sequence: number;
},
): BlockState | undefined {
return this.inner[location.zone][
// FIXME: inject `matStore`
matStore.isMe(location.controller) ? "me" : "op"
context.matStore.isMe(location.controller) ? "me" : "op"
][location.sequence];
}
clearAllInteractivity() {
......
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