babylon.condition.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 StateCondition = (function (_super) {
  26. __extends(StateCondition, _super);
  27. function StateCondition(actionManager, target, propertyPath, value, operator) {
  28. if (typeof operator === "undefined") { operator = StateCondition.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. // Methods
  37. StateCondition.prototype.isValid = function () {
  38. switch (this.operator) {
  39. case StateCondition.IsGreater:
  40. return this._target[this._property] > this.value;
  41. case StateCondition.IsLesser:
  42. return this._target[this._property] < this.value;
  43. case StateCondition.IsEqual:
  44. case StateCondition.IsDifferent:
  45. var check;
  46. if (this.value.equals) {
  47. check = this.value.equals(this._target[this._property]);
  48. } else {
  49. check = this.value === this._target[this._property];
  50. }
  51. return this.operator === StateCondition.IsEqual ? check : !check;
  52. }
  53. return false;
  54. };
  55. StateCondition.IsEqual = 0;
  56. StateCondition.IsDifferent = 1;
  57. StateCondition.IsGreater = 2;
  58. StateCondition.IsLesser = 3;
  59. return StateCondition;
  60. })(Condition);
  61. BABYLON.StateCondition = StateCondition;
  62. var PredicateCondition = (function (_super) {
  63. __extends(PredicateCondition, _super);
  64. function PredicateCondition(actionManager, predicate) {
  65. _super.call(this, actionManager);
  66. this.predicate = predicate;
  67. }
  68. PredicateCondition.prototype.isValid = function () {
  69. return this.predicate();
  70. };
  71. return PredicateCondition;
  72. })(Condition);
  73. BABYLON.PredicateCondition = PredicateCondition;
  74. })(BABYLON || (BABYLON = {}));
  75. //# sourceMappingURL=babylon.condition.js.map