babylon.condition.js 4.5 KB

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