keytops-game-framework 1.0.11 → 1.0.13

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 (2) hide show
  1. package/dist/index.js +173 -169
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6153,6 +6153,170 @@ class IDevice {
6153
6153
  }
6154
6154
  }
6155
6155
 
6156
+ class StringUtils {
6157
+ static random(length, chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
6158
+ var result = '';
6159
+ for (var i = length; i > 0; --i) {
6160
+ result += chars[Math.floor(Math.random() * chars.length)];
6161
+ }
6162
+ return result;
6163
+ }
6164
+ /**
6165
+ * 判断是否是远程资源
6166
+ * @param url
6167
+ * @returns
6168
+ */
6169
+ static isRemote(url) {
6170
+ if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) {
6171
+ return true;
6172
+ }
6173
+ return false;
6174
+ }
6175
+ /**
6176
+ * 是否为空
6177
+ * @param str
6178
+ */
6179
+ static isEmpty(str) {
6180
+ if (str == null || str == undefined || str.length == 0) {
6181
+ return true;
6182
+ }
6183
+ return false;
6184
+ }
6185
+ /**
6186
+ * 替换全部字符串
6187
+ * @param string src 源串
6188
+ * @param string from_ch 被替换的字符
6189
+ * @param string to_ch 替换的字符
6190
+ *
6191
+ * @return string 结果字符串
6192
+ */
6193
+ static replaceAll(src, from_ch, to_ch) {
6194
+ let regExp = new RegExp(from_ch, "g");
6195
+ return src.replace(regExp, to_ch);
6196
+ }
6197
+ /**
6198
+ * 参数替换
6199
+ * @param str
6200
+ * @param rest
6201
+ *
6202
+ * @example
6203
+ *
6204
+ * var str:string = "here is some info '{0}' and {1}";
6205
+ * trace(StringUtil.substitute(str, 15.4, true));
6206
+ *
6207
+ * // this will output the following string:
6208
+ * // "here is some info '15.4' and true"
6209
+ */
6210
+ static format(str, ...rest) {
6211
+ if (str == null)
6212
+ return '';
6213
+ // Replace all of the parameters in the msg string.
6214
+ var len = rest.length;
6215
+ var args;
6216
+ if (len == 1 && rest[0] instanceof Array) {
6217
+ args = rest[0];
6218
+ len = args.length;
6219
+ }
6220
+ else {
6221
+ args = rest;
6222
+ }
6223
+ for (var i = 0; i < len; i++) {
6224
+ str = str.replace(new RegExp("\\{" + i + "\\}", "g"), args[i]);
6225
+ }
6226
+ return str;
6227
+ }
6228
+ /**
6229
+ *
6230
+ * 格式化数字
6231
+ * @param amount 目标数字
6232
+ * @param format 支持{1:"", 100:"百", 1000:"千", 10000:"万", 100000:"十万", 1000000:"百万", 10000000:"千万", 100000000:"亿", 1000000000000:"兆"}等
6233
+ * @returns
6234
+ */
6235
+ static formatNumber(amount, format) {
6236
+ if (!format || amount == 0) {
6237
+ return `${amount}`;
6238
+ }
6239
+ let formatKey = [];
6240
+ for (const key in format) {
6241
+ if (format.hasOwnProperty(key)) {
6242
+ formatKey.push(Number(key));
6243
+ }
6244
+ }
6245
+ if (!formatKey || formatKey.length == 0) {
6246
+ return `${amount}`;
6247
+ }
6248
+ formatKey.sort((a, b) => b - a);
6249
+ let result = [];
6250
+ let total = amount;
6251
+ for (let i = 0; i < formatKey.length; i++) {
6252
+ const key = formatKey[i];
6253
+ let count = Math.floor(Math.abs(total / key)) * (total / Math.abs(total));
6254
+ if (count == 0) {
6255
+ continue;
6256
+ }
6257
+ total = total % key;
6258
+ result.push(`${count}${format[key]}`);
6259
+ }
6260
+ return result.length ? result.join("") : `${amount}`;
6261
+ }
6262
+ /**
6263
+ * 带自动补全的秒数格式。
6264
+ * @param second 秒数
6265
+ * @param format 格式化文本
6266
+ * @param pad 填充文本,默认为“0”
6267
+ * @example
6268
+ * formatSecond(86400, "ddd天hh小时mm分ss秒")=>"001天00小时00分00秒"
6269
+ * formatSecond(86400, "dd天hh小时mm分ss秒")=>"01天00小时00分00秒"
6270
+ * formatSecond(86400, "hh小时mm分ss秒")=>"24小时00分00秒"
6271
+ * formatSecond(86400, "mm分ss秒")=>"1440分00秒"
6272
+ * @returns
6273
+ */
6274
+ static formatSecond(second, format, pad = "0") {
6275
+ const formatArr = [
6276
+ { unit: 86400, regExp: /D{2,}/i },
6277
+ { unit: 3600, regExp: /H{1,2}/i },
6278
+ { unit: 60, regExp: /m{1,2}/i },
6279
+ { unit: 1, regExp: /s{1,2}/i },
6280
+ ];
6281
+ for (let i = 0; i < formatArr.length; i++) {
6282
+ const element = formatArr[i];
6283
+ let match = element.regExp.exec(format);
6284
+ if (match) {
6285
+ format = format.replace(element.regExp, Math.floor(second / element.unit).toFixed(0).padStart(match[0].length, pad));
6286
+ second = second % element.unit;
6287
+ }
6288
+ }
6289
+ return format;
6290
+ }
6291
+ /**
6292
+ * 带自动补全的时间戳格式化
6293
+ * @param milliseconds
6294
+ * @param format
6295
+ * @param pad 填充文本,默认为“0”
6296
+ * @returns
6297
+ */
6298
+ static formatTimestamp(milliseconds, format, pad = "0") {
6299
+ let date = new Date(milliseconds);
6300
+ date.getHours();
6301
+ const formatArr = [
6302
+ { r: /Y{4}/, to: date.getFullYear() },
6303
+ { r: /M{1,2}/, to: date.getMonth() + 1 },
6304
+ { r: /D{1,2}/, to: date.getDate() },
6305
+ { r: /H{1,2}/, to: date.getHours() },
6306
+ { r: /m{1,2}/, to: date.getMinutes() },
6307
+ { r: /s{1,2}/, to: date.getSeconds() },
6308
+ ];
6309
+ for (let i = 0; i < formatArr.length; i++) {
6310
+ const element = formatArr[i];
6311
+ let match = element.r.exec(format);
6312
+ if (match) {
6313
+ format = format.replace(element.r, element.to.toString().padStart(match[0].length, "0"));
6314
+ }
6315
+ }
6316
+ return format;
6317
+ }
6318
+ }
6319
+
6156
6320
  /**
6157
6321
  * 登录能力
6158
6322
  */
