feat(framework): config 身份类型 + 纯合并 resolveIdentity + 构建期默认
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/** 渠道身份(属性名沿用协议字段,序列化进 player_login,逐字不变)。 */
|
||||
export interface ChannelIdentity {
|
||||
agentid: string | number;
|
||||
channelid: string | number;
|
||||
gameid: string;
|
||||
marketid: string | number;
|
||||
version: string; // 旧 GameData.Version
|
||||
versionCode: number; // 旧 GameData.versionCode
|
||||
}
|
||||
|
||||
/** 身份来源:返回部分字段覆盖。 */
|
||||
export type IdentitySource = () => Partial<ChannelIdentity>;
|
||||
|
||||
function hasValue(v: unknown): boolean {
|
||||
return v !== undefined && v !== null && v !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 按数组顺序合并身份,后者覆盖前者(仅覆盖有效值字段)。
|
||||
* 约定首个 source 为完整 defaults,故返回视为完整 ChannelIdentity。
|
||||
*/
|
||||
export function resolveIdentity(sources: IdentitySource[]): ChannelIdentity {
|
||||
const out: Partial<ChannelIdentity> = {};
|
||||
for (const src of sources) {
|
||||
const part = src();
|
||||
for (const k of Object.keys(part) as (keyof ChannelIdentity)[]) {
|
||||
const v = part[k];
|
||||
if (hasValue(v)) (out as Record<string, unknown>)[k] = v;
|
||||
}
|
||||
}
|
||||
return out as ChannelIdentity;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { ChannelIdentity } from '../identity.ts';
|
||||
|
||||
/**
|
||||
* 构建期默认渠道身份(旧 version.js 等价物)。
|
||||
* gameid 每子游戏固定写死;agentid/channelid/marketid/version 为默认,运行期由 query/native/profile 覆盖。
|
||||
*/
|
||||
export const BUILD_IDENTITY: ChannelIdentity = {
|
||||
agentid: '00bA05haB0d9ZC0fwGD09Q2OA30insbQ',
|
||||
channelid: 'frdt0C1GG0t91P0McFo0rbA1he5yurbS',
|
||||
gameid: '8x4l0rGjf026f60c48h0mbUAhK5vV16f',
|
||||
marketid: 4,
|
||||
version: '1.1',
|
||||
versionCode: 10000,
|
||||
};
|
||||
Reference in New Issue
Block a user