09150aabc12199b9096239af328644e4d61e7aba.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, SafeVarNumber, SafeConstNumber, _crd;
  4. function get_new_safe_number(num) {
  5. return new SafeVarNumber(num);
  6. }
  7. function get_new_safe_const_number(num) {
  8. return new SafeConstNumber(num);
  9. }
  10. _export({
  11. get_new_safe_number: get_new_safe_number,
  12. get_new_safe_const_number: get_new_safe_const_number
  13. });
  14. return {
  15. setters: [function (_cc) {
  16. _cclegacy = _cc.cclegacy;
  17. }],
  18. execute: function () {
  19. _crd = true;
  20. _cclegacy._RF.push({}, "7e0d8kg6FBL46wNVfNiK7eE", "SafeNumber", undefined);
  21. /**
  22. * 防内存调试变量数字类型
  23. */
  24. SafeVarNumber = class SafeVarNumber {
  25. constructor(num = 0) {
  26. this.cache = 0;
  27. this.scale = 2;
  28. this.map = {};
  29. this.idx = 0;
  30. this.value = num;
  31. }
  32. /**数值 */
  33. get value() {
  34. if (Math.abs(this.map[this.idx] * this.scale - this.cache) > 0.000001) {
  35. this.map[this.idx] = this.cache / this.scale;
  36. }
  37. return this.map[this.idx];
  38. }
  39. set value(num) {
  40. delete this.map[this.idx];
  41. this.idx = Math.floor(Math.random() * 256);
  42. this.map[this.idx] = num;
  43. this.scale = Math.floor(Math.random() * 2) + 2;
  44. this.cache = num * this.scale;
  45. }
  46. valueOf() {
  47. return this.value;
  48. }
  49. toString() {
  50. return this.value.toString();
  51. }
  52. clone() {
  53. return new SafeVarNumber(this.value);
  54. }
  55. };
  56. /**
  57. * 防内存调试常量数字类型
  58. */
  59. SafeConstNumber = class SafeConstNumber {
  60. constructor(num = 0) {
  61. this.cache = 0;
  62. this.scale = 2;
  63. this.map = {};
  64. this.idx = 0;
  65. this.idx = Math.floor(Math.random() * 256);
  66. this.map[this.idx] = num;
  67. this.scale = Math.floor(Math.random() * 2) + 2;
  68. this.cache = num * this.scale;
  69. }
  70. /**数值 */
  71. get value() {
  72. let num = this.map[this.idx];
  73. if (Math.abs(num * this.scale - this.cache) > 0.000001) {
  74. num = this.cache / this.scale;
  75. }
  76. delete this.map[this.idx];
  77. this.idx = Math.floor(Math.random() * 256);
  78. this.map[this.idx] = num;
  79. return this.map[this.idx];
  80. }
  81. valueOf() {
  82. return this.value;
  83. }
  84. toString() {
  85. return this.value.toString();
  86. }
  87. clone() {
  88. return new SafeConstNumber(this.value);
  89. }
  90. };
  91. _cclegacy._RF.pop();
  92. _crd = false;
  93. }
  94. };
  95. });
  96. //# sourceMappingURL=09150aabc12199b9096239af328644e4d61e7aba.js.map