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

refactor store with placeStore

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