a2f25f48cbfa2f7e52a840b80a2809b034d1e5a9.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. System.register(["__unresolved_0", "cc", "cc/env", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Component, log, _decorator, DEBUG, VM, VMEnv, _dec, _class, _crd, DEBUG_WATCH_PATH, ccclass, help, VMBase;
  4. function _reportPossibleCrUseOfVM(extras) {
  5. _reporterNs.report("VM", "./ViewModel", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfVMEnv(extras) {
  8. _reporterNs.report("VMEnv", "./VMEnv", _context.meta, extras);
  9. }
  10. return {
  11. setters: [function (_unresolved_) {
  12. _reporterNs = _unresolved_;
  13. }, function (_cc) {
  14. _cclegacy = _cc.cclegacy;
  15. __checkObsolete__ = _cc.__checkObsolete__;
  16. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  17. Component = _cc.Component;
  18. log = _cc.log;
  19. _decorator = _cc._decorator;
  20. }, function (_ccEnv) {
  21. DEBUG = _ccEnv.DEBUG;
  22. }, function (_unresolved_2) {
  23. VM = _unresolved_2.VM;
  24. }, function (_unresolved_3) {
  25. VMEnv = _unresolved_3.VMEnv;
  26. }],
  27. execute: function () {
  28. _crd = true;
  29. _cclegacy._RF.push({}, "2f6f36IvUdPO7xynnVTPgzb", "VMBase", undefined);
  30. __checkObsolete__(['Component', 'log', '_decorator']);
  31. // 用来处理通知数据的层级
  32. // 控制旗下子节点的数据
  33. // 目前只是起到一个识别组件的作用,之后会抽象很多功能在这里面
  34. // player.equips.* 可以自动根据所在父对象的位置设置顺序
  35. DEBUG_WATCH_PATH = false;
  36. ({
  37. ccclass,
  38. help
  39. } = _decorator);
  40. /**
  41. * watchPath 的基础,只提供绑定功能 和 对应的数据更新函数
  42. */
  43. _export("VMBase", VMBase = (_dec = help('https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12037631&doc_id=2873565'), ccclass(_class = _dec(_class = class VMBase extends Component {
  44. constructor(...args) {
  45. super(...args);
  46. /**VM管理 */
  47. this.VM = _crd && VM === void 0 ? (_reportPossibleCrUseOfVM({
  48. error: Error()
  49. }), VM) : VM;
  50. /** watch 单路径 */
  51. this.watchPath = '';
  52. /** 是否启用模板多路径模式 */
  53. this.templateMode = false;
  54. /** watch 多路径 */
  55. this.watchPathArr = [];
  56. /** 储存模板多路径的值 */
  57. this.templateValueArr = [];
  58. }
  59. /**
  60. * 如果需要重写onLoad 方法,请根据顺序调用 super.onLoad(),执行默认方法
  61. */
  62. onLoad() {
  63. if ((_crd && VMEnv === void 0 ? (_reportPossibleCrUseOfVMEnv({
  64. error: Error()
  65. }), VMEnv) : VMEnv).editor) return; // 提前拆分、并且解析路径
  66. let paths = this.watchPath.split('.');
  67. for (let i = 1; i < paths.length; i++) {
  68. const p = paths[i]; // 如果发现了路径使用了 * ,则自动去自己的父节点查找自己所在 index 值
  69. if (p == '*') {
  70. let index = this.node.parent.children.findIndex(n => n === this.node);
  71. if (index <= 0) index = 0;
  72. paths[i] = index.toString();
  73. break;
  74. }
  75. } // 替换掉原路径
  76. this.watchPath = paths.join('.'); // 提前进行路径数组 的 解析
  77. let pathArr = this.watchPathArr;
  78. if (pathArr.length >= 1) {
  79. for (let i = 0; i < pathArr.length; i++) {
  80. const path = pathArr[i];
  81. let paths = path.split('.');
  82. for (let i = 1; i < paths.length; i++) {
  83. const p = paths[i];
  84. if (p == '*') {
  85. let index = this.node.parent.children.findIndex(n => n === this.node);
  86. if (index <= 0) index = 0;
  87. paths[i] = index.toString();
  88. break;
  89. }
  90. }
  91. this.watchPathArr[i] = paths.join('.');
  92. }
  93. } // 打印出所有绑定的路径,方便调试信息
  94. if (DEBUG_WATCH_PATH && DEBUG) {
  95. log('所有路径', this.watchPath ? [this.watchPath] : this.watchPathArr, '<<', this.node.parent.name + '.' + this.node.name);
  96. }
  97. if (this.watchPath == '' && this.watchPathArr.join('') == '') {
  98. log('可能未设置路径的节点:', this.node.parent.name + '.' + this.node.name);
  99. }
  100. }
  101. onEnable() {
  102. if ((_crd && VMEnv === void 0 ? (_reportPossibleCrUseOfVMEnv({
  103. error: Error()
  104. }), VMEnv) : VMEnv).editor) return;
  105. if (this.templateMode) {
  106. this.setMultPathEvent(true);
  107. } else if (this.watchPath != '') {
  108. this.VM.bindPath(this.watchPath, this.onValueChanged, this);
  109. }
  110. this.onValueInit(); // 激活时,调用值初始化
  111. }
  112. onDisable() {
  113. if ((_crd && VMEnv === void 0 ? (_reportPossibleCrUseOfVMEnv({
  114. error: Error()
  115. }), VMEnv) : VMEnv).editor) return;
  116. if (this.templateMode) {
  117. this.setMultPathEvent(false);
  118. } else if (this.watchPath != '') {
  119. this.VM.unbindPath(this.watchPath, this.onValueChanged, this);
  120. }
  121. } // 多路径监听方式
  122. setMultPathEvent(enabled = true) {
  123. if ((_crd && VMEnv === void 0 ? (_reportPossibleCrUseOfVMEnv({
  124. error: Error()
  125. }), VMEnv) : VMEnv).editor) return;
  126. let arr = this.watchPathArr;
  127. for (let i = 0; i < arr.length; i++) {
  128. const path = arr[i];
  129. if (enabled) {
  130. this.VM.bindPath(path, this.onValueChanged, this);
  131. } else {
  132. this.VM.unbindPath(path, this.onValueChanged, this);
  133. }
  134. }
  135. }
  136. onValueInit() {// 虚方法
  137. }
  138. /**
  139. * 值变化事件
  140. * @param n 新值
  141. * @param o 旧值
  142. * @param pathArr 对象路径数组
  143. */
  144. onValueChanged(n, o, pathArr) {}
  145. }) || _class) || _class));
  146. _cclegacy._RF.pop();
  147. _crd = false;
  148. }
  149. };
  150. });
  151. //# sourceMappingURL=a2f25f48cbfa2f7e52a840b80a2809b034d1e5a9.js.map