/** Native ZIP cache is installed by the WeChat build extension; editor/web use Creator directly. */ export default class ActivityBundleLoader { private static runtime(): any { return typeof window !== "undefined" && (window as any).__activityBundles; } static beginCycle(): void { const runtime = this.runtime(); if (runtime) runtime.beginCycle(); } /** Reserve a coherent dependency set without downloading any bundle. */ static retainGroup(name: string): () => void { const runtime = this.runtime(); if (runtime) return runtime.retainGroup(name); if (cc.sys && cc.sys.platform === cc.sys.WECHAT_GAME) throw new Error("活动分包加载器未初始化,请重新构建小游戏"); return () => {}; } static prepareGroup(name: string): Promise { const runtime = this.runtime(); if (runtime) return runtime.prepareGroup(name); try { this.retainGroup(name)(); return Promise.resolve(); } catch (error) { return Promise.reject(error); } } static ensureBundle(name: string): Promise { const runtime = this.runtime(); if (runtime) return runtime.ensureBundle(name); if (cc.sys && cc.sys.platform === cc.sys.WECHAT_GAME) return Promise.reject(new Error("活动分包加载器未初始化,请重新构建小游戏")); return new Promise((resolve, reject) => cc.assetManager.loadBundle(name, (error, bundle) => error ? reject(error) : resolve(bundle))); } static async acquireBundle(name: string): Promise<{ bundle: cc.AssetManager.Bundle; release: () => void }> { const runtime = this.runtime(); return runtime ? runtime.acquireBundle(name) : { bundle: await this.ensureBundle(name), release: () => {} }; } }