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
...@@ -14,7 +14,7 @@ const INT32_BYTE_OFFSET = 4; ...@@ -14,7 +14,7 @@ const INT32_BYTE_OFFSET = 4;
export default (data: Uint8Array) => { export default (data: Uint8Array) => {
const dataView = new DataView(data.buffer); const dataView = new DataView(data.buffer);
// TODO: 对DataView包装下实现一个BufferIO类,便于解析二进制数据 // TODO: use `BufferIO`
const pT = dataView.getUint8(0); const pT = dataView.getUint8(0);
const playerType = const playerType =
(pT & 0xf) <= 0 (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 { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { store } from "../../store";
import { meInfoInit, opInfoInit } from "../../reducers/duel/mod";
export default function handleGameMsg(pb: ygopro.YgoStocMsg) { export default function handleGameMsg(pb: ygopro.YgoStocMsg) {
const dispatch = store.dispatch;
const msg = pb.stoc_game_msg; const msg = pb.stoc_game_msg;
switch (msg.gameMsg) { switch (msg.gameMsg) {
case "start": { case "start": {
// TODO const start = msg.start;
console.log(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; break;
} }
......
...@@ -6,6 +6,7 @@ import joinedReducer from "./reducers/joinSlice"; ...@@ -6,6 +6,7 @@ import joinedReducer from "./reducers/joinSlice";
import chatReducer from "./reducers/chatSlice"; import chatReducer from "./reducers/chatSlice";
import playerReducer from "./reducers/playerSlice"; import playerReducer from "./reducers/playerSlice";
import moraReducer from "./reducers/moraSlice"; import moraReducer from "./reducers/moraSlice";
import duelReducer from "./reducers/duel/mod";
export const store = configureStore({ export const store = configureStore({
reducer: { reducer: {
...@@ -13,6 +14,7 @@ export const store = configureStore({ ...@@ -13,6 +14,7 @@ export const store = configureStore({
chat: chatReducer, chat: chatReducer,
player: playerReducer, player: playerReducer,
mora: moraReducer, 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