keytops-game-framework 1.0.10 → 1.0.12

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 +179 -168
  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
  */
@@ -6178,9 +6342,7 @@ class ILoginAble {
6178
6342
  */
6179
6343
  login(caller, onSuccess, onFail) {
6180
6344
  console.log("登录", this._type);
6181
- if (storage.userId) {
6182
- this._setOpenID(storage.userId);
6183
- }
6345
+ this._setOpenID(storage.userId || "temp_" + StringUtils.random(16));
6184
6346
  onSuccess && onSuccess.apply(caller);
6185
6347
  }
6186
6348
  _setOpenID(openID) {
@@ -6241,6 +6403,14 @@ class IPayAble {
6241
6403
 
6242
6404
  class EnterOptionParser {
6243
6405
  constructor(options) {
6406
+ if (typeof options === "string") {
6407
+ try {
6408
+ options = options ? JSON.parse(options) : {};
6409
+ }
6410
+ catch (_a) {
6411
+ options = {};
6412
+ }
6413
+ }
6244
6414
  this._options = options || {};
6245
6415
  }
6246
6416
  /**
@@ -8740,170 +8910,6 @@ MathUtils.seed = 10;
8740
8910
  */
8741
8911
  MathUtils.onlyMap = new Map();
8742
8912
 
8743
- class StringUtils {
8744
- static random(length, chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
8745
- var result = '';
8746
- for (var i = length; i > 0; --i) {
8747
- result += chars[Math.floor(Math.random() * chars.length)];
8748
- }
8749
- return result;
8750
- }
8751
- /**
8752
- * 判断是否是远程资源
8753
- * @param url
8754
- * @returns
8755
- */
8756
- static isRemote(url) {
8757
- if (url.indexOf("http://") == 0 || url.indexOf("https://") == 0) {
8758
- return true;
8759
- }
8760
- return false;
8761
- }
8762
- /**
8763
- * 是否为空
8764
- * @param str
8765
- */
8766
- static isEmpty(str) {
8767
- if (str == null || str == undefined || str.length == 0) {
8768
- return true;
8769
- }
8770
- return false;
8771
- }
8772
- /**
8773
- * 替换全部字符串
8774
- * @param string src 源串
8775
- * @param string from_ch 被替换的字符
8776
- * @param string to_ch 替换的字符
8777
- *
8778
- * @return string 结果字符串
8779
- */
8780
- static replaceAll(src, from_ch, to_ch) {
8781
- let regExp = new RegExp(from_ch, "g");
8782
- return src.replace(regExp, to_ch);
8783
- }
8784
- /**
8785
- * 参数替换
8786
- * @param str
8787
- * @param rest
8788
- *
8789
- * @example
8790
- *
8791
- * var str:string = "here is some info '{0}' and {1}";
8792
- * trace(StringUtil.substitute(str, 15.4, true));
8793
- *
8794
- * // this will output the following string:
8795
- * // "here is some info '15.4' and true"
8796
- */
8797
- static format(str, ...rest) {
8798
- if (str == null)
8799
- return '';
8800
- // Replace all of the parameters in the msg string.
8801
- var len = rest.length;
8802
- var args;
8803
- if (len == 1 && rest[0] instanceof Array) {
8804
- args = rest[0];
8805
- len = args.length;
8806
- }
8807
- else {
8808
- args = rest;
8809
- }
8810
- for (var i = 0; i < len; i++) {
8811
- str = str.replace(new RegExp("\\{" + i + "\\}", "g"), args[i]);
8812
- }
8813
- return str;
8814
- }
8815
- /**
8816
- *
8817
- * 格式化数字
8818
- * @param amount 目标数字
8819
- * @param format 支持{1:"", 100:"百", 1000:"千", 10000:"万", 100000:"十万", 1000000:"百万", 10000000:"千万", 100000000:"亿", 1000000000000:"兆"}等
8820
- * @returns
8821
- */
8822
- static formatNumber(amount, format) {
8823
- if (!format || amount == 0) {
8824
- return `${amount}`;
8825
- }
8826
- let formatKey = [];
8827
- for (const key in format) {
8828
- if (format.hasOwnProperty(key)) {
8829
- formatKey.push(Number(key));
8830
- }
8831
- }
8832
- if (!formatKey || formatKey.length == 0) {
8833
- return `${amount}`;
8834
- }
8835
- formatKey.sort((a, b) => b - a);
8836
- let result = [];
8837
- let total = amount;
8838
- for (let i = 0; i < formatKey.length; i++) {
8839
- const key = formatKey[i];
8840
- let count = Math.floor(Math.abs(total / key)) * (total / Math.abs(total));
8841
- if (count == 0) {
8842
- continue;
8843
- }
8844
- total = total % key;
8845
- result.push(`${count}${format[key]}`);
8846
- }
8847
- return result.length ? result.join("") : `${amount}`;
8848
- }
8849
- /**
8850
- * 带自动补全的秒数格式。
8851
- * @param second 秒数
8852
- * @param format 格式化文本
8853
- * @param pad 填充文本,默认为“0”
8854
- * @example
8855
- * formatSecond(86400, "ddd天hh小时mm分ss秒")=>"001天00小时00分00秒"
8856
- * formatSecond(86400, "dd天hh小时mm分ss秒")=>"01天00小时00分00秒"
8857
- * formatSecond(86400, "hh小时mm分ss秒")=>"24小时00分00秒"
8858
- * formatSecond(86400, "mm分ss秒")=>"1440分00秒"
8859
- * @returns
8860
- */
8861
- static formatSecond(second, format, pad = "0") {
8862
- const formatArr = [
8863
- { unit: 86400, regExp: /D{2,}/i },
8864
- { unit: 3600, regExp: /H{1,2}/i },
8865
- { unit: 60, regExp: /m{1,2}/i },
8866
- { unit: 1, regExp: /s{1,2}/i },
8867
- ];
8868
- for (let i = 0; i < formatArr.length; i++) {
8869
- const element = formatArr[i];
8870
- let match = element.regExp.exec(format);
8871
- if (match) {
8872
- format = format.replace(element.regExp, Math.floor(second / element.unit).toFixed(0).padStart(match[0].length, pad));
8873
- second = second % element.unit;
8874
- }
8875
- }
8876
- return format;
8877
- }
8878
- /**
8879
- * 带自动补全的时间戳格式化
8880
- * @param milliseconds
8881
- * @param format
8882
- * @param pad 填充文本,默认为“0”
8883
- * @returns
8884
- */
8885
- static formatTimestamp(milliseconds, format, pad = "0") {
8886
- let date = new Date(milliseconds);
8887
- date.getHours();
8888
- const formatArr = [
8889
- { r: /Y{4}/, to: date.getFullYear() },
8890
- { r: /M{1,2}/, to: date.getMonth() + 1 },
8891
- { r: /D{1,2}/, to: date.getDate() },
8892
- { r: /H{1,2}/, to: date.getHours() },
8893
- { r: /m{1,2}/, to: date.getMinutes() },
8894
- { r: /s{1,2}/, to: date.getSeconds() },
8895
- ];
8896
- for (let i = 0; i < formatArr.length; i++) {
8897
- const element = formatArr[i];
8898
- let match = element.r.exec(format);
8899
- if (match) {
8900
- format = format.replace(element.r, element.to.toString().padStart(match[0].length, "0"));
8901
- }
8902
- }
8903
- return format;
8904
- }
8905
- }
8906
-
8907
8913
  class KKTServer {
8908
8914
  requestConfig(context) {
8909
8915
  var _a, _b;
@@ -10243,7 +10249,12 @@ class CocosStorageUtils {
10243
10249
  if (!window['CC_DEBUG']) {
10244
10250
  key = md5(key);
10245
10251
  }
10246
- sys.localStorage.setItem(key, value);
10252
+ try {
10253
+ sys.localStorage.setItem(key, value);
10254
+ }
10255
+ catch (error) {
10256
+ console.error('Failed to set storage value:', "key:", key, "value:", value, "length:", String(value).length, "error:", error);
10257
+ }
10247
10258
  }
10248
10259
  getValue(key) {
10249
10260
  if (!window['CC_DEBUG']) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keytops-game-framework",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "cocos creator game framework library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",