Commit 558f5612 authored by Chunchi Che's avatar Chunchi Che

add TimeLimit reducer

parent df8c68bf
......@@ -5,6 +5,7 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { InitInfo, infoInitImpl } from "./initInfoSlice";
import { TimeLimit, updateTimeLimitImpl } from "./timeLimit";
import {
Hands,
handsCase,
......@@ -21,6 +22,8 @@ export interface DuelState {
opInitInfo?: InitInfo; // 对手的初始状态
meHands?: Hands; // 自己的手牌
opHands?: Hands; // 对手的手牌
meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时
currentPlayer?: number; // 当前的操作方
currentPhase?: string; // 当前的阶段
}
......@@ -37,6 +40,7 @@ const duelSlice = createSlice({
infoInit: infoInitImpl,
updateTurn: newTurnImpl,
updatePhase: newPhaseImpl,
updateTimeLimit: updateTimeLimitImpl,
// 手牌相关`Reducer`
clearHandsInteractivity: clearHandsInteractivityImpl,
......@@ -54,6 +58,7 @@ export const {
updatePhase,
clearHandsInteractivity,
addHandsInteractivity,
updateTimeLimit,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
......
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
import { judgeSelf } from "./util";
export interface TimeLimit {
leftTime: number;
}
// 更新计时
export const updateTimeLimitImpl: CaseReducer<
DuelState,
PayloadAction<[number, number]>
> = (state, action) => {
const player = action.payload[0];
const leftTime = action.payload[1];
if (judgeSelf(player, state)) {
state.meTimeLimit = { leftTime };
} else {
state.opTimeLimit = { leftTime };
}
};
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { store } from "../../store";
import { updateTimeLimit } from "../../reducers/duel/mod";
export default function handleTimeLimit(timeLimit: ygopro.StocTimeLimit) {
const dispatch = store.dispatch;
dispatch(updateTimeLimit([timeLimit.player, timeLimit.left_time]));
}
......@@ -14,6 +14,7 @@ import handleSelectHand from "./mora/selectHand";
import handleSelectTp from "./mora/selectTp";
import handleDeckCount from "./mora/deckCount";
import handleGameMsg from "./duel/gameMsg";
import handleTimeLimit from "./duel/timeLimit";
/*
* 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体,
......@@ -88,7 +89,7 @@ export default function handleSocketMessage(e: MessageEvent) {
break;
}
case "stoc_time_limit": {
// TODO
handleTimeLimit(pb.stoc_time_limit);
break;
}
......
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