@chiyou/minigame-framework 1.4.0 → 1.4.2

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.
@@ -1,4 +1,5 @@
1
1
  import { AbsPlatformAdapter } from './AbsPlatformAdapter';
2
+ import { LaunchCategory } from "../../Definition/AnalyticsDefinition";
2
3
  import { LogUtils } from '../../Utils/LogUtils';
3
4
  import { FwkErrorCode } from '../../Definition/FwkErrorDefinition';
4
5
  import { AuthorizeResult, GetSettingResult } from '../../Definition/PrivacyDefinition';
@@ -87,6 +88,15 @@ class WeiXinPlatformBusiness {
87
88
  export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
88
89
 
89
90
  static TAG: string = "PlatformAdapterWeiXin";
91
+ protected launchSceneCategoryMap: Map<LaunchCategory, Set<string>> = new Map([
92
+ [LaunchCategory.RecentUse, new Set(["1001", "1089", "1090", "1256", "1271"])],
93
+ [LaunchCategory.Desktop, new Set(["1023", "1113", "1114", "1223"])],
94
+ [LaunchCategory.Search, new Set(["1005", "1006", "1027", "1053", "1106", "1183"])],
95
+ [LaunchCategory.Chat, new Set(["1007", "1008", "1036", "1096"])],
96
+ [LaunchCategory.Share, new Set(["1044", "1073", "1074"])],
97
+ [LaunchCategory.Ad, new Set(["1045", "1046", "1067", "1084", "1095", "1200", "1201", "1228", "1232", "1238", "1274", "1295", "1387"])],
98
+ [LaunchCategory.Other, new Set([])],
99
+ ]);
90
100
 
91
101
  private portalGame: PortalGame = new PortalGame();
92
102
  private gameClub: GameClub = new GameClub();
@@ -503,18 +513,18 @@ export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
503
513
 
504
514
  public onGameColdStart(): void {
505
515
  this.coldStartOptions = null;
506
- this.coldStartScene = "";
516
+ this._coldStartScene = "";
507
517
 
508
518
  if (window["wx"] && window["wx"].getLaunchOptionsSync) {
509
519
  this.coldStartOptions = window["wx"].getLaunchOptionsSync();
510
520
  if (this.coldStartOptions !== null && this.coldStartOptions["scene"]) {
511
- this.coldStartScene = this.coldStartOptions["scene"].toString();
521
+ this._coldStartScene = this.coldStartOptions["scene"].toString();
512
522
  }
513
523
  }
514
524
 
515
525
  LogUtils.Instance.info(PlatformAdapterWeiXin.TAG, "冷启动场景更新", {
516
526
  operation: "updateColdStartScene",
517
- scene: this.coldStartScene
527
+ scene: this._coldStartScene
518
528
  });
519
529
  }
520
530
 
@@ -576,52 +586,8 @@ export class PlatformAdapterWeiXin extends AbsPlatformAdapter {
576
586
 
577
587
  }
578
588
 
579
- public isLaunchFromRecentUse(): boolean {
580
- let recentUseSceneSet: Set<string> = new Set<string>([
581
- "1001",
582
- "1089",
583
- "1256",
584
- "1103",
585
- "1104",
586
- "1257",
587
- ]);
588
-
589
- let isLaunchFromRecentUse: boolean = recentUseSceneSet.has(this.coldStartScene) || recentUseSceneSet.has(this.warmStartScene);
590
- LogUtils.Instance.info(PlatformAdapterWeiXin.TAG, "判断是否最近使用启动", {
591
- operation: "isLaunchFromRecentUse",
592
- result: isLaunchFromRecentUse
593
- });
594
- return isLaunchFromRecentUse;
595
- }
596
589
 
597
- public isLaunchFromDesktopShortcut(): boolean {
598
- let desktopShortcutSceneSet: Set<string> = new Set<string>([
599
- "1023",
600
- "1223",
601
- ]);
602
590
 
603
- let isLaunchFromDesktopShortcut: boolean = desktopShortcutSceneSet.has(this.coldStartScene) || desktopShortcutSceneSet.has(this.warmStartScene);
604
- LogUtils.Instance.info(PlatformAdapterWeiXin.TAG, "判断是否桌面快捷方式启动", {
605
- operation: "isLaunchFromDesktopShortcut",
606
- result: isLaunchFromDesktopShortcut
607
- });
608
- return isLaunchFromDesktopShortcut;
609
- }
610
-
611
- public isLaunchFromAdvertisement(): boolean {
612
- let advertisementSceneSet: Set<string> = new Set<string>([
613
- "1045", "1046", "1067", "1068", "1084", "1095",
614
- "1189", "1200", "1201", "1215", "1228", "1230",
615
- "1232", "1238", "1274", "1295",
616
- ]);
617
-
618
- let isLaunchFromAdvertisement: boolean = advertisementSceneSet.has(this.coldStartScene);
619
- LogUtils.Instance.info(PlatformAdapterWeiXin.TAG, "判断是否广告启动", {
620
- operation: "isLaunchFromAdvertisement",
621
- result: isLaunchFromAdvertisement
622
- });
623
- return isLaunchFromAdvertisement;
624
- }
625
591
 
626
592
  public checkSession(callback: (isValid: boolean) => void): void {
627
593
  if (window["wx"] && window["wx"].checkSession) {
@@ -1,4 +1,5 @@
1
1
  import { AbsPlatformAdapter } from './AbsPlatformAdapter';
2
+ import { LaunchCategory } from "../../Definition/AnalyticsDefinition";
2
3
  import { LogUtils } from '../../Utils/LogUtils';
3
4
  import { FwkErrorCode } from '../../Definition/FwkErrorDefinition';
4
5
  import { AuthorizeResult, GetSettingResult } from '../../Definition/PrivacyDefinition';
@@ -7,6 +8,15 @@ import { ScreenInfo } from '../../Definition/SystemDefinition';
7
8
  export class PlatformAdapterXiaoMi extends AbsPlatformAdapter {
8
9
 
9
10
  static TAG: string = "PlatformAdapterXiaoMi";
11
+ protected launchSceneCategoryMap: Map<LaunchCategory, Set<string>> = new Map([
12
+ [LaunchCategory.RecentUse, new Set([])],
13
+ [LaunchCategory.Desktop, new Set([])],
14
+ [LaunchCategory.Search, new Set([])],
15
+ [LaunchCategory.Chat, new Set([])],
16
+ [LaunchCategory.Share, new Set([])],
17
+ [LaunchCategory.Ad, new Set([])],
18
+ [LaunchCategory.Other, new Set([])],
19
+ ]);
10
20
 
11
21
  // Common
12
22
  public init(): void {
@@ -284,11 +294,11 @@ export class PlatformAdapterXiaoMi extends AbsPlatformAdapter {
284
294
 
285
295
  public onGameColdStart(): void {
286
296
  this.coldStartOptions = null;
287
- this.coldStartScene = "";
297
+ this._coldStartScene = "";
288
298
 
289
299
  LogUtils.Instance.info(PlatformAdapterXiaoMi.TAG, "冷启动场景更新", {
290
300
  operation: "updateColdStartScene",
291
- scene: this.coldStartScene
301
+ scene: this._coldStartScene
292
302
  });
293
303
  }
294
304
 
@@ -346,17 +356,8 @@ export class PlatformAdapterXiaoMi extends AbsPlatformAdapter {
346
356
 
347
357
  }
348
358
 
349
- public isLaunchFromRecentUse(): boolean {
350
- return false;
351
- }
352
359
 
353
- public isLaunchFromDesktopShortcut(): boolean {
354
- return false;
355
- }
356
360
 
357
- public isLaunchFromAdvertisement(): boolean {
358
- return false;
359
- }
360
361
 
361
362
  public checkSession(callback: (isValid: boolean) => void): void {
362
363
  // XiaoMi不支持这个方法,直接返回true
@@ -1,4 +1,5 @@
1
1
  import { AbsPlatformAdapter } from './AbsPlatformAdapter';
2
+ import { LaunchCategory } from "../../Definition/AnalyticsDefinition";
2
3
  import { LogUtils } from '../../Utils/LogUtils';
3
4
  import { FwkErrorCode } from '../../Definition/FwkErrorDefinition';
4
5
  import { AuthorizeResult, GetSettingResult } from '../../Definition/PrivacyDefinition';
@@ -7,6 +8,15 @@ import { ScreenInfo } from '../../Definition/SystemDefinition';
7
8
  export class PlatformAdapterZhiFuBao extends AbsPlatformAdapter {
8
9
 
9
10
  static TAG: string = "PlatformAdapterZhiFuBao";
11
+ protected launchSceneCategoryMap: Map<LaunchCategory, Set<string>> = new Map([
12
+ [LaunchCategory.RecentUse, new Set(["1000", "1001", "1002", "1003"])],
13
+ [LaunchCategory.Desktop, new Set(["1023"])],
14
+ [LaunchCategory.Search, new Set([])],
15
+ [LaunchCategory.Chat, new Set([])],
16
+ [LaunchCategory.Share, new Set([])],
17
+ [LaunchCategory.Ad, new Set(["1400"])],
18
+ [LaunchCategory.Other, new Set([])],
19
+ ]);
10
20
 
11
21
  // Common
12
22
  public init(): void {
@@ -314,18 +324,18 @@ export class PlatformAdapterZhiFuBao extends AbsPlatformAdapter {
314
324
 
315
325
  public onGameColdStart(): void {
316
326
  this.coldStartOptions = null;
317
- this.coldStartScene = "";
327
+ this._coldStartScene = "";
318
328
 
319
329
  if (window["my"] && window["my"].getLaunchOptionsSync) {
320
330
  this.coldStartOptions = window["my"].getLaunchOptionsSync();
321
331
  if (this.coldStartOptions !== null && this.coldStartOptions["scene"]) {
322
- this.coldStartScene = this.coldStartOptions["scene"];
332
+ this._coldStartScene = this.coldStartOptions["scene"];
323
333
  }
324
334
  }
325
335
 
326
336
  LogUtils.Instance.info(PlatformAdapterZhiFuBao.TAG, "冷启动场景更新", {
327
337
  operation: "updateColdStartScene",
328
- scene: this.coldStartScene
338
+ scene: this._coldStartScene
329
339
  });
330
340
  }
331
341
 
@@ -387,47 +397,8 @@ export class PlatformAdapterZhiFuBao extends AbsPlatformAdapter {
387
397
 
388
398
  }
389
399
 
390
- public isLaunchFromRecentUse(): boolean {
391
- let recentUseSceneSet: Set<string> = new Set<string>([
392
- "1000",
393
- "1001",
394
- "1002",
395
- "1003",
396
- ]);
397
400
 
398
- let isLaunchFromRecentUse: boolean = recentUseSceneSet.has(this.coldStartScene) || recentUseSceneSet.has(this.warmStartScene);
399
- LogUtils.Instance.info(PlatformAdapterZhiFuBao.TAG, "判断是否最近使用启动", {
400
- operation: "isLaunchFromRecentUse",
401
- result: isLaunchFromRecentUse
402
- });
403
- return isLaunchFromRecentUse;
404
- }
405
-
406
- public isLaunchFromDesktopShortcut(): boolean {
407
- let desktopShortcutSceneSet: Set<string> = new Set<string>([
408
- "1023",
409
- ]);
410
401
 
411
- let isLaunchFromDesktopShortcut: boolean = desktopShortcutSceneSet.has(this.coldStartScene) || desktopShortcutSceneSet.has(this.warmStartScene);
412
- LogUtils.Instance.info(PlatformAdapterZhiFuBao.TAG, "判断是否桌面快捷方式启动", {
413
- operation: "isLaunchFromDesktopShortcut",
414
- result: isLaunchFromDesktopShortcut
415
- });
416
- return isLaunchFromDesktopShortcut;
417
- }
418
-
419
- public isLaunchFromAdvertisement(): boolean {
420
- let advertisementSceneSet: Set<string> = new Set<string>([
421
- "1400",
422
- ]);
423
-
424
- let isLaunchFromAdvertisement: boolean = advertisementSceneSet.has(this.coldStartScene);
425
- LogUtils.Instance.info(PlatformAdapterZhiFuBao.TAG, "判断是否广告启动", {
426
- operation: "isLaunchFromAdvertisement",
427
- result: isLaunchFromAdvertisement
428
- });
429
- return isLaunchFromAdvertisement;
430
- }
431
402
 
432
403
  public checkSession(callback: (isValid: boolean) => void): void {
433
404
  // ZhiFuBao不支持这个方法,直接返回true
@@ -32,88 +32,14 @@ export interface UmengConfig {
32
32
 
33
33
  // ==================== SDK 类型声明 ====================
34
34
 
35
- /** 关卡结束事件类型 */
36
- export enum StageEventType {
37
- /** 关卡完成 */
38
- Complete = "complete",
39
- /** 关卡失败 */
40
- Fail = "fail",
41
- }
42
-
43
- /** 关卡中行为事件类型 */
44
- export enum StageRunningEventType {
45
- /** 使用道具 */
46
- Tools = "tools",
47
- /** 获得奖励 */
48
- Award = "award",
49
- }
50
-
51
- /** 关卡开始参数 */
52
- export interface StageStartParams {
53
- /** 关卡ID(必传,string类型) */
54
- stageId: string;
55
- /** 关卡名称(必传) */
56
- stageName: string;
57
- }
58
-
59
- /** 关卡结束参数 */
60
- export interface StageEndParams {
61
- /** 关卡ID(必传,string类型) */
62
- stageId: string;
63
- /** 关卡名称(必传) */
64
- stageName: string;
65
- /** 关卡结束结果(必传,complete/fail) */
66
- event: StageEventType;
67
- /** 关卡耗时(毫秒,可选) */
68
- _um_sdu?: number;
69
- }
70
-
71
- /** 关卡中行为事件参数 */
72
- export interface StageRunningParams {
73
- /** 关卡ID(必传,string类型) */
74
- stageId: string;
75
- /** 关卡名称(必传) */
76
- stageName: string;
77
- /** 事件类型(必传,tools/award) */
78
- event: StageRunningEventType;
79
- /** 事件参数 */
80
- params?: StageRunningItemParams;
81
- }
82
-
83
- /** 关卡中行为物品参数 */
84
- export interface StageRunningItemParams {
85
- /** 商品/道具名称(必传) */
86
- itemName: string;
87
- /** 商品/道具ID(可选) */
88
- itemId?: string;
89
- /** 商品/道具数量(可选) */
90
- itemCount?: number;
91
- /** 商品/道具单价(可选) */
92
- itemMoney?: number;
93
- /** 描述(可选) */
94
- desc?: string;
95
- }
96
-
97
- /** 友盟关卡 SDK 接口 */
98
- export interface UmaSDKStage {
99
- /** 关卡开始 */
100
- onStart(params: StageStartParams): void;
101
- /** 关卡结束 */
102
- onEnd(params: StageEndParams): void;
103
- /** 关卡中行为 */
104
- onRunning(params: StageRunningParams): void;
105
- }
106
-
107
35
  /**
108
36
  * 友盟 SDK 接口定义
109
37
  *
110
- * 仅包含实际可用的方法(共12个)
38
+ * 仅包含实际可用的方法(共11个)
111
39
  * 已移除:removeUserid, setUserInfo, setAnonymousid, setAppVersion, setSuperProperty(不可用)
112
40
  * 已移除:revenue, stage, level, rc(插件方法)
113
41
  *
114
42
  * 使用方式:SDK 在 game.js 中初始化后,通过 wx.uma 全局实例访问
115
- *
116
- * 关卡行为上报通过 wx.uma.stage 对象访问
117
43
  */
118
44
  export interface UmaSDK {
119
45
  /** 恢复会话(onShow 时调用) */
@@ -138,39 +64,113 @@ export interface UmaSDK {
138
64
  onShareAppMessage(callback: () => object): void;
139
65
  /** 调用分享 */
140
66
  shareAppMessage(options: object): void;
141
- /** 关卡行为上报(stage 对象) */
142
- stage: UmaSDKStage;
143
67
  }
144
68
 
145
- // ==================== 预定义事件 ID ====================
69
+ // ==================== 事件 ID 与参数 ====================
146
70
 
147
- /** 预定义事件 ID */
71
+ /** 事件 ID(按业务分类) */
148
72
  export enum AnalyticsEventId {
73
+ // ==================== 留存 ====================
74
+ /** 游戏启动(DAU / 留存基数) */
75
+ GameLaunch = "game_launch",
76
+
77
+ // ==================== 关卡 ====================
78
+ /** 关卡开始 */
79
+ StageStart = "stage_start",
80
+ /** 关卡结束(成功 / 失败 / 放弃) */
81
+ StageEnd = "stage_end",
82
+ /** 复活成功 */
83
+ StageRevive = "stage_revive",
84
+
85
+ // ==================== 广告 ====================
86
+ /** 广告加载成功 */
87
+ AdLoadSuccess = "ad_load_success",
88
+ /** 广告加载失败 */
89
+ AdLoadError = "ad_load_error",
90
+ /** 广告展示 */
149
91
  AdShow = "ad_show",
150
- AdClick = "ad_click",
151
- AdComplete = "ad_complete",
152
- AdSkip = "ad_skip",
153
- AdError = "ad_error",
154
- Purchase = "purchase",
92
+ /** 广告观看完成(isEnded=true) */
93
+ AdShowComplete = "ad_show_complete",
94
+ /** 广告跳过(isEnded=false) */
95
+ AdShowSkip = "ad_show_skip",
96
+ }
97
+
98
+ /** 关卡结束结果 */
99
+ export enum StageResult {
100
+ Success = "success",
101
+ Fail = "fail",
102
+ Abandon = "abandon",
103
+ }
104
+
105
+ /** 复活方式 */
106
+ export enum ReviveMethod {
107
+ /** 广告复活 */
108
+ Ad = "ad",
109
+ /** 道具复活 */
110
+ Item = "item",
111
+ }
112
+
113
+ /** 启动场景分类 */
114
+ export enum LaunchCategory {
115
+ /** 最近使用/我的小程序 */
116
+ RecentUse = "recent",
117
+ /** 桌面图标/快捷方式 */
118
+ Desktop = "desktop",
119
+ /** 搜索 */
120
+ Search = "search",
121
+ /** 聊天消息卡片 */
122
+ Chat = "chat",
123
+ /** 分享卡片 */
155
124
  Share = "share",
156
- Login = "login",
157
- GameLaunch = "game_launch",
158
- GameError = "game_error",
125
+ /** 广告 */
126
+ Ad = "ad",
127
+ /** 其他/未知 */
128
+ Other = "other",
159
129
  }
160
130
 
161
- /** 事件参数键名 */
131
+ /** 冷启动场景信息 */
132
+ export interface LaunchSceneInfo {
133
+ /** 原始场景值 */
134
+ scene: string;
135
+ /** 归并后的场景分类 */
136
+ category: LaunchCategory;
137
+ }
138
+
139
+ /** 事件参数键名(按业务分类) */
162
140
  export enum AnalyticsParamKey {
163
- Score = "score",
141
+ // ==================== 通用 ====================
142
+ /** 时长(毫秒),关卡耗时等通用场景 */
164
143
  Duration = "duration",
165
- Reason = "reason",
166
- AdType = "ad_type",
167
- AdId = "ad_id",
168
- ItemId = "item_id",
169
- ItemName = "item_name",
170
- Price = "price",
171
- Currency = "currency",
172
- ShareType = "share_type",
173
- ShareContent = "share_content",
174
- ErrorCode = "error_code",
175
- ErrorMsg = "error_msg",
144
+
145
+ // ==================== 留存 ====================
146
+ /** 原始启动场景值 */
147
+ LaunchScene = "launch_scene",
148
+ /** 归并后的场景分类 */
149
+ LaunchCategory = "launch_category",
150
+ /** 启动小时(0-23) */
151
+ LaunchHour = "launch_hour",
152
+
153
+ // ==================== 关卡 ====================
154
+ /** 关卡ID */
155
+ StageId = "stage_id",
156
+ /** 关卡名称 */
157
+ StageName = "stage_name",
158
+ /** 是否首次进入(1=首次, 0=重玩) */
159
+ IsFirst = "is_first",
160
+ /** 关卡结束结果(success / fail / abandon) */
161
+ Result = "result",
162
+ /** 关卡进度(0-1) */
163
+ Progress = "progress",
164
+ /** 是否复活后通关(1=是, 0=否) */
165
+ IsRevived = "is_revived",
166
+ /** 复活方式(ad / item) */
167
+ Method = "method",
168
+
169
+ // ==================== 广告 ====================
170
+ /** 广告场景(业务自定义,如 revive / daily_bonus) */
171
+ AdScene = "ad_scene",
172
+ /** 广告错误码 */
173
+ ErrCode = "err_code",
174
+ /** 广告错误信息 */
175
+ ErrMsg = "err_msg",
176
176
  }