db8aefcd4ca5f0eb533739e806f9c0f865db70b3.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, Timer, _crd;
  4. function get_new_timer(step) {
  5. return new Timer(step);
  6. }
  7. _export("default", get_new_timer);
  8. return {
  9. setters: [function (_cc) {
  10. _cclegacy = _cc.cclegacy;
  11. }],
  12. execute: function () {
  13. _crd = true;
  14. _cclegacy._RF.push({}, "890248SdzRIsa6dPHIO+Qxy", "Timer", undefined);
  15. Timer = class Timer {
  16. get elapsedTime() {
  17. return this._elapsedTime;
  18. }
  19. /** 触发间隔时间(秒) */
  20. get step() {
  21. return this._step;
  22. }
  23. set step(step) {
  24. this._step = step; // 每次修改时间
  25. this._elapsedTime = 0; // 逝去时间
  26. }
  27. get coundown() {
  28. return this._step - this._elapsedTime;
  29. }
  30. get progress() {
  31. return this._elapsedTime / this._step;
  32. }
  33. constructor(step = 0) {
  34. this._elapsedTime = 0;
  35. this._step = -1;
  36. this.step = step;
  37. }
  38. /**
  39. * 序列化(数据库存储)
  40. */
  41. serialize() {
  42. let data = {
  43. "step": this._step,
  44. "elapsed": this._elapsedTime
  45. };
  46. return data;
  47. }
  48. /**
  49. * 反序列化
  50. */
  51. unserialize(data) {
  52. if (!data) return;
  53. this._step = data.step;
  54. this._elapsedTime = data.elapsed;
  55. }
  56. update(dt) {
  57. if (this.step <= 0) return false;
  58. this._elapsedTime += dt;
  59. if (this._elapsedTime >= this._step) {
  60. this._elapsedTime -= this._step;
  61. return true;
  62. }
  63. return false;
  64. }
  65. reset() {
  66. this._elapsedTime = 0;
  67. }
  68. stop() {
  69. this._elapsedTime = 0;
  70. this.step = -1;
  71. }
  72. };
  73. _cclegacy._RF.pop();
  74. _crd = false;
  75. }
  76. };
  77. });
  78. //# sourceMappingURL=db8aefcd4ca5f0eb533739e806f9c0f865db70b3.js.map