babylon.action.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. module BABYLON {
  2. export class Action {
  3. public trigger: number;
  4. public _actionManager: ActionManager;
  5. private _nextActiveAction: Action;
  6. private _child: Action;
  7. private _condition: Condition;
  8. private _triggerParameter: any;
  9. constructor(public triggerOptions: any, condition?: Condition) {
  10. if (triggerOptions.parameter) {
  11. this.trigger = triggerOptions.trigger;
  12. this._triggerParameter = triggerOptions.parameter;
  13. } else {
  14. this.trigger = triggerOptions;
  15. }
  16. this._nextActiveAction = this;
  17. this._condition = condition;
  18. }
  19. // Methods
  20. public _prepare(): void {
  21. }
  22. public getTriggerParameter(): any {
  23. return this._triggerParameter;
  24. }
  25. public _executeCurrent(evt: ActionEvent): void {
  26. if (this._nextActiveAction._condition) {
  27. var condition = this._nextActiveAction._condition;
  28. var currentRenderId = this._actionManager.getScene().getRenderId();
  29. // We cache the current evaluation for the current frame
  30. if (condition._evaluationId === currentRenderId) {
  31. if (!condition._currentResult) {
  32. return;
  33. }
  34. } else {
  35. condition._evaluationId = currentRenderId;
  36. if (!condition.isValid()) {
  37. condition._currentResult = false;
  38. return;
  39. }
  40. condition._currentResult = true;
  41. }
  42. }
  43. this._nextActiveAction.execute(evt);
  44. if (this._nextActiveAction._child) {
  45. if (!this._nextActiveAction._child._actionManager) {
  46. this._nextActiveAction._child._actionManager = this._actionManager;
  47. }
  48. this._nextActiveAction = this._nextActiveAction._child;
  49. } else {
  50. this._nextActiveAction = this;
  51. }
  52. }
  53. public execute(evt: ActionEvent): void {
  54. }
  55. public then(action: Action): Action {
  56. this._child = action;
  57. action._actionManager = this._actionManager;
  58. action._prepare();
  59. return action;
  60. }
  61. public _getProperty(propertyPath: string): string {
  62. return this._actionManager._getProperty(propertyPath);
  63. }
  64. public _getEffectiveTarget(target: any, propertyPath: string): any {
  65. return this._actionManager._getEffectiveTarget(target, propertyPath);
  66. }
  67. }
  68. }