fdf2cef7-d328-480f-a677-53c7bd53491b.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use strict";
  2. cc._RF.push(module, 'fdf2c730yhID6Z3U8e9U0kb', 'BaseProp');
  3. // Script/prop/BaseProp.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var gameScene_1 = require("../gameScene");
  26. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  27. var BaseProp = /** @class */ (function (_super) {
  28. __extends(BaseProp, _super);
  29. function BaseProp() {
  30. return _super !== null && _super.apply(this, arguments) || this;
  31. }
  32. BaseProp_1 = BaseProp;
  33. /**
  34. * 初始化数据
  35. * @param element json道具数据
  36. */
  37. BaseProp.prototype.SetData = function (element) {
  38. this.TransfromSet(element, this.node);
  39. this.node.x = Number(element.x);
  40. this.node.y = Number(element.y);
  41. if (element.wid)
  42. this.node.width = Number(element.wid);
  43. if (element.path)
  44. this.SetTexture(element.path);
  45. if (element.hei)
  46. this.node.height = Number(element.hei);
  47. if (element.ang)
  48. this.node.angle = Number(element.ang);
  49. if (element.scaleX)
  50. this.node.scaleX = Number(element.scaleX);
  51. // console.log('element:', element)
  52. this.SetPhyBox();
  53. this.SpecicalSet(element);
  54. };
  55. /**
  56. * 道具内部特殊设置
  57. * @param element
  58. */
  59. BaseProp.prototype.SpecicalSet = function (element) {
  60. };
  61. /**
  62. * 设置物理盒子宽高同步
  63. */
  64. BaseProp.prototype.SetPhyBox = function () {
  65. if (this.node.getComponent(cc.PhysicsBoxCollider)) {
  66. var phyBox = this.node.getComponent(cc.PhysicsBoxCollider);
  67. phyBox.size.width = this.node.width;
  68. phyBox.size.height = this.node.height;
  69. phyBox.apply();
  70. }
  71. };
  72. /**
  73. * 触发函数
  74. * @param flag 是否dead
  75. */
  76. BaseProp.prototype.TriggerFunc = function (flag) {
  77. if (flag === void 0) { flag = true; }
  78. if (flag)
  79. gameScene_1.default.instance.GameFail();
  80. };
  81. BaseProp.prototype.SetOtherDoor = function (other) {
  82. console.log('SetOtherDoor:super');
  83. };
  84. /**
  85. * 传送门设置
  86. */
  87. BaseProp.prototype.TransfromSet = function (element, nodes) {
  88. if (element.num == 'O') {
  89. if (!gameScene_1.default.instance.tempTransform)
  90. gameScene_1.default.instance.tempTransform = nodes;
  91. else {
  92. gameScene_1.default.instance.tempTransform.getComponent(BaseProp_1).SetOtherDoor(nodes);
  93. this.SetOtherDoor(gameScene_1.default.instance.tempTransform);
  94. gameScene_1.default.instance.tempTransform = null;
  95. }
  96. }
  97. };
  98. BaseProp.prototype.SetTexture = function (tex) {
  99. var self = this;
  100. // console.log('装饰:', tex)
  101. this.GetTexture('texture/' + tex).then(function (res) {
  102. self.node.getComponent(cc.Sprite).spriteFrame = res;
  103. self.node.width = res._originalSize.width;
  104. self.node.height = res._originalSize.height;
  105. });
  106. };
  107. BaseProp.prototype.GetTexture = function (name) {
  108. var self = this;
  109. return new Promise(function (resolve) {
  110. cc.loader.loadRes(name, cc.SpriteFrame, function (err, spriteFrame) {
  111. if (err) {
  112. console.log("err", err);
  113. }
  114. else {
  115. resolve(spriteFrame);
  116. }
  117. });
  118. });
  119. };
  120. var BaseProp_1;
  121. BaseProp = BaseProp_1 = __decorate([
  122. ccclass
  123. ], BaseProp);
  124. return BaseProp;
  125. }(cc.Component));
  126. exports.default = BaseProp;
  127. cc._RF.pop();