@chiyou/minigame-framework 1.0.0

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.
Files changed (114) hide show
  1. package/README.md +66 -0
  2. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.d.ts +78 -0
  3. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.js +230 -0
  4. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.d.ts +31 -0
  5. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.js +224 -0
  6. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.d.ts +34 -0
  7. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.js +524 -0
  8. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.d.ts +34 -0
  9. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.js +631 -0
  10. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.d.ts +33 -0
  11. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.js +460 -0
  12. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.d.ts +31 -0
  13. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.js +227 -0
  14. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.d.ts +33 -0
  15. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.js +458 -0
  16. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.d.ts +35 -0
  17. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.js +770 -0
  18. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.d.ts +33 -0
  19. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.js +519 -0
  20. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.d.ts +33 -0
  21. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.js +492 -0
  22. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.d.ts +33 -0
  23. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.js +695 -0
  24. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.d.ts +34 -0
  25. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.js +597 -0
  26. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.d.ts +33 -0
  27. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.js +458 -0
  28. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.d.ts +51 -0
  29. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.js +17 -0
  30. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.d.ts +45 -0
  31. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.js +555 -0
  32. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.d.ts +44 -0
  33. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.js +148 -0
  34. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.d.ts +48 -0
  35. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.js +715 -0
  36. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.d.ts +44 -0
  37. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.js +296 -0
  38. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.d.ts +45 -0
  39. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.js +284 -0
  40. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.d.ts +44 -0
  41. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.js +283 -0
  42. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.d.ts +43 -0
  43. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.js +406 -0
  44. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.d.ts +43 -0
  45. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.js +248 -0
  46. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.d.ts +44 -0
  47. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.js +517 -0
  48. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.d.ts +44 -0
  49. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.js +295 -0
  50. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.d.ts +55 -0
  51. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.js +964 -0
  52. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.d.ts +44 -0
  53. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.js +295 -0
  54. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.d.ts +44 -0
  55. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.js +393 -0
  56. package/dist/Framework/Definition/AdDefinition.d.ts +130 -0
  57. package/dist/Framework/Definition/AdDefinition.js +208 -0
  58. package/dist/Framework/Definition/FrameworkBase.d.ts +13 -0
  59. package/dist/Framework/Definition/FrameworkBase.js +23 -0
  60. package/dist/Framework/Definition/PrivacyDefinition.d.ts +51 -0
  61. package/dist/Framework/Definition/PrivacyDefinition.js +70 -0
  62. package/dist/Framework/Definition/SocialDefinition.d.ts +16 -0
  63. package/dist/Framework/Definition/SocialDefinition.js +2 -0
  64. package/dist/Framework/Definition/SystemDefinition.d.ts +43 -0
  65. package/dist/Framework/Definition/SystemDefinition.js +28 -0
  66. package/dist/Framework/Definition/UIDefinition.d.ts +6 -0
  67. package/dist/Framework/Definition/UIDefinition.js +7 -0
  68. package/dist/Framework/Definition/UserDefinition.d.ts +14 -0
  69. package/dist/Framework/Definition/UserDefinition.js +10 -0
  70. package/dist/Framework/Manager/AdMgr.d.ts +57 -0
  71. package/dist/Framework/Manager/AdMgr.js +684 -0
  72. package/dist/Framework/Manager/AudioMgr.d.ts +28 -0
  73. package/dist/Framework/Manager/AudioMgr.js +265 -0
  74. package/dist/Framework/Manager/BaseMgr.d.ts +18 -0
  75. package/dist/Framework/Manager/BaseMgr.js +114 -0
  76. package/dist/Framework/Manager/EventMgr.d.ts +18 -0
  77. package/dist/Framework/Manager/EventMgr.js +90 -0
  78. package/dist/Framework/Manager/ExcelMgr.d.ts +24 -0
  79. package/dist/Framework/Manager/ExcelMgr.js +156 -0
  80. package/dist/Framework/Manager/LifeCycleMgr.d.ts +20 -0
  81. package/dist/Framework/Manager/LifeCycleMgr.js +110 -0
  82. package/dist/Framework/Manager/NodePoolMgr.d.ts +53 -0
  83. package/dist/Framework/Manager/NodePoolMgr.js +279 -0
  84. package/dist/Framework/Manager/PrivacyMgr.d.ts +15 -0
  85. package/dist/Framework/Manager/PrivacyMgr.js +176 -0
  86. package/dist/Framework/Manager/ResMgr.d.ts +49 -0
  87. package/dist/Framework/Manager/ResMgr.js +337 -0
  88. package/dist/Framework/Manager/SocialMgr.d.ts +23 -0
  89. package/dist/Framework/Manager/SocialMgr.js +220 -0
  90. package/dist/Framework/Manager/SystemMgr.d.ts +24 -0
  91. package/dist/Framework/Manager/SystemMgr.js +222 -0
  92. package/dist/Framework/Manager/TimerMgr.d.ts +11 -0
  93. package/dist/Framework/Manager/TimerMgr.js +63 -0
  94. package/dist/Framework/Manager/UIMgr.d.ts +33 -0
  95. package/dist/Framework/Manager/UIMgr.js +223 -0
  96. package/dist/Framework/Manager/UserMgr.d.ts +15 -0
  97. package/dist/Framework/Manager/UserMgr.js +148 -0
  98. package/dist/Framework/Utils/BezierUtils.d.ts +49 -0
  99. package/dist/Framework/Utils/BezierUtils.js +247 -0
  100. package/dist/Framework/Utils/CSVUtils.d.ts +35 -0
  101. package/dist/Framework/Utils/CSVUtils.js +341 -0
  102. package/dist/Framework/Utils/LogUtils.d.ts +7 -0
  103. package/dist/Framework/Utils/LogUtils.js +32 -0
  104. package/dist/Framework/Utils/NumberUtils.d.ts +16 -0
  105. package/dist/Framework/Utils/NumberUtils.js +44 -0
  106. package/dist/Framework/Utils/TaskUtils.d.ts +10 -0
  107. package/dist/Framework/Utils/TaskUtils.js +24 -0
  108. package/dist/Framework/Utils/TimeUtils.d.ts +19 -0
  109. package/dist/Framework/Utils/TimeUtils.js +33 -0
  110. package/dist/Framework/Utils/WXBizDataCryptUtils.d.ts +12 -0
  111. package/dist/Framework/Utils/WXBizDataCryptUtils.js +37 -0
  112. package/dist/index.d.ts +30 -0
  113. package/dist/index.js +35 -0
  114. package/package.json +40 -0
