Commit 733c252f authored by Chunchi Che's avatar Chunchi Che

update placeStore

parent 051fc7f6
......@@ -7,10 +7,12 @@ export default (fieldDisabled: MsgFieldDisabled) => {
switch (action.zone) {
case ygopro.CardZone.MZONE:
case ygopro.CardZone.SZONE:
placeStore.set(action.zone, action.controller, action.sequence, {
interactivity: undefined,
disabled: action.disabled,
});
const block = placeStore.of(action);
if (block) {
block.disabled = action.disabled;
} else {
console.warn("<FieldDisabled>block is undefined");
}
break;
default:
console.warn("<FieldDisabled>zone is not MZONE nor SZONE!");
......
......@@ -13,17 +13,17 @@ export default (selectPlace: MsgSelectPlace) => {
switch (place.zone) {
case ygopro.CardZone.MZONE:
case ygopro.CardZone.SZONE:
placeStore.set(place.zone, place.controller, place.sequence, {
interactivity: {
const block = placeStore.of(place);
if (block) {
block.interactivity = {
interactType: InteractType.PLACE_SELECTABLE,
response: {
controller: place.controller,
zone: place.zone,
sequence: place.sequence,
},
},
disabled: false,
});
};
}
break;
}
}
......
......@@ -15,17 +15,19 @@ export type PlaceInteractivity =
}>
| undefined;
const { MZONE, SZONE } = ygopro.CardZone;
const { MZONE, SZONE, HAND, GRAVE, EXTRA } = ygopro.CardZone;
export interface BlockState {
interactivity?: PlaceInteractivity; // 互动性
disabled: boolean; // 是否被禁用
chainIndex: number[]; // 当前位置上的连锁序号。YGOPRO和MASTER DUEL的连锁都是和位置绑定的,因此在`PlaceStore`中记录连锁状态。
}
const genPLaces = (n: number): BlockState[] =>
Array.from({ length: n }).map(() => ({
interactivity: undefined,
disabled: false,
chainIndex: [],
}));
const initialState = {
......@@ -37,27 +39,35 @@ const initialState = {
me: genPLaces(6),
op: genPLaces(6),
},
[HAND]: {
me: [],
op: [],
},
[GRAVE]: {
me: [],
op: [],
},
[EXTRA]: {
me: [],
op: [],
},
};
class PlaceStore implements NeosStore {
inner: {
[MZONE]: {
me: BlockState[];
op: BlockState[];
};
[SZONE]: {
[zone: number]: {
me: BlockState[];
op: BlockState[];
};
} = initialState;
set(
zone: ygopro.CardZone.MZONE | ygopro.CardZone.SZONE,
controller: number,
sequence: number,
state: BlockState,
) {
placeStore.inner[zone][matStore.isMe(controller) ? "me" : "op"][sequence] =
state;
of(location: {
zone: ygopro.CardZone;
controller: number;
sequence: number;
}): BlockState | undefined {
return placeStore.inner[location.zone][
matStore.isMe(location.controller) ? "me" : "op"
][location.sequence];
}
clearAllInteractivity() {
(["me", "op"] as const).forEach((who) => {
......
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