@@ -6177,10 +6341,9 @@ class ILoginAble {
6177
6341
  * 登录,helper内登录成功后,必须调用this._setOpenId();否则后续逻辑会有BUG
6178
6342
  */
6179
6343
  login(caller, onSuccess, onFail) {
6180
- console.log("登录", this._type);
6181
- if (storage.userId) {
6182
- this._setOpenID(storage.userId);
6183
- }
6344
+ const openID = storage.userId || "temp_" + StringUtils.random(16);
6345
+ this._setOpenID(openID);
6346
+ console.log("登录", this._type, "openID", openID, "this.openID", this.openID);
6184
6347
  onSuccess && onSuccess.apply(caller);
6185
6348
  }
6186
6349
  _setOpenID(openID) {
@@ -8748,170 +8911,6 @@ MathUtils.seed = 10;
8748
8911
  */
8749
8912
  MathUtils.onlyMap = new Map();
8750
8913
 
8751
- class StringUtils {
8752
- static random(length, chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
8753
- var result = '';
8754
- for (var i = length; i > 0; --i) {
8755
- result += chars[Math.floor(Math.random() * chars.length)];
8756
- }
8757
- return result;
8758
- }
8759
- /**
8760
- * 判断是否是远程资源
8761
- * @param url
8762
- * @returns
8763
- */
8764
- static isRemote(url) {
8765
- if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) {
8766
- return true;
8767
- }
8768
- return false;
8769
- }
8770
- /**
8771
- * 是否为空
8772
- * @param str
8773
- */
8774
- static isEmpty(str) {
8775
- if (str == null || str == undefined || str.length == 0) {
8776
- return true;
8777
- }
8778
- return false;
8779
- }
8780
- /**
8781
- * 替换全部字符串
8782
- * @param string src 源串
8783
- * @param string from_ch 被替换的字符
8784
- * @param string to_ch 替换的字符
8785
- *
8786
- * @return string 结果字符串
8787
- */
8788
- static replaceAll(src, from_ch, to_ch) {
8789
- let regExp = new RegExp(from_ch, "g");
8790
- return src.replace(regExp, to_ch);
8791
- }
8792
- /**
8793
- * 参数替换
8794
- * @param str
8795
- * @param rest
8796
- *
8797
- * @example
8798
- *
8799
- * var str:string = "here is some info '{0}' and {1}";
8800
- * trace(StringUtil.substitute(str, 15.4, true));
8801
- *
8802
- * // this will output the following string:
8803
- * // "here is some info '15.4' and true"
8804
- */
8805
- static format(str, ...rest) {
8806
- if (str == null)
8807
- return '';
8808
- // Replace all of the parameters in the msg string.
8809
- var len = rest.length;
8810
- var args;
8811
- if (len == 1 && rest[0] instanceof Array) {
8812
- args = rest[0];
8813
- len = args.length;
8814
- }
8815
- else {
8816
- args = rest;
8817
- }
8818
- for (var i = 0; i < len; i++) {
8819
- str = str.replace(new RegExp("\\{" + i + "\\}", "g"), args[i]);
8820
- }
8821
- return str;
8822
- }
8823
- /**
8824
- *
8825
- * 格式化数字
8826
- * @param amount 目标数字
8827
- * @param format 支持{1:"", 100:"百", 1000:"千", 10000:"万", 100000:"十万", 1000000:"百万", 10000000:"千万", 100000000:"亿", 1000000000000:"兆"}等
8828
- * @returns
8829
- */
8830
- static formatNumber(amount, format) {
8831
- if (!format || amount == 0) {
8832
- return `${amount}`;
8833
- }
8834
- let formatKey = [];
8835
- for (const key in format) {
8836
- if (format.hasOwnProperty(key)) {
8837
- formatKey.push(Number(key));
8838
- }
8839
- }
8840
- if (!formatKey || formatKey.length == 0) {
8841
- return `${amount}`;
8842
- }
8843
- formatKey.sort((a, b) => b - a);
8844
- let result = [];
8845
- let total = amount;
8846
- for (let i = 0; i < formatKey.length; i++) {
8847
- const key = formatKey[i];
8848
- let count = Math.floor(Math.abs(total / key)) * (total / Math.abs(total));
8849
- if (count == 0) {
8850
- continue;
8851
- }
8852
- total = total % key;
8853
- result.push(`${count}${format[key]}`);
8854
- }
8855
- return result.length ? result.join("") : `${amount}`;
8856
- }
8857
- /**
8858
- * 带自动补全的秒数格式。
8859
- * @param second 秒数
8860
- * @param format 格式化文本
8861
- * @param pad 填充文本,默认为“0”
8862
- * @example
8863
- * formatSecond(86400, "ddd天hh小时mm分ss秒")=>"001天00小时00分00秒"
8864
- * formatSecond(86400, "dd天hh小时mm分ss秒")=>"01天00小时00分00秒"
8865
- * formatSecond(86400, "hh小时mm分ss秒")=>"24小时00分00秒"
8866
- * formatSecond(86400, "mm分ss秒")=>"1440分00秒"
8867
- * @returns
8868
- */
8869
- static formatSecond(second, format, pad = "0") {
8870
- const formatArr = [
8871
- { unit: 86400, regExp: /D{2,}/i },
8872
- { unit: 3600, regExp: /H{1,2}/i },
8873
- { unit: 60, regExp: /m{1,2}/i },
8874
- { unit: 1, regExp: /s{1,2}/i },
8875
- ];
8876
- for (let i = 0; i < formatArr.length; i++) {
8877
- const element = formatArr[i];
8878
- let match = element.regExp.exec(format);
8879
- if (match) {
8880
- format = format.replace(element.regExp, Math.floor(second / element.unit).toFixed(0).padStart(match[0].length, pad));
8881
- second = second % element.unit;
8882
- }
8883
- }
8884
- return format;
8885
- }
8886
- /**
8887
- * 带自动补全的时间戳格式化
8888
- * @param milliseconds
8889
- * @param format
8890
- * @param pad 填充文本,默认为“0”
8891
- * @returns
8892
- */
8893
- static formatTimestamp(milliseconds, format, pad = "0") {
8894
- let date = new Date(milliseconds);
8895
- date.getHours();
8896
- const formatArr = [
8897
- { r: /Y{4}/, to: date.getFullYear() },
8898
- { r: /M{1,2}/, to: date.getMonth() + 1 },
8899
- { r: /D{1,2}/, to: date.getDate() },
8900
- { r: /H{1,2}/, to: date.getHours() },
8901
- { r: /m{1,2}/, to: date.getMinutes() },
8902
- { r: /s{1,2}/, to: date.getSeconds() },
8903
- ];
8904
- for (let i = 0; i < formatArr.length; i++) {
8905
- const element = formatArr[i];
8906
- let match = element.r.exec(format);
8907
- if (match) {
8908
- format = format.replace(element.r, element.to.toString().padStart(match[0].length, "0"));
8909
- }
8910
- }
8911
- return format;
8912
- }
8913
- }
8914
-
8915
8914
  class KKTServer {
8916
8915
  requestConfig(context) {
8917
8916
  var _a, _b;
@@ -10251,7 +10250,12 @@ class CocosStorageUtils {
10251
10250
  if (!window['CC_DEBUG']) {
10252
10251
  key = md5(key);
10253
10252
  }
10254
- sys.localStorage.setItem(key, value);
10253
+ try {
10254
+ sys.localStorage.setItem(key, value);
10255
+ }
10256
+ catch (error) {
10257
+ console.error('Failed to set storage value:', "key:", key, "value:", value, "length:", String(value).length, "error:", error);
10258
+ }
10255
10259
  }
10256
10260
  getValue(key) {
10257
10261
  if (!window['CC_DEBUG']) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keytops-game-framework",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "cocos creator game framework library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",