Commit 11a974ad authored by Chunchi Che's avatar Chunchi Che

add auto return to single mode

parent 102cf9fc
Pipeline #28717 passed with stages
in 19 minutes and 53 seconds
...@@ -3,6 +3,11 @@ import PhaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType; ...@@ -3,6 +3,11 @@ import PhaseType = ygopro.StocGameMessage.MsgNewPhase.PhaseType;
import { CardMeta } from "@/api"; import { CardMeta } from "@/api";
//! 一些Neos中基础的数据结构 //! 一些Neos中基础的数据结构
// Mode
export const MODE_SINGLE = 0x0;
export const MODE_MATCH = 0x1;
export const MODE_TAG = 0x2;
// Position // Position
export const FACEUP_ATTACK = 0x1; export const FACEUP_ATTACK = 0x1;
......
...@@ -5,6 +5,5 @@ export default function handleDuelEnd( ...@@ -5,6 +5,5 @@ export default function handleDuelEnd(
container: Container, container: Container,
_pb: ygopro.YgoStocMsg, _pb: ygopro.YgoStocMsg,
) { ) {
console.log("duel end");
container.context.matStore.duelEnd = true; container.context.matStore.duelEnd = true;
} }
...@@ -5,6 +5,11 @@ export default function handleJoinGame( ...@@ -5,6 +5,11 @@ export default function handleJoinGame(
container: Container, container: Container,
pb: ygopro.YgoStocMsg, pb: ygopro.YgoStocMsg,
) { ) {
const _msg = pb.stoc_join_game; const context = container.context;
container.context.roomStore.joined = true; const msg = pb.stoc_join_game;
console.log(msg.mode);
context.roomStore.joined = true;
context.roomStore.mode = msg.mode;
} }
...@@ -5,6 +5,8 @@ import { ygopro } from "@/api"; ...@@ -5,6 +5,8 @@ import { ygopro } from "@/api";
import StocHsPlayerChange = ygopro.StocHsPlayerChange; import StocHsPlayerChange = ygopro.StocHsPlayerChange;
import SelfType = ygopro.StocTypeChange.SelfType; import SelfType = ygopro.StocTypeChange.SelfType;
import HandType = ygopro.HandType; import HandType = ygopro.HandType;
import { MODE_MATCH, MODE_SINGLE, MODE_TAG } from "@/common";
import { type NeosStore } from "./shared"; import { type NeosStore } from "./shared";
export interface Player { export interface Player {
...@@ -33,6 +35,13 @@ export enum RoomStage { ...@@ -33,6 +35,13 @@ export enum RoomStage {
DUEL_START = 6, // 决斗开始 DUEL_START = 6, // 决斗开始
} }
// Duel Mode
export enum DuelMode {
SINGLE = MODE_SINGLE,
MATCH = MODE_MATCH,
TAG = MODE_TAG,
}
export class RoomStore implements NeosStore { export class RoomStore implements NeosStore {
joined: boolean = false; // 是否已经加入房间 joined: boolean = false; // 是否已经加入房间
players: (Player | undefined)[] = Array.from({ length: 4 }).map( players: (Player | undefined)[] = Array.from({ length: 4 }).map(
...@@ -43,6 +52,7 @@ export class RoomStore implements NeosStore { ...@@ -43,6 +52,7 @@ export class RoomStore implements NeosStore {
selfType: SelfType = 0; // 当前玩家的类型 selfType: SelfType = 0; // 当前玩家的类型
stage: RoomStage = RoomStage.WAITING; stage: RoomStage = RoomStage.WAITING;
errorMsg?: string = undefined; // 错误信息 errorMsg?: string = undefined; // 错误信息
mode?: DuelMode = undefined; // 当前对局模式
getMePlayer() { getMePlayer() {
return this.players.find((player) => player?.isMe); return this.players.find((player) => player?.isMe);
...@@ -58,6 +68,7 @@ export class RoomStore implements NeosStore { ...@@ -58,6 +68,7 @@ export class RoomStore implements NeosStore {
this.isHost = false; this.isHost = false;
this.stage = RoomStage.WAITING; this.stage = RoomStage.WAITING;
this.errorMsg = undefined; this.errorMsg = undefined;
this.mode = undefined;
} }
} }
......
import React, { CSSProperties } from "react"; import React, { CSSProperties } from "react";
import { useNavigate } from "react-router-dom";
import { proxy, useSnapshot } from "valtio"; import { proxy, useSnapshot } from "valtio";
import { fetchStrings, Region } from "@/api"; import { fetchStrings, Region } from "@/api";
import { replayStore, resetDuel } from "@/stores"; import { DuelMode, replayStore, resetDuel, roomStore } from "@/stores";
import { NeosModal } from "../NeosModal"; import { NeosModal } from "../NeosModal";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
...@@ -23,10 +24,16 @@ const localStore = proxy(defaultProps); ...@@ -23,10 +24,16 @@ const localStore = proxy(defaultProps);
export const EndModal: React.FC = () => { export const EndModal: React.FC = () => {
const { isOpen, isWin, reason } = useSnapshot(localStore); const { isOpen, isWin, reason } = useSnapshot(localStore);
const { isReplay } = useSnapshot(replayStore); const { isReplay } = useSnapshot(replayStore);
const navigate = useNavigate();
const onReturn = () => { const onReturn = () => {
resetDuel(); resetDuel();
rs(); rs();
if (roomStore.mode === DuelMode.SINGLE) {
// duel end in single mode, return to match page
navigate("/match");
}
}; };
return ( return (
......
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