Commit 9f7c37a8 authored by Chunchi Che's avatar Chunchi Che

optimize NewWaitRoom

parent 4525f1bb
Pipeline #22935 failed with stages
in 10 minutes and 58 seconds
...@@ -3,6 +3,12 @@ import { roomStore } from "@/stores"; ...@@ -3,6 +3,12 @@ import { roomStore } from "@/stores";
type MsgSibylName = ygopro.StocGameMessage.MsgSibylName; type MsgSibylName = ygopro.StocGameMessage.MsgSibylName;
export default (sibylName: MsgSibylName) => { export default (sibylName: MsgSibylName) => {
roomStore.getMePlayer().name = sibylName.name_0; const me = roomStore.getMePlayer();
roomStore.getOpPlayer().name = sibylName.name_1; const op = roomStore.getOpPlayer();
if (me) {
me.name = sibylName.name_0;
}
if (op) {
op.name = sibylName.name_1;
}
}; };
...@@ -5,15 +5,22 @@ import { roomStore } from "@/stores"; ...@@ -5,15 +5,22 @@ import { roomStore } from "@/stores";
export default function handleDeckCount(pb: ygopro.YgoStocMsg) { export default function handleDeckCount(pb: ygopro.YgoStocMsg) {
const deckCount = pb.stoc_deck_count; const deckCount = pb.stoc_deck_count;
roomStore.getMePlayer().deckInfo = { const me = roomStore.getMePlayer();
const op = roomStore.getOpPlayer();
if (me) {
me.deckInfo = {
mainSize: deckCount.meMain, mainSize: deckCount.meMain,
extraSize: deckCount.meExtra, extraSize: deckCount.meExtra,
sideSize: deckCount.meSide, sideSize: deckCount.meSide,
}; };
}
roomStore.getOpPlayer().deckInfo = { if (op) {
op.deckInfo = {
mainSize: deckCount.opMain, mainSize: deckCount.opMain,
extraSize: deckCount.opExtra, extraSize: deckCount.opExtra,
sideSize: deckCount.opSide, sideSize: deckCount.opSide,
}; };
}
} }
...@@ -37,12 +37,12 @@ class RoomStore implements NeosStore { ...@@ -37,12 +37,12 @@ class RoomStore implements NeosStore {
stage: RoomStage = RoomStage.WAITING; stage: RoomStage = RoomStage.WAITING;
getMePlayer() { getMePlayer() {
if (this.selfType == SelfType.PLAYER1) return this.players[0]; if (this.selfType == SelfType.PLAYER1) return this.players.at(0);
return this.players[1]; return this.players.at(1);
} }
getOpPlayer() { getOpPlayer() {
if (this.selfType == SelfType.PLAYER1) return this.players[1]; if (this.selfType == SelfType.PLAYER1) return this.players.at(1);
return this.players[0]; return this.players.at(0);
} }
reset(): void { reset(): void {
......
...@@ -59,14 +59,14 @@ export const LifeBar: React.FC = () => { ...@@ -59,14 +59,14 @@ export const LifeBar: React.FC = () => {
<div className={styles.container}> <div className={styles.container}>
<LifeBarItem <LifeBarItem
active={!matStore.isMe(currentPlayer)} active={!matStore.isMe(currentPlayer)}
name={snapPlayer.getOpPlayer().name ?? "?"} name={snapPlayer.getOpPlayer()?.name ?? "?"}
life={opLife} life={opLife}
timeLimit={opTimeLimit} timeLimit={opTimeLimit}
isMe={false} isMe={false}
/> />
<LifeBarItem <LifeBarItem
active={matStore.isMe(currentPlayer)} active={matStore.isMe(currentPlayer)}
name={snapPlayer.getMePlayer().name ?? "?"} name={snapPlayer.getMePlayer()?.name ?? "?"}
life={meLife} life={meLife}
timeLimit={myTimeLimit} timeLimit={myTimeLimit}
isMe={true} isMe={true}
......
...@@ -95,12 +95,12 @@ export const Component: React.FC = () => { ...@@ -95,12 +95,12 @@ export const Component: React.FC = () => {
size="large" size="large"
className={styles["btn-join"]} className={styles["btn-join"]}
onClick={() => { onClick={() => {
room.getMePlayer().state == PlayerState.NO_READY room.getMePlayer()?.state === PlayerState.NO_READY
? sendHsReady() ? sendHsReady()
: sendHsNotReady(); : sendHsNotReady();
}} }}
> >
{room.getMePlayer().state == PlayerState.NO_READY {room.getMePlayer()?.state === PlayerState.NO_READY
? "决斗准备" ? "决斗准备"
: "取消准备"} : "取消准备"}
</Button> </Button>
...@@ -235,7 +235,13 @@ const PlayerZone: React.FC<{ ...@@ -235,7 +235,13 @@ const PlayerZone: React.FC<{
<OrderPopup open={false}> <OrderPopup open={false}>
<div style={{ position: "relative" }}> <div style={{ position: "relative" }}>
<Avatar <Avatar
src={avatar ?? `${NeosConfig.assetsPath}/default-avatar.png`} src={
avatar
? avatar
: player
? `${NeosConfig.assetsPath}/default-avatar.png`
: ""
}
size={48} size={48}
/> />
{player?.state === PlayerState.READY && ( {player?.state === PlayerState.READY && (
......
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