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

add TimeLimit reducer

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