keytops-game-framework 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,13 @@ export * from "./social/SocialAnalyticsAble";
15
15
  export * from "./tutorial/TutorialAnalyticsAble";
16
16
  export * from "./pay/PayAnalyticsAble";
17
17
  export * from "./firebase/FirebaseAnalyticsSender";
18
+ /**
19
+ * 自定义统计能力构造器。
20
+ *
21
+ * 自定义能力通过构造参数复用 AnalyticsManager 的基础统计能力,
22
+ * 从而共享 Sender、公共属性、用户属性和调试配置。
23
+ */
24
+ export type AnalyticsAbilityConstructor<T> = new (baseAble: AnalyticsAble) => T;
18
25
  declare class AnalyticsManager {
19
26
  private hasRelayUrl;
20
27
  private hasAliDirectConfig;
@@ -59,6 +66,13 @@ declare class AnalyticsManager {
59
66
  * 支付漏斗统计能力
60
67
  */
61
68
  get pay(): PayAnalyticsAble;
69
+ private _abilityMap;
70
+ /**
71
+ * 获取由 AnalyticsManager 代管的自定义统计能力。
72
+ *
73
+ * 同一个构造器只会创建一个实例;自定义能力应通过构造参数接收基础统计能力。
74
+ */
75
+ getAbility<T>(abilityClass: AnalyticsAbilityConstructor<T>): T;
62
76
  /**
63
77
  * 启用统计(基础统计能力)
64
78
  * @param debugMode 调试模式,是否打印日志信息,默认为false
package/dist/index.js CHANGED
@@ -6734,6 +6734,7 @@ class AnalyticsManager {
6734
6734
  this._social = null;
6735
6735
  this._tutorial = null;
6736
6736
  this._pay = null;
6737
+ this._abilityMap = new Map();
6737
6738
  this._assignmentSender = null;
6738
6739
  }
6739
6740
  hasRelayUrl(config) {
@@ -6845,6 +6846,22 @@ class AnalyticsManager {
6845
6846
  }
6846
6847
  return this._pay;
6847
6848
  }
6849
+ /**
6850
+ * 获取由 AnalyticsManager 代管的自定义统计能力。
6851
+ *
6852
+ * 同一个构造器只会创建一个实例;自定义能力应通过构造参数接收基础统计能力。
6853
+ */
6854
+ getAbility(abilityClass) {
6855
+ if (!this.base.inited) {
6856
+ throw new Error("请先通过enable初始化基础统计能力");
6857
+ }
6858
+ let instance = this._abilityMap.get(abilityClass);
6859
+ if (!instance) {
6860
+ instance = new abilityClass(this.base);
6861
+ this._abilityMap.set(abilityClass, instance);
6862
+ }
6863
+ return instance;
6864
+ }
6848
6865
  /**
6849
6866
  * 启用统计(基础统计能力)
6850
6867
  * @param debugMode 调试模式,是否打印日志信息,默认为false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keytops-game-framework",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "cocos creator game framework library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",