Commit c61a4a16 authored by timel's avatar timel

feat: valtio store logic 15%

parent 39c16d26
import { proxy } from "valtio";
import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import type { DuelState } from "./types";
export const playMat = proxy<DuelState>({
opMagics: {
inner: Array(5)
.fill(null)
.map((_, i) => ({
location: {
location: ygopro.CardZone.SZONE,
},
idleInteractivities: [],
counters: {},
})),
},
});
import { proxy } from "valtio";
import { playMat } from "./playMat";
export const duelStore = proxy({
playMat,
});
import { proxy } from "valtio";
import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import type { DuelState } from "./types";
/**
* 生成一个指定长度的卡片数组
*/
function genDuelFieldState(location: ygopro.CardZone, n: number = 5) {
return {
inner: Array(n)
.fill(null)
.map((_) => ({
location: {
location,
},
idleInteractivities: [],
counters: {},
})),
};
}
export const playMat = proxy<DuelState>({
opMagics: genDuelFieldState(ygopro.CardZone.SZONE),
meMagics: genDuelFieldState(ygopro.CardZone.SZONE),
opMonsters: genDuelFieldState(ygopro.CardZone.MZONE),
meMonsters: genDuelFieldState(ygopro.CardZone.MZONE),
opGraveyard: { inner: [] },
meGraveyard: { inner: [] },
opBanishedZone: { inner: [] },
meBanishedZone: { inner: [] },
opHands: { inner: [] },
meHands: { inner: [] },
opDeck: { inner: [] },
meDeck: { inner: [] },
opExtraDeck: { inner: [] },
meExtraDeck: { inner: [] },
});
......@@ -6,26 +6,26 @@ export interface DuelState {
meInitInfo?: InitInfo; // 自己的初始状态
opInitInfo?: InitInfo; // 对手的初始状态
meHands?: HandState; // 自己的手牌
opHands?: HandState; // 对手的手牌
meHands: HandState; // 自己的手牌
opHands: HandState; // 对手的手牌
meMonsters?: MonsterState; // 自己的怪兽区状态
opMonsters?: MonsterState; // 对手的怪兽区状态
meMonsters: MonsterState; // 自己的怪兽区状态
opMonsters: MonsterState; // 对手的怪兽区状态
meMagics?: MagicState; // 自己的魔法陷阱区状态
opMagics?: MagicState; // 对手的魔法陷阱区状态
meMagics: MagicState; // 自己的魔法陷阱区状态
opMagics: MagicState; // 对手的魔法陷阱区状态
meGraveyard?: GraveyardState; // 自己的墓地状态
opGraveyard?: GraveyardState; // 对手的墓地状态
meGraveyard: GraveyardState; // 自己的墓地状态
opGraveyard: GraveyardState; // 对手的墓地状态
meBanishedZone?: BanishedZoneState; // 自己的除外区状态
opBanishedZone?: BanishedZoneState; // 对手的除外区状态
meBanishedZone: BanishedZoneState; // 自己的除外区状态
opBanishedZone: BanishedZoneState; // 对手的除外区状态
meDeck?: DeckState; // 自己的卡组状态
opDeck?: DeckState; // 对手的卡组状态
meDeck: DeckState; // 自己的卡组状态
opDeck: DeckState; // 对手的卡组状态
meExtraDeck?: ExtraDeckState; // 自己的额外卡组状态
opExtraDeck?: ExtraDeckState; // 对手的额外卡组状态
meExtraDeck: ExtraDeckState; // 自己的额外卡组状态
opExtraDeck: ExtraDeckState; // 对手的额外卡组状态
meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时
......@@ -54,7 +54,7 @@ export interface CardState {
occupant?: CardMeta; // 占据此位置的卡牌元信息
location: {
controler?: number;
location?: number;
location: ygopro.CardZone;
position?: ygopro.CardPosition;
overlay_sequence?: number;
}; // 位置信息
......
......@@ -2,6 +2,7 @@ export * from "./chatStore";
export * from "./joinStore";
export * from "./moraStore";
export * from "./playerStore";
export * from "./duelStore";
import { createContext, type ReactNode, useRef } from "react";
import { proxy } from "valtio";
......@@ -11,12 +12,14 @@ import { chatStore } from "./chatStore";
import { joinStore } from "./joinStore";
import { moraStore } from "./moraStore";
import { playerStore } from "./playerStore";
import { duelStore } from "./duelStore";
export const valtioStore = proxy({
playerStore,
chatStore,
joinStore,
moraStore,
duelStore,
});
devtools(valtioStore, { name: "valtio store", enabled: true });
......
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