feat: 集成Rust WASM渲染引擎与TypeScript ECS框架 (#228)
* feat: 集成Rust WASM渲染引擎与TypeScript ECS框架 * feat: 增强编辑器UI功能与跨平台支持 * fix: 修复CI测试和类型检查问题 * fix: 修复CI问题并提高测试覆盖率 * fix: 修复CI问题并提高测试覆盖率
This commit is contained in:
46
packages/platform-wechat/src/utils.ts
Normal file
46
packages/platform-wechat/src/utils.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 微信小游戏工具函数
|
||||
*/
|
||||
|
||||
/**
|
||||
* 获取微信全局对象
|
||||
*/
|
||||
export function getWx(): WechatMinigame.Wx {
|
||||
if (typeof wx === 'undefined') {
|
||||
throw new Error('当前环境不是微信小游戏环境');
|
||||
}
|
||||
return wx;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测当前是否为微信小游戏环境
|
||||
*/
|
||||
export function isWeChatMiniGame(): boolean {
|
||||
try {
|
||||
if (typeof wx === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
const wxObj = wx as WechatMinigame.Wx;
|
||||
return typeof wxObj.getWindowInfo === 'function' &&
|
||||
typeof wxObj.createCanvas === 'function' &&
|
||||
typeof wxObj.createImage === 'function';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将微信回调风格 API 转换为 Promise
|
||||
*/
|
||||
export function promisify<T>(
|
||||
fn: (options: any) => void,
|
||||
options: any = {}
|
||||
): Promise<T> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fn({
|
||||
...options,
|
||||
success: (res: T) => resolve(res),
|
||||
fail: (err: any) => reject(err)
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user