babylon.condition.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var Condition = (function () {
  10. function Condition(actionManager) {
  11. this._actionManager = actionManager;
  12. }
  13. Condition.prototype.isValid = function () {
  14. return true;
  15. };
  16. Condition.prototype._getProperty = function (propertyPath) {
  17. return this._actionManager._getProperty(propertyPath);
  18. };
  19. Condition.prototype._getEffectiveTarget = function (target, propertyPath) {
  20. return this._actionManager._getEffectiveTarget(target, propertyPath);
  21. };
  22. return Condition;
  23. })();
  24. BABYLON.Condition = Condition;
  25. var ValueCondition = (function (_super) {
  26. __extends(ValueCondition, _super);
  27. function ValueCondition(actionManager, target, propertyPath, value, operator) {
  28. if (operator === void 0) { operator = ValueCondition.IsEqual; }
  29. _super.call(this, actionManager);
  30. this.propertyPath = propertyPath;
  31. this.value = value;
  32. this.operator = operator;
  33. this._target = this._getEffectiveTarget(target, this.propertyPath);
  34. this._property = this._getProperty(this.propertyPath);
  35. }
  36. Object.defineProperty(ValueCondition, "IsEqual", {
  37. get: function () {
  38. return ValueCondition._IsEqual;
  39. },
  40. enumerable: true,
  41. configurable: true
  42. });
  43. Object.defineProperty(ValueCondition, "IsDifferent", {
  44. get: function () {
  45. return ValueCondition._IsDifferent;
  46. },
  47. enumerable: true,
  48. configurable: true
  49. });
  50. Object.defineProperty(ValueCondition, "IsGreater", {
  51. get: function () {
  52. return ValueCondition._IsGreater;
  53. },
  54. enumerable: true,
  55. configurable: true
  56. });
  57. Object.defineProperty(ValueCondition, "IsLesser", {
  58. get: function () {
  59. return ValueCondition._IsLesser;
  60. },
  61. enumerable: true,
  62. configurable: true
  63. });
  64. // Methods
  65. ValueCondition.prototype.isValid = function () {
  66. switch (this.operator) {
  67. case ValueCondition.IsGreater:
  68. return this._target[this._property] > this.value;
  69. case ValueCondition.IsLesser:
  70. return this._target[this._property] < this.value;
  71. case ValueCondition.IsEqual:
  72. case ValueCondition.IsDifferent:
  73. var check;
  74. if (this.value.equals) {
  75. check = this.value.equals(this._target[this._property]);
  76. }
  77. else {
  78. check = this.value === this._target[this._property];
  79. }
  80. return this.operator === ValueCondition.IsEqual ? check : !check;
  81. }
  82. return false;
  83. };
  84. // Statics
  85. ValueCondition._IsEqual = 0;
  86. ValueCondition._IsDifferent = 1;
  87. ValueCondition._IsGreater = 2;
  88. ValueCondition._IsLesser = 3;
  89. return ValueCondition;
  90. })(Condition);
  91. BABYLON.ValueCondition = ValueCondition;
  92. var PredicateCondition = (function (_super) {
  93. __extends(PredicateCondition, _super);
  94. function PredicateCondition(actionManager, predicate) {
  95. _super.call(this, actionManager);
  96. this.predicate = predicate;
  97. }
  98. PredicateCondition.prototype.isValid = function () {
  99. return this.predicate();
  100. };
  101. return PredicateCondition;
  102. })(Condition);
  103. BABYLON.PredicateCondition = PredicateCondition;
  104. var StateCondition = (function (_super) {
  105. __extends(StateCondition, _super);
  106. function StateCondition(actionManager, target, value) {
  107. _super.call(this, actionManager);
  108. this.value = value;
  109. this._target = target;
  110. }
  111. // Methods
  112. StateCondition.prototype.isValid = function () {
  113. return this._target.state === this.value;
  114. };
  115. return StateCondition;
  116. })(Condition);
  117. BABYLON.StateCondition = StateCondition;
  118. })(BABYLON || (BABYLON = {}));
  119. //# sourceMappingURL=babylon.condition.js.map