Commit 23ade447 authored by timel's avatar timel

feat: valtio store logic 80%

parent 24998446
...@@ -11,6 +11,12 @@ import { ...@@ -11,6 +11,12 @@ import {
setEnableM2, setEnableM2,
} from "@/reducers/duel/mod"; } from "@/reducers/duel/mod";
import { AppDispatch } from "@/store"; import { AppDispatch } from "@/store";
import {
clearAllIdleInteractivities as FIXME_clearAllIdleInteractivities,
matStore,
} from "@/valtioStores";
import MsgSelectBattleCmd = ygopro.StocGameMessage.MsgSelectBattleCmd; import MsgSelectBattleCmd = ygopro.StocGameMessage.MsgSelectBattleCmd;
export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => { export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => {
...@@ -20,6 +26,8 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => { ...@@ -20,6 +26,8 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => {
// 先清掉之前的互动性 // 先清掉之前的互动性
dispatch(clearAllIdleInteractivities(player)); dispatch(clearAllIdleInteractivities(player));
FIXME_clearAllIdleInteractivities(player);
const dispatcher = ( const dispatcher = (
battleData: MsgSelectBattleCmd.BattleCmd.BattleData, battleData: MsgSelectBattleCmd.BattleCmd.BattleData,
interactType: InteractType | undefined, interactType: InteractType | undefined,
...@@ -67,6 +75,30 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => { ...@@ -67,6 +75,30 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => {
cmd.battle_datas.forEach((data) => { cmd.battle_datas.forEach((data) => {
const cardInfo = data.card_info; const cardInfo = data.card_info;
// valtio
if (interactType) {
const map: Partial<
Record<InteractType, undefined | Partial<Interactivity<number>>>
> = {
[InteractType.ACTIVATE]: { activateIndex: data.effect_description },
[InteractType.ATTACK]: { directAttackAble: data.direct_attackable },
};
const tmp = map[interactType];
if (tmp) {
matStore
.getZone(cardInfo.location)
.addIdleInteractivity(player, cardInfo.sequence, {
...tmp,
interactType,
response: data.response,
});
} else {
console.warn(`Unhandled InteractType:`, interactType);
}
}
// >>> 从这开始删除 >>>
switch (cardInfo.location) { switch (cardInfo.location) {
case ygopro.CardZone.HAND: { case ygopro.CardZone.HAND: {
dispatcher(data, interactType, addHandsIdleInteractivity); dispatcher(data, interactType, addHandsIdleInteractivity);
...@@ -86,11 +118,15 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => { ...@@ -86,11 +118,15 @@ export default (selectBattleCmd: MsgSelectBattleCmd, dispatch: AppDispatch) => {
default: { default: {
} }
} }
// <<< 到这结束删除,上面的const dispatcher也删掉 <<<
}); });
}); });
dispatch(setEnableM2(selectBattleCmd.enable_m2)); dispatch(setEnableM2(selectBattleCmd.enable_m2));
dispatch(setEnableEp(selectBattleCmd.enable_ep)); dispatch(setEnableEp(selectBattleCmd.enable_ep));
matStore.phase.enableM2 = selectBattleCmd.enable_m2;
matStore.phase.enableEp = selectBattleCmd.enable_ep;
}; };
function battleTypeToInteracType( function battleTypeToInteracType(
......
...@@ -12,15 +12,22 @@ import { ...@@ -12,15 +12,22 @@ import {
setEnableEp, setEnableEp,
} from "@/reducers/duel/mod"; } from "@/reducers/duel/mod";
import { AppDispatch } from "@/store"; import { AppDispatch } from "@/store";
import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd;
import { ActionCreatorWithPayload } from "@reduxjs/toolkit"; import { ActionCreatorWithPayload } from "@reduxjs/toolkit";
import {
clearAllIdleInteractivities as FIXME_clearAllIdleInteractivities,
matStore,
} from "@/valtioStores";
import MsgSelectIdleCmd = ygopro.StocGameMessage.MsgSelectIdleCmd;
export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => { export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
const player = selectIdleCmd.player; const player = selectIdleCmd.player;
const cmds = selectIdleCmd.idle_cmds; const cmds = selectIdleCmd.idle_cmds;
// 先清掉之前的互动性 // 先清掉之前的互动性
dispatch(clearAllIdleInteractivities(player)); dispatch(clearAllIdleInteractivities(player));
FIXME_clearAllIdleInteractivities(player);
const dispatcher = ( const dispatcher = (
idleData: MsgSelectIdleCmd.IdleCmd.IdleData, idleData: MsgSelectIdleCmd.IdleCmd.IdleData,
...@@ -66,6 +73,28 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => { ...@@ -66,6 +73,28 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
cmd.idle_datas.forEach((data) => { cmd.idle_datas.forEach((data) => {
const cardInfo = data.card_info; const cardInfo = data.card_info;
// valtio。代码从 ./selectBattleCmd.ts 复制过来的
if (interactType) {
const map: Partial<
Record<InteractType, undefined | Partial<Interactivity<number>>>
> = {
[InteractType.ACTIVATE]: { activateIndex: data.effect_description },
};
const tmp = map[interactType];
if (tmp) {
matStore
.getZone(cardInfo.location)
.addIdleInteractivity(player, cardInfo.sequence, {
...tmp,
interactType,
response: data.response,
});
} else {
console.warn(`Unhandled InteractType:`, interactType);
}
}
switch (cardInfo.location) { switch (cardInfo.location) {
case ygopro.CardZone.HAND: { case ygopro.CardZone.HAND: {
dispatcher(data, interactType, addHandsIdleInteractivity); dispatcher(data, interactType, addHandsIdleInteractivity);
...@@ -106,6 +135,9 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => { ...@@ -106,6 +135,9 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
dispatch(setEnableBp(selectIdleCmd.enable_bp)); dispatch(setEnableBp(selectIdleCmd.enable_bp));
dispatch(setEnableEp(selectIdleCmd.enable_ep)); dispatch(setEnableEp(selectIdleCmd.enable_ep));
matStore.phase.enableBp = selectIdleCmd.enable_bp;
matStore.phase.enableEp = selectIdleCmd.enable_ep;
}; };
function idleTypeToInteractType( function idleTypeToInteractType(
......
...@@ -3,8 +3,27 @@ import { updateHandsMeta } from "@/reducers/duel/handsSlice"; ...@@ -3,8 +3,27 @@ import { updateHandsMeta } from "@/reducers/duel/handsSlice";
import { AppDispatch } from "@/store"; import { AppDispatch } from "@/store";
import MsgShuffleHand = ygopro.StocGameMessage.MsgShuffleHand; import MsgShuffleHand = ygopro.StocGameMessage.MsgShuffleHand;
import { matStore } from "@/valtioStores";
export default (shuffleHand: MsgShuffleHand, dispatch: AppDispatch) => { export default (shuffleHand: MsgShuffleHand, dispatch: AppDispatch) => {
dispatch( dispatch(
updateHandsMeta({ controler: shuffleHand.player, codes: shuffleHand.hands }) updateHandsMeta({ controler: shuffleHand.player, codes: shuffleHand.hands })
); );
const { hands: codes, player: controller } = shuffleHand;
const metas = codes.map((code) => {
return {
occupant: { id: code, data: {}, text: {} },
location: {
controler: controller,
location: ygopro.CardZone.HAND,
},
idleInteractivities: [],
counters: {},
};
});
matStore.hands.at(controller).length = 0;
matStore.hands.at(controller).push(...metas);
}; };
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