Commit 43b00a01 authored by Chunchi Che's avatar Chunchi Che

add Phase slice

parent 1bdc9c2b
...@@ -9,6 +9,7 @@ import * as GAME_MSG from "../../protoDecl"; ...@@ -9,6 +9,7 @@ import * as GAME_MSG from "../../protoDecl";
import MsgStartAdapter from "./start"; import MsgStartAdapter from "./start";
import MsgDrawAdapter from "./draw"; import MsgDrawAdapter from "./draw";
import MsgNewTurnAdapter from "./newTurn"; import MsgNewTurnAdapter from "./newTurn";
import MsgNewPhaseAdapter from "./newPhase";
/* /*
* STOC GameMsg * STOC GameMsg
...@@ -49,6 +50,11 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -49,6 +50,11 @@ export default class GameMsgAdapter implements StocAdapter {
break; break;
} }
case GAME_MSG.MSG_NEW_PHASE: {
gameMsg.new_phase = MsgNewPhaseAdapter(gameData);
break;
}
default: { default: {
console.log("Unhandled GameMessage function=", func); console.log("Unhandled GameMessage function=", func);
......
...@@ -24,6 +24,7 @@ export default (data: Uint8Array) => { ...@@ -24,6 +24,7 @@ export default (data: Uint8Array) => {
break; break;
} }
case 0x02: { case 0x02: {
phaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType.STANDBY;
break; break;
} }
case 0x04: { case 0x04: {
......
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
meHandsCase, meHandsCase,
} from "./handsSlice"; } from "./handsSlice";
import { newTurnImpl } from "./turnSlice"; import { newTurnImpl } from "./turnSlice";
import { newPhaseImpl } from "./phaseSlice";
import { RootState } from "../../store"; import { RootState } from "../../store";
export interface DuelState { export interface DuelState {
...@@ -20,6 +21,7 @@ export interface DuelState { ...@@ -20,6 +21,7 @@ export interface DuelState {
meHands?: Hands; // 自己的手牌 meHands?: Hands; // 自己的手牌
opHands?: Hands; // 对手的手牌 opHands?: Hands; // 对手的手牌
currentPlayer?: number; // 当前的操作方 currentPlayer?: number; // 当前的操作方
currentPhase?: string; // 当前的阶段
} }
const initialState: DuelState = {}; const initialState: DuelState = {};
...@@ -33,6 +35,7 @@ const duelSlice = createSlice({ ...@@ -33,6 +35,7 @@ const duelSlice = createSlice({
meAddHands: meAddHandsImpl, meAddHands: meAddHandsImpl,
opAddHands: opAddHandsImpl, opAddHands: opAddHandsImpl,
updateTurn: newTurnImpl, updateTurn: newTurnImpl,
updatePhase: newPhaseImpl,
}, },
extraReducers(builder) { extraReducers(builder) {
meHandsCase(builder); meHandsCase(builder);
......
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { RootState } from "../../store";
import { DuelState } from "./mod";
export const newPhaseImpl: CaseReducer<DuelState, PayloadAction<string>> = (
state,
action
) => {
state.currentPhase = action.payload;
};
export const selectCurrentPhase = (state: RootState) => state.duel.currentPhase;
...@@ -3,6 +3,7 @@ import { store } from "../../store"; ...@@ -3,6 +3,7 @@ import { store } from "../../store";
import onMsgStart from "./start"; import onMsgStart from "./start";
import onMsgDraw from "./draw"; import onMsgDraw from "./draw";
import onMsgNewTurn from "./newTurn"; import onMsgNewTurn from "./newTurn";
import onMsgNewPhase from "./newPhase";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) { export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -30,6 +31,13 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) { ...@@ -30,6 +31,13 @@ export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
break; break;
} }
case "new_phase": {
const newPhase = msg.new_phase;
onMsgNewPhase(newPhase, dispatch);
break;
}
default: { default: {
console.log("Unhandled GameMsg=" + msg.gameMsg); console.log("Unhandled GameMsg=" + msg.gameMsg);
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store";
export default (
newPhase: ygopro.StocGameMessage.MsgNewPhase,
dispatch: AppDispatch
) => {
// TODO
};
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