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