babylon.condition.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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._getTarget = function (targetType, targetName) {
  17. return this._actionManager._getTarget(targetType, targetName);
  18. };
  19. Condition.prototype._getProperty = function (propertyPath) {
  20. return this._actionManager._getProperty(propertyPath);
  21. };
  22. Condition.prototype._getEffectiveTarget = function (target, propertyPath) {
  23. return this._actionManager._getEffectiveTarget(target, propertyPath);
  24. };
  25. return Condition;
  26. })();
  27. BABYLON.Condition = Condition;
  28. var StateCondition = (function (_super) {
  29. __extends(StateCondition, _super);
  30. function StateCondition(actionManager, targetType, targetName, propertyPath, value, operator) {
  31. if (typeof operator === "undefined") { operator = StateCondition.IsEqual; }
  32. _super.call(this, actionManager);
  33. this.targetType = targetType;
  34. this.targetName = targetName;
  35. this.propertyPath = propertyPath;
  36. this.value = value;
  37. this.operator = operator;
  38. this._target = this._getTarget(this.targetType, this.targetName);
  39. this._target = this._getEffectiveTarget(this._target, this.propertyPath);
  40. this._property = this._getProperty(this.propertyPath);
  41. }
  42. // Methods
  43. StateCondition.prototype.isValid = function () {
  44. switch (this.operator) {
  45. case StateCondition.IsGreater:
  46. return this._target[this._property] > this.value;
  47. case StateCondition.IsLesser:
  48. return this._target[this._property] < this.value;
  49. case StateCondition.IsEqual:
  50. case StateCondition.IsDifferent:
  51. var check;
  52. if (this.value.equals) {
  53. check = this.value.equals(this._target[this._property]);
  54. } else {
  55. check = this.value === this._target[this._property];
  56. }
  57. return this.operator === StateCondition.IsEqual ? check : !check;
  58. }
  59. return false;
  60. };
  61. StateCondition.IsEqual = 0;
  62. StateCondition.IsDifferent = 1;
  63. StateCondition.IsGreater = 2;
  64. StateCondition.IsLesser = 3;
  65. return StateCondition;
  66. })(Condition);
  67. BABYLON.StateCondition = StateCondition;
  68. var PredicateCondition = (function (_super) {
  69. __extends(PredicateCondition, _super);
  70. function PredicateCondition(actionManager, predicate) {
  71. _super.call(this, actionManager);
  72. this.predicate = predicate;
  73. }
  74. PredicateCondition.prototype.isValid = function () {
  75. return this.predicate();
  76. };
  77. return PredicateCondition;
  78. })(Condition);
  79. BABYLON.PredicateCondition = PredicateCondition;
  80. })(BABYLON || (BABYLON = {}));
  81. //# sourceMappingURL=babylon.condition.js.map