Commit 72b0abc8 authored by chechunchi's avatar chechunchi

update placeStore

parent b705673e
...@@ -14,12 +14,15 @@ export default (selectPlace: MsgSelectPlace) => { ...@@ -14,12 +14,15 @@ export default (selectPlace: MsgSelectPlace) => {
case ygopro.CardZone.MZONE: case ygopro.CardZone.MZONE:
case ygopro.CardZone.SZONE: case ygopro.CardZone.SZONE:
placeStore.set(place.zone, place.controller, place.sequence, { placeStore.set(place.zone, place.controller, place.sequence, {
interactType: InteractType.PLACE_SELECTABLE, interactivity: {
response: { interactType: InteractType.PLACE_SELECTABLE,
controller: place.controller, response: {
zone: place.zone, controller: place.controller,
sequence: place.sequence, zone: place.zone,
sequence: place.sequence,
},
}, },
disabled: false,
}); });
break; break;
} }
......
...@@ -15,31 +15,60 @@ export type PlaceInteractivity = ...@@ -15,31 +15,60 @@ export type PlaceInteractivity =
const { MZONE, SZONE } = ygopro.CardZone; const { MZONE, SZONE } = ygopro.CardZone;
export interface BlockState {
interactivity?: PlaceInteractivity; // 互动性
disabled: boolean;
}
export const placeStore = proxy({ export const placeStore = proxy({
inner: { inner: {
[MZONE]: { [MZONE]: {
me: Array.from({ length: 7 }).map(() => undefined as PlaceInteractivity), me: Array.from({ length: 7 }).map(
op: Array.from({ length: 7 }).map(() => undefined as PlaceInteractivity), () =>
({
interactivity: undefined,
disabled: false,
} as BlockState)
),
op: Array.from({ length: 7 }).map(
() =>
({
interactivity: undefined,
disabled: false,
} as BlockState)
),
}, },
[SZONE]: { [SZONE]: {
me: Array.from({ length: 6 }).map(() => undefined as PlaceInteractivity), me: Array.from({ length: 6 }).map(
op: Array.from({ length: 6 }).map(() => undefined as PlaceInteractivity), () =>
({
interactivity: undefined,
disabled: false,
} as BlockState)
),
op: Array.from({ length: 6 }).map(
() =>
({
interactivity: undefined,
disabled: false,
} as BlockState)
),
}, },
}, },
set( set(
zone: ygopro.CardZone.MZONE | ygopro.CardZone.SZONE, zone: ygopro.CardZone.MZONE | ygopro.CardZone.SZONE,
controller: number, controller: number,
sequence: number, sequence: number,
placeInteractivity: PlaceInteractivity state: BlockState
) { ) {
placeStore.inner[zone][matStore.isMe(controller) ? "me" : "op"][sequence] = placeStore.inner[zone][matStore.isMe(controller) ? "me" : "op"][sequence] =
placeInteractivity; state;
}, },
clearAll() { clearAllInteractivity() {
(["me", "op"] as const).forEach((who) => { (["me", "op"] as const).forEach((who) => {
([MZONE, SZONE] as const).forEach((where) => { ([MZONE, SZONE] as const).forEach((where) => {
placeStore.inner[where][who] = placeStore.inner[where][who].map( placeStore.inner[where][who].forEach(
() => undefined (block) => (block.interactivity = undefined)
); );
}); });
}); });
......
...@@ -5,11 +5,16 @@ import { type FC } from "react"; ...@@ -5,11 +5,16 @@ import { type FC } from "react";
import { type INTERNAL_Snapshot as Snapshot, useSnapshot } from "valtio"; import { type INTERNAL_Snapshot as Snapshot, useSnapshot } from "valtio";
import { sendSelectPlaceResponse, ygopro } from "@/api"; import { sendSelectPlaceResponse, ygopro } from "@/api";
import { cardStore, type PlaceInteractivity, placeStore } from "@/stores"; import {
BlockState,
cardStore,
type PlaceInteractivity,
placeStore,
} from "@/stores";
const BgExtraRow: FC<{ const BgExtraRow: FC<{
meSnap: Snapshot<PlaceInteractivity[]>; meSnap: Snapshot<BlockState[]>;
opSnap: Snapshot<PlaceInteractivity[]>; opSnap: Snapshot<BlockState[]>;
}> = ({ meSnap, opSnap }) => { }> = ({ meSnap, opSnap }) => {
return ( return (
<div className={classnames("bg-row")}> <div className={classnames("bg-row")}>
...@@ -20,8 +25,8 @@ const BgExtraRow: FC<{ ...@@ -20,8 +25,8 @@ const BgExtraRow: FC<{
highlight: !!meSnap[i] || !!opSnap[i], highlight: !!meSnap[i] || !!opSnap[i],
})} })}
onClick={() => { onClick={() => {
onBlockClick(meSnap[i]); onBlockClick(meSnap[i].interactivity);
onBlockClick(opSnap[i]); onBlockClick(opSnap[i].interactivity);
}} }}
></div> ></div>
))} ))}
...@@ -32,7 +37,7 @@ const BgExtraRow: FC<{ ...@@ -32,7 +37,7 @@ const BgExtraRow: FC<{
const BgRow: FC<{ const BgRow: FC<{
isSzone?: boolean; isSzone?: boolean;
opponent?: boolean; opponent?: boolean;
snap: Snapshot<PlaceInteractivity[]>; snap: Snapshot<BlockState[]>;
}> = ({ isSzone = false, opponent = false, snap }) => ( }> = ({ isSzone = false, opponent = false, snap }) => (
<div className={classnames("bg-row", { opponent })}> <div className={classnames("bg-row", { opponent })}>
{Array.from({ length: 5 }).map((_, i) => ( {Array.from({ length: 5 }).map((_, i) => (
...@@ -42,7 +47,7 @@ const BgRow: FC<{ ...@@ -42,7 +47,7 @@ const BgRow: FC<{
szone: isSzone, szone: isSzone,
highlight: !!snap[i], highlight: !!snap[i],
})} })}
onClick={() => onBlockClick(snap[i])} onClick={() => onBlockClick(snap[i].interactivity)}
></div> ></div>
))} ))}
</div> </div>
...@@ -68,6 +73,6 @@ const onBlockClick = (placeInteractivity: PlaceInteractivity) => { ...@@ -68,6 +73,6 @@ const onBlockClick = (placeInteractivity: PlaceInteractivity) => {
if (placeInteractivity) { if (placeInteractivity) {
sendSelectPlaceResponse(placeInteractivity.response); sendSelectPlaceResponse(placeInteractivity.response);
cardStore.inner.forEach((card) => (card.idleInteractivities = [])); cardStore.inner.forEach((card) => (card.idleInteractivities = []));
placeStore.clearAll(); placeStore.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