Browse Source

Merge pull request #4008 from BabylonJSGuide/master

Commented in two of the action files
David Catuhe 7 years ago
parent
commit
a0b36b01af
3 changed files with 225 additions and 10 deletions
  1. 71 3
      src/Actions/babylon.action.ts
  2. 1 1
      src/Actions/babylon.actionManager.ts
  3. 153 6
      src/Actions/babylon.condition.ts

+ 71 - 3
src/Actions/babylon.action.ts

@@ -1,6 +1,18 @@
 module BABYLON {
+    /**
+     * The action to be carried out following a trigger
+     * @see http://doc.babylonjs.com/how_to/how_to_use_actions#available-actions
+     */
     export class Action {
+        /**
+         * Trigger for the action
+         */
         public trigger: number;
+
+        /**
+         * Internal only - manager for action
+         * @ignore 
+         */
         public _actionManager: ActionManager;
 
         private _nextActiveAction: Action;
@@ -8,8 +20,17 @@
         private _condition?: Condition;
         private _triggerParameter: any;
 
+        /**
+        * An event triggered prior to action being executed.
+        * @type Observable
+        */
         public onBeforeExecuteObservable = new Observable<Action>();
 
+        /**
+         * Creates a new Action
+         * @param triggerOptions the trigger, with or without parameters, for the action
+         * @param condition an optional determinant of action 
+         */
         constructor(public triggerOptions: any, condition?: Condition) {
 
             if (triggerOptions.parameter) {
@@ -23,14 +44,25 @@
             this._condition = condition;
         }
 
-        // Methods
+        /**
+         * Internal only
+         * @ignore 
+         */
         public _prepare(): void {
         }
 
+        /**
+         * Gets the trigger parameters
+         * @returns the trigger parameters
+         */
         public getTriggerParameter(): any {
             return this._triggerParameter;
         }
 
+        /**
+         * Internal only - executes current action event
+         * @ignore 
+         */
         public _executeCurrent(evt?: ActionEvent): void {
             if (this._nextActiveAction._condition) {
                 var condition = this._nextActiveAction._condition;
@@ -59,10 +91,17 @@
             this.skipToNextActiveAction();
         }
 
+        /**
+         * Execute placeholder for child classes
+         * @param evt optional action event
+         */
         public execute(evt?: ActionEvent): void {
 
         }
 
+        /**
+         * Skips to next active action
+         */
         public skipToNextActiveAction(): void {
             if (this._nextActiveAction._child) {
 
@@ -76,6 +115,12 @@
             }
         }
 
+        /**
+         * Adds action to chain of actions, may be a DoNothingAction
+         * @param index The index of the attribute.
+         * @returns The action passed in
+         * @see https://www.babylonjs-playground.com/#1T30HR#0
+         */
         public then(action: Action): Action {
             this._child = action;
 
@@ -85,18 +130,33 @@
             return action;
         }
 
+        /**
+         * Internal only
+         * @ignore 
+         */
         public _getProperty(propertyPath: string): string {
             return this._actionManager._getProperty(propertyPath);
         }
 
+        /**
+         * Internal only
+         * @ignore 
+         */
         public _getEffectiveTarget(target: any, propertyPath: string): any {
             return this._actionManager._getEffectiveTarget(target, propertyPath);
         }
         
+        /**
+         * Serialize placeholder for child classes
+         * @param parent of child
+         */
         public serialize(parent: any): any {
         }
         
-        // Called by BABYLON.Action objects in serialize(...). Internal use
+        /**
+         * Internal only called by serialize
+         * @ignore 
+         */
         protected _serialize(serializedAction: any, parent?: any): any {
             var serializationObject: any = { 
                 type: 1,
@@ -127,6 +187,10 @@
             return serializationObject;
         }
         
+        /**
+         * Internal only
+         * @ignore 
+         */
         public static _SerializeValueAsString = (value: any): string => {
             if (typeof value === "number") {
                 return value.toString();
@@ -152,7 +216,11 @@
             
             return value; // string
         };
-    
+        
+        /**
+         * Internal only
+         * @ignore 
+         */
         public static _GetTargetProperty = (target: Scene | Node) => {
             return {
                 name: "target",

+ 1 - 1
src/Actions/babylon.actionManager.ts

@@ -1,7 +1,7 @@
 module BABYLON {
 
     /**
-     * ActionEvent is the event beint sent when an action is triggered.
+     * ActionEvent is the event being sent when an action is triggered.
      */
     export class ActionEvent {
         /**

+ 153 - 6
src/Actions/babylon.condition.ts

@@ -1,29 +1,67 @@
 module BABYLON {
+    /**
+     * A Condition applied to an Action 
+     */
     export class Condition {
+        /**
+         * Internal only - manager for action
+         * @ignore 
+         */
         public _actionManager: ActionManager;
 
+        /**
+         * Internal only
+         * @ignore 
+         */
         public _evaluationId: number;
+
+        /**
+         * Internal only
+         * @ignore 
+         */
         public _currentResult: boolean;
 
+        /**
+         * Creates a new Condition
+         * @param actionManager the manager of the action the condition is applied to 
+         */
         constructor(actionManager: ActionManager) {
             this._actionManager = actionManager;
         }
 
+        /**
+         * Check if the current condition is valid
+         */
         public isValid(): boolean {
             return true;
         }
 
+        /**
+         * Internal only 
+         * @ignore 
+         */
         public _getProperty(propertyPath: string): string {
             return this._actionManager._getProperty(propertyPath);
         }
 
+        /**
+         * Internal only 
+         * @ignore 
+         */
         public _getEffectiveTarget(target: any, propertyPath: string): any {
             return this._actionManager._getEffectiveTarget(target, propertyPath);
         }
         
+        /**
+         * Serialize placeholder for child classes
+         */
         public serialize(): any {
         }
         
+        /**
+         * Internal only 
+         * @ignore 
+         */
         protected _serialize(serializedCondition: any): any {
             return { 
                 type: 2, // Condition
@@ -34,36 +72,95 @@
         }
     }
 
+    /**
+     * Defines specific conditional operators as extensions of Condition
+     */
     export class ValueCondition extends Condition {
-        // Statics
+        
+        /**
+         * Internal only 
+         * @ignore 
+         */
         private static _IsEqual = 0;
+
+        /**
+         * Internal only 
+         * @ignore 
+         */
         private static _IsDifferent = 1;
+
+        /**
+         * Internal only 
+         * @ignore 
+         */
         private static _IsGreater = 2;
+
+        /**
+         * Internal only 
+         * @ignore 
+         */
         private static _IsLesser = 3;
 
+        /**
+         * @returns the number for IsEqual
+         */
         public static get IsEqual(): number {
             return ValueCondition._IsEqual;
         }
 
+        /**
+         * @returns the number for IsDifferent
+         */
         public static get IsDifferent(): number {
             return ValueCondition._IsDifferent;
         }
 
+        /**
+         * @returns the number for IsGreater
+         */
         public static get IsGreater(): number {
             return ValueCondition._IsGreater;
         }
 
+        /**
+         * @returns the number for IsLesser
+         */
         public static get IsLesser(): number {
             return ValueCondition._IsLesser;
         }
 
-        // Members
+        /**
+         * Internal only The action manager for the condition
+         * @ignore 
+         */
         public _actionManager: ActionManager;
 
+        /**
+         * Internal only 
+         * @ignore 
+         */
         private _target: any;
+
+        /**
+         * Internal only 
+         * @ignore 
+         */
         private _effectiveTarget: any;
+
+        /**
+         * Internal only 
+         * @ignore 
+         */
         private _property: string;
 
+        /**
+         * Creates a new ValueCondition
+         * @param actionManager manager for the action the condition applies to
+         * @param target for the action
+         * @param propertyPath path to specify the property of the target the conditional operator uses 
+         * @param value the vale compared by the conditional operator against the current value of the property
+         * @param operator the conditional operator, default {BABYLON.ValueCondition.IsEqual}  
+         */
         constructor(actionManager: ActionManager, target: any, public propertyPath: string, public value: any, public operator: number = ValueCondition.IsEqual) {
             super(actionManager);
 
@@ -72,7 +169,10 @@
             this._property = this._getProperty(this.propertyPath);
         }
 
-        // Methods
+        /**
+         * Compares the given value with the property value for the specified conditional operator
+         * @returns the result of the comparison
+         */
         public isValid(): boolean {
             switch (this.operator) {
                 case ValueCondition.IsGreater:
@@ -94,6 +194,10 @@
             return false;
         }
         
+        /**
+         * Serialize the ValueCondition into a JSON compatible object
+         * @returns serialization object
+         */
         public serialize(): any {
             return this._serialize({
                name: "ValueCondition",
@@ -106,6 +210,11 @@
             });
         }
         
+        /**
+         * Gets the name of the conditional operator for the ValueCondition
+         * @param operator the conditional operator
+         * @returns the name 
+         */
         public static GetOperatorName(operator: number): string {
             switch (operator) {
                 case ValueCondition._IsEqual: return "IsEqual";
@@ -117,37 +226,75 @@
         }
     }
 
+    /**
+     * Defines a predicate condition as an extension of Condition
+     */
     export class PredicateCondition extends Condition {
-        // Members
+        
+        /**
+         * Internal only - manager for action
+         * @ignore 
+         */
         public _actionManager: ActionManager;
 
 
+        /**
+         * Creates a new {BABYLON.PredicateCondition}
+         * @param actionManager manager for the action the condition applies to
+         * @param predicate 
+         */
         constructor(actionManager: ActionManager, public predicate: () => boolean) {
             super(actionManager);
         }
 
+        /**
+         * @returns the validity of the predicate condition
+         */
         public isValid(): boolean {
             return this.predicate();
         }
     }
 
+    /**
+     * Defines a state condition as an extension of {BABYLON.Condition}
+     */
     export class StateCondition extends Condition {
-        // Members
+        
+        /**
+         * Internal only - manager for action
+         * @ignore 
+         */
         public _actionManager: ActionManager;
 
+        /**
+         * Internal only
+         * @ignore 
+         */
         private _target: any;
 
+        /**
+         * Creates a new {BABYLON.StateCondition}
+         * @param actionManager manager for the action the condition applies to
+         * @param target of the condition
+         * @param value to compare with target state 
+         */
         constructor(actionManager: ActionManager, target: any, public value: string) {
             super(actionManager);
 
             this._target = target;
         }
 
-        // Methods
+        /**
+         * @returns the validity of the state
+         */
         public isValid(): boolean {
             return this._target.state === this.value;
         }
         
+        /**
+         * Serialize the {BABYLON.StateCondition} into a JSON compatible object
+         * @returns serialization object
+         */
         public serialize(): any {
             return this._serialize({
                name: "StateCondition",