Commit 33e986dd authored by timel's avatar timel

feat: valtio store logic 35%

parent 485fdcc8
......@@ -51,7 +51,7 @@ export interface CardText {
* */
export async function fetchCard(
id: number,
local?: boolean
local: boolean = true
): Promise<CardMeta> {
if (local) {
return await sqliteMiddleWare({
......
......@@ -58,6 +58,7 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
dispatch(
removeGraveyard({ controler: from.controler, sequence: from.sequence })
);
playMatStore.graveyards.remove(from.controler, from.sequence);
break;
}
......@@ -68,6 +69,7 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
sequence: from.sequence,
})
);
playMatStore.banishedZones.remove(from.controler, from.sequence);
break;
}
......@@ -75,6 +77,7 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
dispatch(
removeExtraDeck({ controler: from.controler, sequence: from.sequence })
);
playMatStore.extraDecks.remove(from.controler, from.sequence);
break;
}
......
......@@ -97,12 +97,28 @@ const wrap = <T extends DuelFieldState>(
...cards
);
},
setOccupant: async (
controller: number,
sequence: number,
id: number,
position?: ygopro.CardPosition
) => {
const meta = await fetchCard(id);
const target = res[getWhom(controller)][sequence];
target.occupant = meta;
if (position) {
target.location.position = position;
}
},
removeOccupant: (controller: number, sequence: number) => {
res[getWhom(controller)][sequence].occupant = undefined;
},
});
return res;
};
/**
* 🔥 决斗盘状态仓库,本文件核心,
* 💡 决斗盘状态仓库,本文件核心,
* 具体介绍可以点进`PlayMatState`去看
*/
export const playMat = proxy<PlayMatState>({
......
......@@ -12,6 +12,13 @@ export interface CardsBothSide<T extends DuelFieldState> extends BothSide<T> {
remove: (player: number, sequence: number) => void; // 移除特定位置的卡片
add: (controller: number, ids: number[]) => void; // 在末尾添加卡片
insert: (controller: number, sequence: number, id: number) => void; // 在指定位置插入卡片
setOccupant: (
controller: number,
sequence: number,
id: number,
position?: ygopro.CardPosition
) => void; // 设置卡片的卡片信息
removeOccupant: (controller: number, sequence: number) => void; // 移除卡片的卡片信息
}
export interface PlayMatState {
......
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