@@ -0,0 +1,176 @@
1
+ import { LogUtils } from '../Utils/LogUtils';
2
+ import { AuthorizeResult, GetSettingResult, KindReminderType, PrivacyDefinition, PrivacyType, QueryPrivacyResult } from '../Definition/PrivacyDefinition';
3
+ import { UIMgr } from './UIMgr';
4
+ import { ToastDuration } from '../Definition/UIDefinition';
5
+ import { BaseMgr } from './BaseMgr';
6
+ import { FrameworkBase } from '../Definition/FrameworkBase';
7
+ export class PrivacyMgr extends BaseMgr {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.kindReminder = null;
11
+ this.kindReminderAgreeVersion = "";
12
+ }
13
+ onLoad() {
14
+ super.onLoad();
15
+ if (PrivacyMgr.Instance === null) {
16
+ PrivacyMgr.Instance = this;
17
+ }
18
+ else {
19
+ this.destroy();
20
+ return;
21
+ }
22
+ }
23
+ init(kindReminder) {
24
+ this.kindReminder = kindReminder;
25
+ let aggreeVersion = localStorage.getItem(FrameworkBase.LocalStorage.Key_PrivacyManager_KindReminder_AgreeVersion);
26
+ let aggreeVersionOld = localStorage.getItem(FrameworkBase.LocalStorage.Key_KindReminder_AgreeVersion);
27
+ if (aggreeVersion !== null && aggreeVersion !== "") {
28
+ this.kindReminderAgreeVersion = aggreeVersion;
29
+ }
30
+ else if (aggreeVersionOld !== null && aggreeVersionOld !== "") {
31
+ this.kindReminderAgreeVersion = aggreeVersionOld;
32
+ localStorage.setItem(FrameworkBase.LocalStorage.Key_PrivacyManager_KindReminder_AgreeVersion, this.kindReminderAgreeVersion);
33
+ localStorage.removeItem(FrameworkBase.LocalStorage.Key_KindReminder_AgreeVersion);
34
+ }
35
+ else {
36
+ this.kindReminderAgreeVersion = "";
37
+ localStorage.setItem(FrameworkBase.LocalStorage.Key_PrivacyManager_KindReminder_AgreeVersion, this.kindReminderAgreeVersion);
38
+ }
39
+ LogUtils.Instance.log(PrivacyMgr.TAG, "init() finished.");
40
+ }
41
+ shouldShowKindReminderOnLaunch() {
42
+ let currentPlatformID = this.getCurrentPlatformID();
43
+ if (!this.kindReminder.shouldShowPlatform.has(currentPlatformID)) {
44
+ return false;
45
+ }
46
+ if (this.kindReminder.latestVersion !== this.kindReminderAgreeVersion) {
47
+ return true;
48
+ }
49
+ return false;
50
+ }
51
+ shouldShowKindReminder() {
52
+ let currentPlatformID = this.getCurrentPlatformID();
53
+ if (!this.kindReminder.shouldShowPlatform.has(currentPlatformID)) {
54
+ return false;
55
+ }
56
+ return true;
57
+ }
58
+ getKindReminderContent(type) {
59
+ let currentPlatformID = this.getCurrentPlatformID();
60
+ let content = [];
61
+ if (type === KindReminderType.Type_UserAgreement) {
62
+ content = this.kindReminder.userAgreement.mainContent;
63
+ if (this.kindReminder.userAgreement.supplementaryContent !== null &&
64
+ this.kindReminder.userAgreement.supplementaryContent.has(currentPlatformID)) {
65
+ content = content.concat(this.kindReminder.userAgreement.supplementaryContent.get(currentPlatformID));
66
+ }
67
+ }
68
+ else if (type === KindReminderType.Type_PrivacyPolicy) {
69
+ content = this.kindReminder.privacyPolicy.mainContent;
70
+ if (this.kindReminder.privacyPolicy.supplementaryContent !== null &&
71
+ this.kindReminder.privacyPolicy.supplementaryContent.has(currentPlatformID)) {
72
+ content = content.concat(this.kindReminder.privacyPolicy.supplementaryContent.get(currentPlatformID));
73
+ }
74
+ }
75
+ let resultStr = "";
76
+ for (let i = 1; i <= content.length; i++) {
77
+ let paragraph = content[i - 1];
78
+ for (let j = 1; j <= paragraph.length; j++) {
79
+ resultStr += paragraph[j - 1] + "\n";
80
+ }
81
+ resultStr += "\n";
82
+ }
83
+ return resultStr;
84
+ }
85
+ setKindReminderAgreed() {
86
+ this.kindReminderAgreeVersion = this.kindReminder.latestVersion;
87
+ localStorage.setItem(FrameworkBase.LocalStorage.Key_PrivacyManager_KindReminder_AgreeVersion, this.kindReminderAgreeVersion);
88
+ }
89
+ queryPrivacyAvailable(featureName, privacyType, callback) {
90
+ LogUtils.Instance.log(PrivacyMgr.TAG, "checkPrivacyAvailable");
91
+ LogUtils.Instance.log("", "featureName=" + featureName + ",privacyType=" + PrivacyType[privacyType]);
92
+ if (callback === null) {
93
+ return;
94
+ }
95
+ if (this.getPlatformAdapter() === null) {
96
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_Invalid]);
97
+ callback(QueryPrivacyResult.Result_Invalid);
98
+ return;
99
+ }
100
+ let privacyInfo = PrivacyDefinition.PrivacyConfig.get(privacyType);
101
+ if (privacyInfo === null) {
102
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_Invalid]);
103
+ callback(QueryPrivacyResult.Result_Invalid);
104
+ return;
105
+ }
106
+ this.getPlatformAdapter().requirePrivacyAuthorize((result) => {
107
+ if (!result) {
108
+ UIMgr.Instance.showToast("未同意隐私协议,无法使用" + featureName);
109
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_PrivacyReject]);
110
+ callback(QueryPrivacyResult.Result_PrivacyReject);
111
+ return;
112
+ }
113
+ let privacyPlatformInfo = privacyInfo.privacyPlatformMap.get(this.getCurrentPlatformID());
114
+ let scopeDescription = privacyPlatformInfo.scopeDescription;
115
+ if (privacyPlatformInfo === null || privacyPlatformInfo.scopeDisable) {
116
+ UIMgr.Instance.showToast("不支持[" + scopeDescription + "],无法使用" + featureName);
117
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_ScopeDisable]);
118
+ callback(QueryPrivacyResult.Result_ScopeDisable);
119
+ return;
120
+ }
121
+ if (!privacyPlatformInfo.needAuthorize) {
122
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_Agree]);
123
+ callback(QueryPrivacyResult.Result_Agree);
124
+ return;
125
+ }
126
+ let scopeName = privacyPlatformInfo.scopeName;
127
+ this.getPlatformAdapter().getSetting(scopeName, (result) => {
128
+ if (result === GetSettingResult.Result_SettingNotAvailable) {
129
+ UIMgr.Instance.showToast("App版本过低,无法使用" + featureName, ToastDuration.Duration_Long);
130
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_Invalid]);
131
+ callback(QueryPrivacyResult.Result_Invalid);
132
+ return;
133
+ }
134
+ else if (result === GetSettingResult.Result_Rejected) {
135
+ UIMgr.Instance.showToast("右上角...设置,开启[" + scopeDescription + "]权限,即可使用" + featureName, ToastDuration.Duration_Long);
136
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_AuthorizeReject]);
137
+ callback(QueryPrivacyResult.Result_AuthorizeReject);
138
+ return;
139
+ }
140
+ else if (result === GetSettingResult.Result_NotExist_AuthorizeAvailable) {
141
+ this.getPlatformAdapter().authorize(scopeName, (result3) => {
142
+ if (result3 === AuthorizeResult.Result_AuthorizeNotAvailable) {
143
+ UIMgr.Instance.showToast("App版本过低,无法使用" + featureName, ToastDuration.Duration_Long);
144
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_Invalid]);
145
+ callback(QueryPrivacyResult.Result_Invalid);
146
+ return;
147
+ }
148
+ else if (result3 === AuthorizeResult.Result_Rejected) {
149
+ UIMgr.Instance.showToast("右上角...设置,开启[" + scopeDescription + "]权限,即可使用" + featureName, ToastDuration.Duration_Long);
150
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_AuthorizeReject]);
151
+ callback(QueryPrivacyResult.Result_AuthorizeReject);
152
+ return;
153
+ }
154
+ else if (result3 === AuthorizeResult.Result_Authorized) {
155
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_Agree]);
156
+ callback(QueryPrivacyResult.Result_Agree);
157
+ return;
158
+ }
159
+ });
160
+ }
161
+ else if (result === GetSettingResult.Result_Authorized) {
162
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_Agree]);
163
+ callback(QueryPrivacyResult.Result_Agree);
164
+ return;
165
+ }
166
+ else if (result === GetSettingResult.Result_NotExist_AuthorizeNotAvailable) {
167
+ LogUtils.Instance.log("", QueryPrivacyResult[QueryPrivacyResult.Result_Continue]);
168
+ callback(QueryPrivacyResult.Result_Continue);
169
+ return;
170
+ }
171
+ });
172
+ });
173
+ }
174
+ }
175
+ PrivacyMgr.Instance = null;
176
+ PrivacyMgr.TAG = "PrivacyMgr";
@@ -0,0 +1,49 @@
1
+ import { Asset } from 'cc';
2
+ import { BaseMgr } from './BaseMgr';
3
+ export type ResBatch = string;
4
+ export interface ResBundleConfig {
5
+ assetType: typeof Asset;
6
+ resBatchUrlsMap: Map<ResBatch, string[]>;
7
+ }
8
+ export declare class ResBundleInfo {
9
+ assetType: typeof Asset;
10
+ isBundleLoaded: boolean;
11
+ constructor(assetType: typeof Asset);
12
+ }
13
+ export declare class ResLoadInfo {
14
+ totalResCount: number;
15
+ loadedResCount: number;
16
+ constructor();
17
+ }
18
+ export declare class ResBatchInfo {
19
+ isBatchLoaded: boolean;
20
+ bundleLoadInfo: Map<string, ResLoadInfo>;
21
+ constructor();
22
+ }
23
+ export declare class ResMgr extends BaseMgr {
24
+ static Instance: ResMgr;
25
+ static TAG: string;
26
+ private resBundleConfig;
27
+ private resBatchSet;
28
+ private resBundleInfoMap;
29
+ private resBatchInfoMap;
30
+ private abBundsMap;
31
+ private loadInProgressFunc;
32
+ private loadEndFunc;
33
+ private totalResCount;
34
+ private nowLoadedResCount;
35
+ onLoad(): void;
36
+ init(resBundleConfig: Map<string, ResBundleConfig>): void;
37
+ private _printInfo;
38
+ private _initResBundleInfo;
39
+ private _initResBatchInfo;
40
+ preloadResBatch(resBatchList: ResBatch[], loadInProgressFunc: (loadedResCount: number, totalResCount: number) => void, loadEndFunc: () => void): void;
41
+ private _preloadAssetsBundle;
42
+ private _preloadAssetInAssetBundle;
43
+ private _preloadAsset;
44
+ getAsset<T extends Asset>(bundleName: string, url: string, assetType?: typeof Asset): T | null;
45
+ getBundleResCount(bundleName: string, path: string, assetType: typeof Asset): number;
46
+ loadRes(bundleName: string, url: string, assetType: typeof Asset, callback: Function): void;
47
+ private _loadRes;
48
+ loadRemoteImage(imageUrl: string, fileSuffix: string, callback: Function): void;
49
+ }
@@ -0,0 +1,337 @@
1
+ import { assetManager } from 'cc';
2
+ import { LogUtils } from '../Utils/LogUtils';
3
+ import { BaseMgr } from './BaseMgr';
4
+ export class ResBundleInfo {
5
+ constructor(assetType) {
6
+ this.assetType = assetType;
7
+ this.isBundleLoaded = false;
8
+ }
9
+ }
10
+ export class ResLoadInfo {
11
+ constructor() {
12
+ this.totalResCount = 0;
13
+ this.loadedResCount = 0;
14
+ }
15
+ }
16
+ export class ResBatchInfo {
17
+ constructor() {
18
+ this.bundleLoadInfo = null;
19
+ this.isBatchLoaded = false;
20
+ this.bundleLoadInfo = new Map();
21
+ }
22
+ }
23
+ export class ResMgr extends BaseMgr {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.resBundleConfig = new Map();
27
+ this.resBatchSet = new Set();
28
+ this.resBundleInfoMap = new Map();
29
+ this.resBatchInfoMap = new Map();
30
+ this.abBundsMap = new Map();
31
+ this.totalResCount = 0;
32
+ this.nowLoadedResCount = 0;
33
+ }
34
+ onLoad() {
35
+ super.onLoad();
36
+ if (ResMgr.Instance === null) {
37
+ ResMgr.Instance = this;
38
+ }
39
+ else {
40
+ this.destroy();
41
+ return;
42
+ }
43
+ }
44
+ init(resBundleConfig) {
45
+ this.resBundleConfig = resBundleConfig;
46
+ this._initResBundleInfo();
47
+ this._initResBatchInfo();
48
+ // this._printInfo();
49
+ LogUtils.Instance.log(ResMgr.TAG, "init() finished.");
50
+ }
51
+ _printInfo() {
52
+ LogUtils.Instance.log("", "resBundleInfoMap", this.resBundleInfoMap);
53
+ LogUtils.Instance.log("", "resBatchInfoMap", this.resBatchInfoMap);
54
+ }
55
+ _initResBundleInfo() {
56
+ this.resBundleInfoMap.clear();
57
+ this.resBundleConfig.forEach((resBundleConfig, bundleName) => {
58
+ let assetType = resBundleConfig.assetType;
59
+ let resBundleInfo = new ResBundleInfo(assetType);
60
+ this.resBundleInfoMap.set(bundleName, resBundleInfo);
61
+ });
62
+ }
63
+ _initResBatchInfo() {
64
+ this.resBatchSet.clear();
65
+ this.resBundleConfig.forEach((resBundleConfig, bundleName) => {
66
+ let resBatchUrlsMap = resBundleConfig.resBatchUrlsMap;
67
+ resBatchUrlsMap.forEach((resUrls, resBatch) => {
68
+ if (!this.resBatchSet.has(resBatch)) {
69
+ this.resBatchSet.add(resBatch);
70
+ }
71
+ });
72
+ });
73
+ this.resBatchInfoMap.clear();
74
+ this.resBatchSet.forEach((resBatch) => {
75
+ let resBatchInfo = new ResBatchInfo();
76
+ let totalResCount = 0;
77
+ this.resBundleConfig.forEach((resBundleConfig, bundleName) => {
78
+ let resBatchUrlsMap = resBundleConfig.resBatchUrlsMap;
79
+ if (resBatchUrlsMap.has(resBatch) && resBatchUrlsMap.get(resBatch) !== null) {
80
+ let resUrls = resBatchUrlsMap.get(resBatch);
81
+ totalResCount += resUrls.length;
82
+ let bundleLoadInfo = new ResLoadInfo();
83
+ bundleLoadInfo.totalResCount = resUrls.length;
84
+ resBatchInfo.bundleLoadInfo.set(bundleName, bundleLoadInfo);
85
+ }
86
+ });
87
+ this.resBatchInfoMap.set(resBatch, resBatchInfo);
88
+ });
89
+ }
90
+ preloadResBatch(resBatchList, loadInProgressFunc, loadEndFunc) {
91
+ if (loadInProgressFunc === null || loadEndFunc === null) {
92
+ return;
93
+ }
94
+ this.loadInProgressFunc = loadInProgressFunc;
95
+ this.loadEndFunc = loadEndFunc;
96
+ LogUtils.Instance.log(ResMgr.TAG, "preloadResBatch resBatchList = " + resBatchList);
97
+ let resBatchListToLoad = [];
98
+ for (let index = 0; index < resBatchList.length; index++) {
99
+ let resBatch = resBatchList[index];
100
+ let resBatchInfo = this.resBatchInfoMap.get(resBatch);
101
+ if (resBatchInfo === null) {
102
+ LogUtils.Instance.log(ResMgr.TAG, "preloadResBatch [fail] resBatchInfo is null.");
103
+ return;
104
+ }
105
+ if (!resBatchInfo.isBatchLoaded) {
106
+ resBatchListToLoad.push(resBatch);
107
+ }
108
+ }
109
+ if (resBatchListToLoad.length === 0) {
110
+ LogUtils.Instance.log(ResMgr.TAG, "preloadResBatch [success] all resBatch already loaded.");
111
+ this.loadEndFunc();
112
+ return;
113
+ }
114
+ let totalBundleCount = this.resBundleInfoMap.size;
115
+ let loadedBundleCount = 0;
116
+ let keys = this.resBundleInfoMap.keys();
117
+ let resultKey = keys.next();
118
+ while (resultKey.done === false) {
119
+ let resBundleInfo = this.resBundleInfoMap.get(resultKey.value);
120
+ if (resBundleInfo === null) {
121
+ LogUtils.Instance.log(ResMgr.TAG, "preloadResBatch [fail] resBundleInfo is null.");
122
+ return;
123
+ }
124
+ if (!resBundleInfo.isBundleLoaded) {
125
+ this._preloadAssetsBundle(resultKey.value, (isSuccess) => {
126
+ if (isSuccess) {
127
+ loadedBundleCount++;
128
+ }
129
+ if (loadedBundleCount === totalBundleCount) {
130
+ this._preloadAssetInAssetBundle(resBatchListToLoad);
131
+ }
132
+ });
133
+ }
134
+ else {
135
+ loadedBundleCount++;
136
+ if (loadedBundleCount === totalBundleCount) {
137
+ this._preloadAssetInAssetBundle(resBatchListToLoad);
138
+ }
139
+ }
140
+ resultKey = keys.next();
141
+ }
142
+ }
143
+ _preloadAssetsBundle(bundleName, endFunc) {
144
+ if (endFunc === null) {
145
+ return;
146
+ }
147
+ let resBundleInfo = this.resBundleInfoMap.get(bundleName);
148
+ if (resBundleInfo === null) {
149
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAssetsBundle() : bundleName = " + bundleName + " [fail] resBundleInfo is null.");
150
+ endFunc(false);
151
+ return;
152
+ }
153
+ if (resBundleInfo.isBundleLoaded) {
154
+ if (this.abBundsMap.has(bundleName)) {
155
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAssetsBundle() : bundleName = " + bundleName + " [success] bundle already loaded.");
156
+ endFunc(true);
157
+ return;
158
+ }
159
+ else {
160
+ resBundleInfo.isBundleLoaded = false;
161
+ this.resBundleInfoMap.set(bundleName, resBundleInfo);
162
+ }
163
+ }
164
+ else {
165
+ if (this.abBundsMap.has(bundleName)) {
166
+ this.abBundsMap.delete(bundleName);
167
+ }
168
+ }
169
+ assetManager.loadBundle(bundleName, (err, bundle) => {
170
+ if (err !== null) {
171
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAssetsBundle() : bundleName = " + bundleName + " [fail] load bundle failed." + err);
172
+ endFunc(false);
173
+ return;
174
+ }
175
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAssetsBundle() : bundleName = " + bundleName + " [success] load bundle succeed.");
176
+ this.abBundsMap.set(bundleName, bundle);
177
+ resBundleInfo.isBundleLoaded = true;
178
+ this.resBundleInfoMap.set(bundleName, resBundleInfo);
179
+ endFunc(true);
180
+ });
181
+ }
182
+ _preloadAssetInAssetBundle(resBatchListToLoad) {
183
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAssetInAssetBundle() resBatchListToLoad = " + resBatchListToLoad);
184
+ this.totalResCount = 0;
185
+ for (let index = 0; index < resBatchListToLoad.length; index++) {
186
+ let resBatch = resBatchListToLoad[index];
187
+ let resBatchInfo = this.resBatchInfoMap.get(resBatch);
188
+ if (resBatchInfo === null) {
189
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAssetInAssetBundle() [fail] resBatchInfo is null.");
190
+ return;
191
+ }
192
+ if (resBatchInfo.isBatchLoaded) {
193
+ continue;
194
+ }
195
+ resBatchInfo.bundleLoadInfo.forEach((bundleLoadInfo, bundleName) => {
196
+ this.totalResCount += bundleLoadInfo.totalResCount;
197
+ });
198
+ }
199
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAssetInAssetBundle() totalResCount = " + this.totalResCount);
200
+ this.nowLoadedResCount = 0;
201
+ for (let index = 0; index < resBatchListToLoad.length; index++) {
202
+ let resBatch = resBatchListToLoad[index];
203
+ this.resBundleConfig.forEach((resBundleConfig, bundleName) => {
204
+ if (resBundleConfig.resBatchUrlsMap.has(resBatch) &&
205
+ resBundleConfig.resBatchUrlsMap.get(resBatch) !== null) {
206
+ let resBatchInfo = this.resBatchInfoMap.get(resBatch);
207
+ let resUrlList = resBundleConfig.resBatchUrlsMap.get(resBatch);
208
+ for (let index = 0; index < resUrlList.length; index++) {
209
+ let resUrl = resUrlList[index];
210
+ if (!this.abBundsMap.has(bundleName) || this.abBundsMap.get(bundleName) === null) {
211
+ continue;
212
+ }
213
+ let adBundle = this.abBundsMap.get(bundleName);
214
+ let bundleLoadInfo = resBatchInfo.bundleLoadInfo.get(bundleName);
215
+ this._preloadAsset(adBundle, resUrl, resBundleConfig.assetType, (isSuccess, error) => {
216
+ if (isSuccess) {
217
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAsset() bundleName = " + bundleName + ", resUrl = " + resUrl + " [success]");
218
+ this.nowLoadedResCount++;
219
+ bundleLoadInfo.loadedResCount++;
220
+ resBatchInfo.bundleLoadInfo.set(bundleName, bundleLoadInfo);
221
+ }
222
+ else {
223
+ LogUtils.Instance.log(ResMgr.TAG, "_preloadAsset() bundleName = " + bundleName + ", resUrl = " + resUrl + ", [fail] " + error);
224
+ }
225
+ if (this.loadInProgressFunc) {
226
+ this.loadInProgressFunc(this.nowLoadedResCount, this.totalResCount);
227
+ }
228
+ if (this.nowLoadedResCount === this.totalResCount) {
229
+ for (let index = 0; index < resBatchListToLoad.length; index++) {
230
+ let _resBatch = resBatchListToLoad[index];
231
+ let _resBatchInfo = this.resBatchInfoMap.get(_resBatch);
232
+ _resBatchInfo.isBatchLoaded = true;
233
+ }
234
+ this.resBatchInfoMap.set(resBatch, resBatchInfo);
235
+ // this._printInfo();
236
+ if (this.loadEndFunc) {
237
+ this.loadEndFunc();
238
+ }
239
+ }
240
+ });
241
+ }
242
+ }
243
+ });
244
+ }
245
+ }
246
+ _preloadAsset(abBundle, resUrl, assetType, endFunc) {
247
+ if (endFunc === null) {
248
+ return;
249
+ }
250
+ abBundle.load(resUrl, assetType, (error, asset) => {
251
+ if (error) {
252
+ endFunc(false, error);
253
+ }
254
+ else {
255
+ endFunc(true);
256
+ }
257
+ });
258
+ }
259
+ getAsset(bundleName, url, assetType) {
260
+ let bundle = assetManager.getBundle(bundleName);
261
+ if (bundle === null) {
262
+ LogUtils.Instance.log(ResMgr.TAG, "getAsset() error: " + bundleName + " AssetsBundle not loaded");
263
+ return null;
264
+ }
265
+ if (!assetType) {
266
+ return bundle.get(url);
267
+ }
268
+ return bundle.get(url, assetType);
269
+ }
270
+ getBundleResCount(bundleName, path, assetType) {
271
+ let abBundle = this.abBundsMap.get(bundleName);
272
+ if (abBundle === null) {
273
+ return 0;
274
+ }
275
+ const infos = [];
276
+ abBundle.getDirWithPath(path, assetType, infos);
277
+ return infos.length;
278
+ }
279
+ loadRes(bundleName, url, assetType, callback) {
280
+ if (!callback) {
281
+ return;
282
+ }
283
+ if (this.abBundsMap.has(bundleName)) {
284
+ this._loadRes(bundleName, url, assetType, callback);
285
+ return;
286
+ }
287
+ assetManager.loadBundle(bundleName, (err, bundle) => {
288
+ if (err !== null) {
289
+ LogUtils.Instance.log(ResMgr.TAG, "loadAssetsBundle() error:" + bundleName);
290
+ if (this.abBundsMap.has(bundleName)) {
291
+ this.abBundsMap.delete(bundleName);
292
+ }
293
+ callback(false);
294
+ return;
295
+ }
296
+ else {
297
+ LogUtils.Instance.log(ResMgr.TAG, "loadAssetsBundle() success:" + bundleName);
298
+ this.abBundsMap.set(bundleName, bundle);
299
+ this._loadRes(bundleName, url, assetType, callback);
300
+ }
301
+ });
302
+ }
303
+ _loadRes(bundleName, url, assetType, callback) {
304
+ let abBundle = this.abBundsMap.get(bundleName);
305
+ if (abBundle === null) {
306
+ callback(false);
307
+ return;
308
+ }
309
+ abBundle.load(url, assetType, (error, asset) => {
310
+ if (error) {
311
+ LogUtils.Instance.log(ResMgr.TAG, "loadRes() " + url + " error: " + error);
312
+ callback(false);
313
+ }
314
+ else {
315
+ LogUtils.Instance.log(ResMgr.TAG, "loadRes() " + url + " sucess");
316
+ callback(true);
317
+ }
318
+ });
319
+ }
320
+ /*
321
+ imageUrl: "https://xxxx"
322
+ fileSuffix: ".png"
323
+ */
324
+ loadRemoteImage(imageUrl, fileSuffix, callback) {
325
+ assetManager.loadRemote(imageUrl, { ext: fileSuffix }, (err, data) => {
326
+ if (err) {
327
+ LogUtils.Instance.log(ResMgr.TAG, err);
328
+ callback(err, null);
329
+ }
330
+ else {
331
+ callback(null, data);
332
+ }
333
+ });
334
+ }
335
+ }
336
+ ResMgr.Instance = null;
337
+ ResMgr.TAG = "ResMgr";
@@ -0,0 +1,23 @@
1
+ import { ShareInfo } from "../Definition/SocialDefinition";
2
+ import { BaseMgr } from "./BaseMgr";
3
+ export declare class SocialMgr extends BaseMgr {
4
+ static Instance: SocialMgr;
5
+ static TAG: string;
6
+ private shareInfo;
7
+ onLoad(): void;
8
+ init(shareInfo: ShareInfo): void;
9
+ supportPassiveShare(): boolean;
10
+ supportActiveShare(): boolean;
11
+ configPassiveShare(title?: string, desc?: string, imageUrl?: string, templateId?: string, query?: string): void;
12
+ activeShareToFriend(callback?: Function, title?: string, desc?: string, imageUrl?: string, templateId?: string, query?: string): void;
13
+ supportRankList(): boolean;
14
+ setRankData(args: any[]): void;
15
+ showRankList(args: any[]): void;
16
+ openPortalGame(): void;
17
+ supportGameClub(): boolean;
18
+ openGameClub(): void;
19
+ supportRecommendToFriend(): boolean;
20
+ openRecommendToFriend(): void;
21
+ supportRecommendToGameClub(): boolean;
22
+ openRecommendToGameClub(): void;
23
+ }