From 231e9ee31c3d8d03b4a0a8c4a2a97e3fe32de1d2 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Sun, 28 Jun 2026 16:38:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(framework):=20config=20=E8=B0=83=E8=AF=95?= =?UTF-8?q?=20profiles=20+=20=3Fprofile=3D=20=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../assets/framework/config/profiles.ts | 29 +++++++++++++++++++ .../framework-tests/config/profiles.test.ts | 27 +++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 cocoscreator_projects/YouleNexus/assets/framework/config/profiles.ts create mode 100644 cocoscreator_projects/framework-tests/config/profiles.test.ts diff --git a/cocoscreator_projects/YouleNexus/assets/framework/config/profiles.ts b/cocoscreator_projects/YouleNexus/assets/framework/config/profiles.ts new file mode 100644 index 0000000..9f48200 --- /dev/null +++ b/cocoscreator_projects/YouleNexus/assets/framework/config/profiles.ts @@ -0,0 +1,29 @@ +import type { ChannelIdentity } from './identity.ts'; + +export interface DebugProfile { + name: string; + server?: string; // 显式 ws 调试服地址(给定则跳过远程抓取) + gameserver?: string; // 远程配置 txt URL(不含防缓存串) + identity?: Partial; // 调试用渠道身份覆盖 + isDebugger?: boolean; // 收发包日志开关(替代旧 Game_Config.Debugger.isDebugger) +} + +/** 正式 gameserver:原 00_SubGame_Config.js:11。 */ +export const DEFAULT_GAMESERVER = 'http://ylyxservice1.0791ts.cn/config/update_json.txt'; +/** 测试 gameserver:原 00_SubGame_Config.js:9 注释。 */ +const STAGING_GAMESERVER = 'http://testgame.youlehdyx.com/update_json/ceshi_json.txt'; + +export const PROFILES: Record = { + prod: { name: 'prod', gameserver: DEFAULT_GAMESERVER, isDebugger: false }, + staging: { name: 'staging', gameserver: STAGING_GAMESERVER, isDebugger: true }, + local: { name: 'local', server: 'ws://127.0.0.1:3088', isDebugger: true }, +}; + +/** 发布只需保持 'prod'。 */ +export const ACTIVE_PROFILE = 'prod'; + +/** 解析当前 profile:ACTIVE_PROFILE 为基线,?profile= 临时切换;未知名回退 ACTIVE_PROFILE。 */ +export function resolveActiveProfile(search: string): DebugProfile { + const name = new URLSearchParams(search).get('profile') || ACTIVE_PROFILE; + return PROFILES[name] ?? PROFILES[ACTIVE_PROFILE]; +} diff --git a/cocoscreator_projects/framework-tests/config/profiles.test.ts b/cocoscreator_projects/framework-tests/config/profiles.test.ts new file mode 100644 index 0000000..884f53c --- /dev/null +++ b/cocoscreator_projects/framework-tests/config/profiles.test.ts @@ -0,0 +1,27 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { resolveActiveProfile, PROFILES, ACTIVE_PROFILE } from '../../YouleNexus/assets/framework/config/profiles.ts'; + +test('默认返回 ACTIVE_PROFILE', () => { + const p = resolveActiveProfile(''); + assert.equal(p.name, ACTIVE_PROFILE); +}); + +test('prod profile 无调试覆盖、isDebugger=false', () => { + const prod = PROFILES['prod']; + assert.equal(prod.isDebugger, false); + assert.equal(prod.server, undefined); + assert.equal(prod.identity, undefined); + assert.ok(prod.gameserver && prod.gameserver.length > 0); +}); + +test('?profile=local 切到 local,含调试服地址', () => { + const p = resolveActiveProfile('?profile=local'); + assert.equal(p.name, 'local'); + assert.ok(p.server && p.server.startsWith('ws://')); +}); + +test('未知 profile 回退到 ACTIVE_PROFILE', () => { + const p = resolveActiveProfile('?profile=nope'); + assert.equal(p.name, ACTIVE_PROFILE); +});