Commit e3b696b8 authored by timel's avatar timel

feat: valtio store logic 75%

parent c77fde8c
import { ygopro } from "@/api"; import { ygopro } from "@/api";
import { reloadField } from "@/reducers/duel/mod"; import { reloadField } from "@/reducers/duel/mod";
import { AppDispatch } from "@/store"; import { AppDispatch } from "@/store";
import MsgReloadField = ygopro.StocGameMessage.MsgReloadField;
import { matStore, type DuelFieldState } from "@/valtioStores";
type MsgReloadField = ygopro.StocGameMessage.MsgReloadField;
type ZoneActions = ygopro.StocGameMessage.MsgReloadField.ZoneAction[];
export default (field: MsgReloadField, dispatch: AppDispatch) => { export default (field: MsgReloadField, dispatch: AppDispatch) => {
dispatch(reloadField(field)); dispatch(reloadField(field));
const _duel_rule = field.duel_rule;
const gamers = ["me", "op"] as const;
gamers.forEach((gamer) => {
matStore.banishedZones[gamer] = [];
matStore.extraDecks[gamer] = [];
matStore.graveyards[gamer] = [];
matStore.hands[gamer] = [];
matStore.monsters[gamer] = [];
matStore.magics[gamer] = [];
});
const { MZONE, SZONE, HAND, DECK, GRAVE, REMOVED, EXTRA } = ygopro.CardZone;
const zones = [MZONE, SZONE, HAND, DECK, GRAVE, REMOVED, EXTRA] as const;
field.actions.forEach(({ player, zone_actions }) => {
zones.forEach((zone) => {
reloadDuelField(
zone,
zone_actions.filter((item) => item.zone === zone),
player
);
});
});
}; };
/** 可以理解成reload DuelFieldState */
function reloadDuelField(
cardZone: ygopro.CardZone,
zoneActions: ZoneActions,
controller: number
) {
zoneActions.sort((a, b) => a.sequence - b.sequence);
const cards = zoneActions.map((action) => {
// FIXME: OVERLAY
return {
location: {
controler: controller,
location: action.zone,
position: action.position,
},
idleInteractivities: [],
counters: {},
reload: true,
};
});
matStore.getZone(cardZone).at(controller).length = 0;
matStore
.getZone(cardZone)
.at(controller)
.push(...cards);
}
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