diff --git a/cocoscreator_projects/YouleNexus/assets/framework/config/runtime-mode.ts b/cocoscreator_projects/YouleNexus/assets/framework/config/runtime-mode.ts index 41328f9..220eb37 100644 --- a/cocoscreator_projects/YouleNexus/assets/framework/config/runtime-mode.ts +++ b/cocoscreator_projects/YouleNexus/assets/framework/config/runtime-mode.ts @@ -1,15 +1,27 @@ +// 1. 先 export type export type RuntimeMode = 'debug' | 'release'; -/** - * 手动覆盖运行模式。 - * null = 自动跟随构建类型(推荐,发布前保持 null)。 - * 'debug' / 'release' = 强制该模式(release 包里临时调试,或编辑器预览里验证正式行为)。 - */ -export const MODE_OVERRIDE: RuntimeMode | null = null; +declare const DEBUG: boolean | undefined; + +// 2. 函数引用 RuntimeMode(此时 type 已 export) +function readModeFromUrl(): RuntimeMode | null { + if (typeof window === 'undefined' || !window.location) return null; + const m = new URLSearchParams(window.location.search).get('mode'); + if (m === 'debug' || m === 'release') return m; + return null; +} + +function detectDebugBuild(): boolean { + if (typeof DEBUG !== 'undefined') return DEBUG; + return true; // Cocos 编辑器内 dev workflow 默认;生产 build 改 false +} + +// 3. 导出常量 +export const MODE_OVERRIDE: RuntimeMode | null = + readModeFromUrl() ?? (detectDebugBuild() ? 'debug' : 'release'); /** * 解析运行模式:override 优先,否则由是否 debug 构建决定。 - * isDebugBuild 由调用方读 Cocos 全局 DEBUG 传入(typeof DEBUG !== 'undefined' ? DEBUG : true)。 */ export function resolveRuntimeMode( isDebugBuild: boolean, diff --git a/cocoscreator_projects/YouleNexus/assets/scripts/RoomEventProbe.ts b/cocoscreator_projects/YouleNexus/assets/scripts/RoomEventProbe.ts new file mode 100644 index 0000000..a69d97d --- /dev/null +++ b/cocoscreator_projects/YouleNexus/assets/scripts/RoomEventProbe.ts @@ -0,0 +1,76 @@ +import { _decorator, Component } from 'cc'; +import { PlatformSession } from '../framework/platform/session.ts'; +import { RoomRPCBus } from '../framework/platform/room-rpc-bus.ts'; +import { EventBus } from '../framework/core/events.ts'; +import type { NetClientEvents } from '../framework/net/net-client.ts'; +import type { PlayerState } from '../framework/platform/stores/types.ts'; + +const { ccclass } = _decorator; + +const PLAYER_A: PlayerState = { + playerid: 100, nickname: '甲', avatar: '', sex: 0, + bean: 0, roomcard: 0, score: 0, charm: 0, taskstate: 0, advanced: 0, + bankpower: 0, bank: 0, bankpwd: 0, ip: '', sign: null, tel: null, + invitecode: null, initCard: 0, initBean: 0, +} as any; + +const PLAYER_B: PlayerState = { + playerid: 200, nickname: '乙', avatar: '', sex: 0, + bean: 0, roomcard: 0, score: 0, charm: 0, taskstate: 0, advanced: 0, + bankpower: 0, bank: 0, bankpwd: 0, ip: '', sign: null, tel: null, + invitecode: null, initCard: 0, initBean: 0, +} as any; + +@ccclass('RoomEventProbe') +export class RoomEventProbe extends Component { + start(): void { + const bus = new EventBus(); + const session = new PlatformSession(bus); + + session.room.state.subscribe((room) => { + console.log('[RoomProbe] RoomStore changed:'); + console.log(' inRoom=' + room.inRoom + ' roomcode=' + room.roomcode); + console.log(' seat=' + room.seat + ' isowner=' + room.isowner); + console.log(' state=' + room.state + ' isbattle=' + room.isbattle); + console.log(' players.length=' + room.players.length); + for (let i = 0; i < room.players.length; i++) { + const p = room.players[i]; + console.log(' players[' + i + ']=' + (p ? 'playerid=' + p.playerid : 'null')); + } + }); + + const roomBus = new RoomRPCBus(bus, session); + roomBus.start(); + console.log('[RoomProbe] RoomRPCBus started'); + + this.scheduleOnce(() => { + // 0. 用 applyRecovery 设初始 4 玩家数组(seat 1 = 甲, seat 2 = 乙) + console.log('[RoomProbe] init: applyRecovery 4 玩家数组'); + session.room.applyRecovery({ + roomcode: 'R1', seat: 1, isowner: 1, isbattle: 0, state: 0, + players: [null, PLAYER_A, PLAYER_B, null] as any, + } as any); + + this.scheduleOnce(() => { + console.log('[RoomProbe] test 1: other_join_room (seat=3)'); + bus.emit('message', { route: 'room', rpc: 'other_join_room', data: { seat: 3, playerid: 300, nickname: '丙' } as any } as any); + + this.scheduleOnce(() => { + console.log('[RoomProbe] test 2: other_exit_room (seat=3)'); + bus.emit('message', { route: 'room', rpc: 'other_exit_room', data: { seat: 3 } as any } as any); + + this.scheduleOnce(() => { + console.log('[RoomProbe] test 3: self_apply_free_room'); + bus.emit('message', { route: 'room', rpc: 'self_apply_free_room', data: { applyer: 1 } as any } as any); + + this.scheduleOnce(() => { + console.log('[RoomProbe] test 4: free_room'); + bus.emit('message', { route: 'room', rpc: 'free_room', data: { result: 1 } as any } as any); + console.log('[RoomProbe] all 4 tests done'); + }, 0.2); + }, 0.2); + }, 0.2); + }, 0.2); + }, 0.1); + } +}