You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
AdLike2048/assets/script/game/device-capability-standards.ts

73 lines
2.7 KiB

import type { DeviceQuality } from './DeviceCapability';
/**
* 平台官方性能分档阈值(与 DeviceCapability 对齐)。
*
* 微信小游戏(2026-03-04 现行标准)
* @see https://developers.weixin.qq.com/minigame/dev/guide/performance/perf-benchmarkLevel.html
* - Android:高档 >=30,中档 23–29,低档 <=22
* - iOS:高档 >=36,中档 30–35,低档 <=29
* - benchmarkLevel -1:性能未知,可结合 modelLevel / memorySize 兜底
* - 推荐 API:wx.getDeviceBenchmarkInfo(3.4.5+);getDeviceInfo.benchmarkLevel 已停更
*
* 抖音小游戏(tt.getSystemInfoSync.deviceScore.overall,满分 10)
* @see https://developer.open-douyin.com/docs/resource/zh-CN/mini-game/develop/api/foundation/system/system-information/tt-get-system-info-sync
* - 低端:(0, 7.30)
* - 中端:[7.30, 8.51)
* - 高端:[8.51, +∞)
*
* modelLevel(微信 getDeviceBenchmarkInfo,会随时间调整,仅作 benchmark 未知时辅助)
* - 1 高档,2 中档,3 低档,0 未知
*/
export type MiniGameOs = 'ios' | 'android' | 'unknown';
/** 微信 benchmarkLevel → 画质档(按 OS 选用官方区间) */
export function wechatBenchmarkToQuality(level: number, os: MiniGameOs): DeviceQuality | null {
if (level === 0 || level <= -2) return 'low';
if (level < 0) return null;
if (os === 'ios') {
if (level >= 36) return 'high';
if (level >= 30) return 'medium';
return 'low';
}
// Android 或未知 OS:默认 Android 大盘(微信 Android 用户占比更高)
if (level >= 30) return 'high';
if (level >= 23) return 'medium';
return 'low';
}
/** 微信 modelLevel → 画质档(benchmark 未知时) */
export function wechatModelLevelToQuality(modelLevel: number): DeviceQuality | null {
switch (modelLevel) {
case 1: return 'high';
case 2: return 'medium';
case 3: return 'low';
default: return null;
}
}
/** 抖音 deviceScore.overall → 画质档 */
export function douyinDeviceScoreToQuality(overall: number): DeviceQuality | null {
if (overall < 0 || !Number.isFinite(overall)) return null;
if (overall >= 8.51) return 'high';
if (overall >= 7.30) return 'medium';
if (overall > 0) return 'low';
return null;
}
/** Web deviceMemory(GB) */
export function webDeviceMemoryToQuality(gb: number, isMobile: boolean): DeviceQuality {
if (gb < 2) return 'low';
if (gb < 4) return isMobile ? 'medium' : 'high';
return 'high';
}
/** 物理内存 MB(微信 getDeviceInfo.memorySize 等) */
export function memoryMbToQuality(mb: number, isMobile: boolean): DeviceQuality {
const gb = mb / 1024;
if (gb < 2) return 'low';
if (gb < 4) return isMobile ? 'medium' : 'high';
return 'high';
}