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