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

update placeStore

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