Commit 55eba807 authored by Chunchi Che's avatar Chunchi Che Committed by WANG HE

handle deckcount

parent 3989ad51
......@@ -10,6 +10,8 @@ import {
STOC_SELECT_HAND,
STOC_SELECT_TP,
STOC_HAND_RESULT,
STOC_DECK_COUNT,
STOC_DUEL_START,
} from "./protoDecl";
import StocChat from "./stoc/stocChat";
import StocJoinGame from "./stoc/stocJoinGame";
......@@ -19,6 +21,7 @@ import StocHsWatchChange from "./stoc/stocHsWatchChange";
import StocTypeChange from "./stoc/stocTypeChange";
import StocSelectHand from "./stoc/stocSelectHand";
import StocSelectTp from "./stoc/stocSelectTp";
import StocDeckCount from "./stoc/stocDeckCount";
/*
* 将[`ygoProPacket`]对象转换成[`ygopro.YgoStocMsg`]对象
......@@ -74,6 +77,16 @@ export function adaptStoc(packet: ygoProPacket): ygopro.YgoStocMsg {
break;
}
case STOC_DECK_COUNT: {
pb = new StocDeckCount(packet).upcast();
break;
}
case STOC_DUEL_START: {
// TODO
break;
}
default: {
break;
}
......
......@@ -19,3 +19,5 @@ export const STOC_TYPE_CHANGE = 19;
export const STOC_SELECT_HAND = 3;
export const STOC_SELECT_TP = 4;
export const STOC_HAND_RESULT = 5;
export const STOC_DECK_COUNT = 9;
export const STOC_DUEL_START = 21;
import { ygopro } from "../../idl/ocgcore";
import { ygoProPacket, StocAdapter } from "../packet";
const LITTLE_ENDIAN = true;
const INT16_BYTE_OFFSET = 2;
/*
* STOC DeckCount
*
* @param see ocgcore.proto
*
* @usage - 展示双方卡组信息
* */
export default class deckCountAdapter implements StocAdapter {
packet: ygoProPacket;
constructor(packet: ygoProPacket) {
this.packet = packet;
}
upcast(): ygopro.YgoStocMsg {
const pb = new ygopro.StocDeckCount({});
const dataView = new DataView(this.packet.exData.buffer);
pb.meMain = dataView.getInt16(0 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.meExtra = dataView.getInt16(1 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.meSide = dataView.getInt16(2 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.opMain = dataView.getInt16(3 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.opExtra = dataView.getInt16(4 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
pb.opSide = dataView.getInt16(5 * INT16_BYTE_OFFSET, LITTLE_ENDIAN);
return new ygopro.YgoStocMsg({
stoc_deck_count: pb,
});
}
}
......@@ -14,7 +14,7 @@ export default class joinGameAdapter implements StocAdapter {
}
upcast(): ygopro.YgoStocMsg {
// todo
// TODO
return new ygopro.YgoStocMsg({
stoc_join_game: new ygopro.StocJoinGame({}),
});
......
......@@ -9,6 +9,13 @@ export interface Player {
name?: string;
state?: string;
isHost?: boolean;
deckInfo?: deckInfo;
}
export interface deckInfo {
mainCnt: number;
extraCnt: number;
sideCnt: number;
}
export interface playerState {
......@@ -47,6 +54,12 @@ const playerSlice = createSlice({
player1Leave: (state) => {
state.player1 = {};
},
player0DeckInfo: (state, action: PayloadAction<deckInfo>) => {
state.player0.deckInfo = action.payload;
},
player1DeckInfo: (state, action: PayloadAction<deckInfo>) => {
state.player1.deckInfo = action.payload;
},
hostChange: (state, action: PayloadAction<number>) => {
const i = action.payload;
......@@ -77,6 +90,8 @@ export const {
player1Update,
player0Leave,
player1Leave,
player0DeckInfo,
player1DeckInfo,
hostChange,
observerIncrement,
observerChange,
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { store } from "../../store";
import { player0DeckInfo, player1DeckInfo } from "../../reducers/playerSlice";
// FIXME: player0 不一定是当前玩家
export default function handleDeckCount(pb: ygopro.YgoStocMsg) {
const dispath = store.dispatch;
const deckCount = pb.stoc_deck_count;
dispath(
player0DeckInfo({
mainCnt: deckCount.meMain,
extraCnt: deckCount.meExtra,
sideCnt: deckCount.meSide,
})
);
dispath(
player1DeckInfo({
mainCnt: deckCount.opMain,
extraCnt: deckCount.opExtra,
sideCnt: deckCount.opSide,
})
);
}
......@@ -12,6 +12,7 @@ import { ygoProPacket } from "../api/ocgcore/ocgAdapter/packet";
import { adaptStoc } from "../api/ocgcore/ocgAdapter/adapter";
import handleSelectHand from "./mora/selectHand";
import handleSelectTp from "./mora/selectTp";
import handleDeckCount from "./mora/deckCount";
/*
* 先将从长连接中读取到的二进制数据通过Adapter转成protobuf结构体,
......@@ -69,6 +70,17 @@ export default function handleSocketMessage(e: MessageEvent) {
break;
}
case "stoc_deck_count": {
handleDeckCount(pb);
break;
}
case "stoc_duel_start": {
// TODO
console.log("TODO: handle STOC DuleStart.");
break;
}
default: {
console.log(packet);
......
......@@ -13,6 +13,7 @@ import {
selectTpSelectAble,
unSelectTpAble,
} from "../reducers/moraSlice";
import { selectPlayer0, selectPlayer1 } from "../reducers/playerSlice";
import { store } from "../store";
// TODO: 应该展示对手卡组信息和聊天信息
......@@ -20,6 +21,8 @@ export default function Mora() {
const dispatch = store.dispatch;
const selectHandAble = useAppSelector(selectHandSelectAble);
const selectTpAble = useAppSelector(selectTpSelectAble);
const player0 = useAppSelector(selectPlayer0);
const player1 = useAppSelector(selectPlayer1);
const handleSelectScissors = () => {
sendHandResult("scissors");
......@@ -63,6 +66,16 @@ export default function Mora() {
second
</button>
</div>
<div className="item">
<p>
Me: main={player0.deckInfo?.mainCnt}, extra=
{player0.deckInfo?.extraCnt}, side={player0.deckInfo?.sideCnt}
</p>
<p>
Me: main={player1.deckInfo?.mainCnt}, extra=
{player1.deckInfo?.extraCnt}, side={player1.deckInfo?.sideCnt}
</p>
</div>
</div>
);
}
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