dd58f4c37bc544ff40b69eba21e4cf27f0cab923.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. System.register(["__unresolved_0", "cc"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, ECSGroup, _crd;
  4. function _reportPossibleCrUseOfecs(extras) {
  5. _reporterNs.report("ecs", "./ECS", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfECSEntity(extras) {
  8. _reporterNs.report("ECSEntity", "./ECSEntity", _context.meta, extras);
  9. }
  10. _export("ECSGroup", void 0);
  11. return {
  12. setters: [function (_unresolved_) {
  13. _reporterNs = _unresolved_;
  14. }, function (_cc) {
  15. _cclegacy = _cc.cclegacy;
  16. }],
  17. execute: function () {
  18. _crd = true;
  19. _cclegacy._RF.push({}, "c21a23o9P5FNJamcMmoYWfs", "ECSGroup", undefined);
  20. /*
  21. * @Author: dgflash
  22. * @Date: 2022-09-01 18:00:28
  23. * @LastEditors: dgflash
  24. * @LastEditTime: 2022-09-05 14:21:54
  25. */
  26. _export("ECSGroup", ECSGroup = class ECSGroup {
  27. /**
  28. * 符合规则的实体
  29. */
  30. get matchEntities() {
  31. if (this._entitiesCache === null) {
  32. this._entitiesCache = Array.from(this._matchEntities.values());
  33. }
  34. return this._entitiesCache;
  35. }
  36. /**
  37. * 当前group中实体的数量
  38. *
  39. * 注:不要手动修改这个属性值。
  40. * 注:其实可以通过this._matchEntities.size获得实体数量,但是需要封装get方法。为了减少一次方法的调用所以才直接创建一个count属性
  41. */
  42. /** 获取matchEntities中第一个实体 */
  43. get entity() {
  44. return this.matchEntities[0];
  45. }
  46. constructor(matcher) {
  47. /** 实体筛选规则 */
  48. this.matcher = void 0;
  49. this._matchEntities = new Map();
  50. this._entitiesCache = null;
  51. this.count = 0;
  52. this._enteredEntities = null;
  53. this._removedEntities = null;
  54. this.matcher = matcher;
  55. }
  56. onComponentAddOrRemove(entity) {
  57. if (this.matcher.isMatch(entity)) {
  58. // Group只关心指定组件在实体身上的添加和删除动作。
  59. this._matchEntities.set(entity.eid, entity);
  60. this._entitiesCache = null;
  61. this.count++;
  62. if (this._enteredEntities) {
  63. this._enteredEntities.set(entity.eid, entity);
  64. this._removedEntities.delete(entity.eid);
  65. }
  66. } else if (this._matchEntities.has(entity.eid)) {
  67. // 如果Group中有这个实体,但是这个实体已经不满足匹配规则,则从Group中移除该实体
  68. this._matchEntities.delete(entity.eid);
  69. this._entitiesCache = null;
  70. this.count--;
  71. if (this._enteredEntities) {
  72. this._enteredEntities.delete(entity.eid);
  73. this._removedEntities.set(entity.eid, entity);
  74. }
  75. }
  76. }
  77. watchEntityEnterAndRemove(enteredEntities, removedEntities) {
  78. this._enteredEntities = enteredEntities;
  79. this._removedEntities = removedEntities;
  80. }
  81. clear() {
  82. var _this$_enteredEntitie, _this$_removedEntitie;
  83. this._matchEntities.clear();
  84. this._entitiesCache = null;
  85. this.count = 0;
  86. (_this$_enteredEntitie = this._enteredEntities) == null || _this$_enteredEntitie.clear();
  87. (_this$_removedEntitie = this._removedEntities) == null || _this$_removedEntitie.clear();
  88. }
  89. });
  90. _cclegacy._RF.pop();
  91. _crd = false;
  92. }
  93. };
  94. });
  95. //# sourceMappingURL=dd58f4c37bc544ff40b69eba21e4cf27f0cab923.js.map