Commit 430350b1 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/slice/game' into 'main'

add duelSlice and impl initInfo slice

See merge request !18
parents 37f73cd3 972ed5f0
Pipeline #18013 failed with stages
in 9 seconds
......@@ -14,7 +14,7 @@ const INT32_BYTE_OFFSET = 4;
export default (data: Uint8Array) => {
const dataView = new DataView(data.buffer);
// TODO: 对DataView包装下实现一个BufferIO类,便于解析二进制数据
// TODO: use `BufferIO`
const pT = dataView.getUint8(0);
const playerType =
(pT & 0xf) <= 0
......
export interface InitInfo {
playerType?: string;
masterRule?: string;
life: number;
deckSize: number;
extraSize: number;
}
/*
* 对局内的状态更新逻辑
*
* */
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { InitInfo } from "./initInfoSlice";
export interface DuelState {
meInitInfo?: InitInfo; // 自己的初始状态
opInitInfo?: InitInfo; // 对手的初始状态
}
const initialState: DuelState = {};
const duelSlice = createSlice({
name: "duel",
initialState,
reducers: {
meInfoInit: (state, action: PayloadAction<InitInfo>) => {
state.meInitInfo = action.payload;
},
opInfoInit: (state, action: PayloadAction<InitInfo>) => {
state.opInitInfo = action.payload;
},
},
});
export const { meInfoInit, opInfoInit } = duelSlice.actions;
export default duelSlice.reducer;
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { store } from "../../store";
import { meInfoInit, opInfoInit } from "../../reducers/duel/mod";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch;
const msg = pb.stoc_game_msg;
switch (msg.gameMsg) {
case "start": {
// TODO
console.log(msg.start);
const start = msg.start;
dispatch(
meInfoInit({
playerType: start.playerType.toString(),
life: start.life1,
deckSize: start.deckSize1,
extraSize: start.extraSize1,
})
);
dispatch(
opInfoInit({
life: start.life2,
deckSize: start.deckSize2,
extraSize: start.extraSize2,
})
);
break;
}
......
......@@ -6,6 +6,7 @@ import joinedReducer from "./reducers/joinSlice";
import chatReducer from "./reducers/chatSlice";
import playerReducer from "./reducers/playerSlice";
import moraReducer from "./reducers/moraSlice";
import duelReducer from "./reducers/duel/mod";
export const store = configureStore({
reducer: {
......@@ -13,6 +14,7 @@ export const store = configureStore({
chat: chatReducer,
player: playerReducer,
mora: moraReducer,
duel: duelReducer,
},
});
......
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