2921e5ac3c3c1df56126233b0234feb3b9fe16b9.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Toggle, _decorator, VMBase, VMEnv, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _crd, ccclass, property, executeInEditMode, menu, help, COMP_ARRAY_CHECK, VMCustom;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. function _reportPossibleCrUseOfVMBase(extras) {
  8. _reporterNs.report("VMBase", "./VMBase", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfVMEnv(extras) {
  11. _reporterNs.report("VMEnv", "./VMEnv", _context.meta, extras);
  12. }
  13. return {
  14. setters: [function (_unresolved_) {
  15. _reporterNs = _unresolved_;
  16. }, function (_cc) {
  17. _cclegacy = _cc.cclegacy;
  18. __checkObsolete__ = _cc.__checkObsolete__;
  19. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  20. Toggle = _cc.Toggle;
  21. _decorator = _cc._decorator;
  22. }, function (_unresolved_2) {
  23. VMBase = _unresolved_2.VMBase;
  24. }, function (_unresolved_3) {
  25. VMEnv = _unresolved_3.VMEnv;
  26. }],
  27. execute: function () {
  28. _crd = true;
  29. _cclegacy._RF.push({}, "ce662fwsSVPLKpmHx+KocFu", "VMCustom", undefined);
  30. __checkObsolete__(['Toggle', '_decorator']);
  31. ({
  32. ccclass,
  33. property,
  34. executeInEditMode,
  35. menu,
  36. help
  37. } = _decorator);
  38. /** 自动检查识别的数组,你可以准备自己的组件放上去自动识别 */
  39. COMP_ARRAY_CHECK = [['BhvFrameIndex', 'index', false], ['BhvGroupToggle', 'index', false], ['BhvRollNumber', 'targetValue', false], // 组件名、默认属性、controller值
  40. ['cc.Label', 'string', false], ['cc.RichText', 'string', false], ['cc.EditBox', 'string', true], ['cc.Slider', 'progress', true], ['cc.ProgressBar', 'progress', false], ['cc.Toggle', 'isChecked', true]];
  41. /**
  42. * [VM-Custom]
  43. * 自定义数值监听, 可以快速对该节点上任意一个组件上的属性进行双向绑定
  44. */
  45. _export("VMCustom", VMCustom = (_dec = menu('OopsFramework/Mvvm/VM-Custom (自定义)'), _dec2 = help('https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12037634&doc_id=2873565'), _dec3 = property({
  46. tooltip: '激活controller,以开启双向绑定,否则只能接收消息'
  47. }), _dec4 = property({
  48. tooltip: "监视对象路径"
  49. }), _dec5 = property({
  50. tooltip: '绑定组件的名字'
  51. }), _dec6 = property({
  52. tooltip: '组件上需要监听的属性'
  53. }), _dec7 = property({
  54. tooltip: '刷新间隔频率(只影响脏检查的频率)',
  55. step: 0.01,
  56. range: [0, 1],
  57. visible: function visible() {
  58. // @ts-ignore
  59. return this.controller === true;
  60. }
  61. }), ccclass(_class = executeInEditMode(_class = _dec(_class = _dec2(_class = (_class2 = class VMCustom extends (_crd && VMBase === void 0 ? (_reportPossibleCrUseOfVMBase({
  62. error: Error()
  63. }), VMBase) : VMBase) {
  64. constructor() {
  65. super(...arguments);
  66. _initializerDefineProperty(this, "controller", _descriptor, this);
  67. _initializerDefineProperty(this, "watchPath", _descriptor2, this);
  68. _initializerDefineProperty(this, "componentName", _descriptor3, this);
  69. _initializerDefineProperty(this, "componentProperty", _descriptor4, this);
  70. _initializerDefineProperty(this, "refreshRate", _descriptor5, this);
  71. /** 计时器 */
  72. this._timer = 0;
  73. /** 监听的组件对象 */
  74. this._watchComponent = null;
  75. /** 是否能监听组件的数据 */
  76. this._canWatchComponent = false;
  77. /** 检查的值 */
  78. this._oldValue = null;
  79. }
  80. onLoad() {
  81. super.onLoad(); // 只在运行时检查组件是否缺失可用
  82. this.checkEditorComponent(); //编辑器检查
  83. if ((_crd && VMEnv === void 0 ? (_reportPossibleCrUseOfVMEnv({
  84. error: Error()
  85. }), VMEnv) : VMEnv).editor) return;
  86. this._watchComponent = this.node.getComponent(this.componentName);
  87. this.checkComponentState();
  88. }
  89. onRestore() {
  90. this.checkEditorComponent();
  91. }
  92. start() {
  93. //从 watch 的路径中获取一个初始值
  94. this.onValueInit();
  95. } // 挂在对应节点后,自动获取组件属性和名字
  96. checkEditorComponent() {
  97. if ((_crd && VMEnv === void 0 ? (_reportPossibleCrUseOfVMEnv({
  98. error: Error()
  99. }), VMEnv) : VMEnv).editor) return;
  100. var checkArray = COMP_ARRAY_CHECK;
  101. for (var i = 0; i < checkArray.length; i++) {
  102. var params = checkArray[i];
  103. var comp = this.node.getComponent(params[0]);
  104. if (comp) {
  105. if (this.componentName == '') this.componentName = params[0];
  106. if (this.componentProperty == '') this.componentProperty = params[1];
  107. if (params[2] !== null) this.controller = params[2];
  108. break;
  109. }
  110. }
  111. }
  112. checkComponentState() {
  113. this._canWatchComponent = false;
  114. if (!this._watchComponent) {
  115. console.error('未设置需要监听的组件');
  116. return;
  117. }
  118. if (!this.componentProperty) {
  119. console.error('未设置需要监听的组件 的属性');
  120. return;
  121. }
  122. if (this.componentProperty in this._watchComponent === false) {
  123. console.error('需要监听的组件的属性不存在');
  124. return;
  125. }
  126. this._canWatchComponent = true;
  127. }
  128. getComponentValue() {
  129. return this._watchComponent[this.componentProperty];
  130. }
  131. setComponentValue(value) {
  132. // 如果遇到 Toggle 组件就调用上面的方法解决
  133. if (this.componentName == "cc.Toggle") {
  134. this.node.getComponent(Toggle).isChecked = value;
  135. } else {
  136. this._watchComponent[this.componentProperty] = value;
  137. }
  138. }
  139. /** 初始化获取数据 */
  140. onValueInit() {
  141. if ((_crd && VMEnv === void 0 ? (_reportPossibleCrUseOfVMEnv({
  142. error: Error()
  143. }), VMEnv) : VMEnv).editor) return; //更新信息
  144. this.setComponentValue(this.VM.getValue(this.watchPath));
  145. }
  146. /** [可重写]组件的值发生变化后,触发更新此值 */
  147. onValueController(newValue, oldValue) {
  148. this.VM.setValue(this.watchPath, newValue);
  149. }
  150. /** [可重写]初始化改变数据 */
  151. onValueChanged(n, o, pathArr) {
  152. this.setComponentValue(n);
  153. }
  154. update(dt) {
  155. // 脏检查(组件是否存在,是否被激活)
  156. if ((_crd && VMEnv === void 0 ? (_reportPossibleCrUseOfVMEnv({
  157. error: Error()
  158. }), VMEnv) : VMEnv).editor) return; //if (this.templateMode == true) return; //todo 模板模式下不能计算
  159. if (!this.controller) return;
  160. if (!this._canWatchComponent || this._watchComponent['enabled'] === false) return; //刷新频率检查
  161. this._timer += dt;
  162. if (this._timer < this.refreshRate) return;
  163. this._timer = 0;
  164. var oldValue = this._oldValue;
  165. var newValue = this.getComponentValue();
  166. if (this._oldValue === newValue) return;
  167. this._oldValue = this.getComponentValue();
  168. this.onValueController(newValue, oldValue);
  169. }
  170. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "controller", [_dec3], {
  171. configurable: true,
  172. enumerable: true,
  173. writable: true,
  174. initializer: function initializer() {
  175. return false;
  176. }
  177. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "watchPath", [_dec4], {
  178. configurable: true,
  179. enumerable: true,
  180. writable: true,
  181. initializer: function initializer() {
  182. return "";
  183. }
  184. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "componentName", [_dec5], {
  185. configurable: true,
  186. enumerable: true,
  187. writable: true,
  188. initializer: function initializer() {
  189. return "";
  190. }
  191. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "componentProperty", [_dec6], {
  192. configurable: true,
  193. enumerable: true,
  194. writable: true,
  195. initializer: function initializer() {
  196. return "";
  197. }
  198. }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "refreshRate", [_dec7], {
  199. configurable: true,
  200. enumerable: true,
  201. writable: true,
  202. initializer: function initializer() {
  203. return 0.1;
  204. }
  205. })), _class2)) || _class) || _class) || _class) || _class));
  206. _cclegacy._RF.pop();
  207. _crd = false;
  208. }
  209. };
  210. });
  211. //# sourceMappingURL=2921e5ac3c3c1df56126233b0234feb3b9fe16b9.js.map