feat(config): unify startup mode and server selection

This commit is contained in:
2026-09-05 22:52:14 +08:00
parent 239af0aa39
commit facceeae9b
26 changed files with 204 additions and 240 deletions
@@ -9,20 +9,7 @@ import type { Transport } from '../framework/net/transport.ts';
const { ccclass } = _decorator;
/**
* LoginFlow: 登录场景编排器(真机版,接入 PlatformSession 真实流)。
*
* 调试期间:
* - mode='debug' + ?profile=local → 跳过远程配置,直连本地服务器
* - 真实 WebSocket 传输(用浏览器原生 WebSocket API)
*
* 流程:
* 1. 构造 EventBus + PlatformSession + NetClient(WebSocket transport)
* 2. bootstrap() 跳过远程,直接拿 local server='ws://127.0.0.1:3088'
* 3. NetClient.start() → 真 WS connect → server 回 player_login
* 4. PlatformSession 落 3 Store → app.phase=loggedIn
* 5. director.loadScene('MainMenu')
*/
/** 旧登录编排兼容入口;启动配置由 profiles.ts 统一提供。 */
class WSTransport implements Transport {
private onOpenCb?: () => void;
@@ -73,11 +60,9 @@ export class LoginFlow extends Component {
(async () => {
try {
// 调试模式 + ?profile=local → 跳过远程,直连本地 ws://127.0.0.1:3088
const result = await resolveBootstrap({
mode: 'debug',
win: window as any,
search: '?profile=local',
search: window.location.search,
fetcher: new HttpConfigFetcher(),
isNative: false,
});
@@ -86,11 +71,7 @@ export class LoginFlow extends Component {
console.log('[LoginFlow] bootstrap OK, servers=' + result.servers[0] + ' profile=' + result.profile.name);
} catch (e) {
console.warn('[LoginFlow] bootstrap failed: ' + (e as Error).message);
session.app.setIdentity({
agentid: 'A', channelid: 'C', gameid: 'G', marketid: 4, version: 10000,
});
session.app.setServers(['ws://127.0.0.1:3088']);
console.log('[LoginFlow] fallback to ws://127.0.0.1:3088');
return;
}
// 构造 NetClient + 真实 WS transport
@@ -66,7 +66,7 @@ export class LocalPlatformLogin extends Component {
const view = this.view;
const browser = window as unknown as NativeHost & { returnCitySN?: unknown };
this.host = createLocalLoginHost({
configOptions: { mode: 'debug', hostKind: 'h5', search: window.location.search,
configOptions: { hostKind: 'h5', search: window.location.search,
win: browser, fetcher: new HttpConfigFetcher() },
storage: window.localStorage, random: Math.random, now: Date.now,
sampleHost: () => ({ location: null,