Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "src/subsystem/system.behavior"

Index

Variables

Const behaviorCreationError

behaviorCreationError: string = "behavior_creation_error"

Behavior creation error, returned by [[Behavior.addBehavior]].

Functions

addBehavior

  • Adds a behavior to the behavior class instance.

    Note

    Does not check for inconsistencies within ID and index arrays, as if it is internally managed by this class, inconsistencies should not happen.

    Usage

    // Create a new instance of Behavior
    var behavior = new Behavior();
    
    // Add a behavior
    behavior.addBehavior("hello_behavior", () => console.log("Hello World"));

    Parameters

    Returns Promise<string>

    ID of the behavior; behaviorCreationError if creation failed

addBehaviors

  • Adds behaviors to the system, and fires post-addtion events. Firstly, this function attempts to add the behaviors. When the behavior addition has been processed, the function will attempt to fire post-addition events, depending on success/failure of behavior additions.

    instance
    fires

    module:system.private#events#behaviorAttach

    fires

    module:system.private#events#behaviorAttachFail

    fires

    module:system.private#events#behaviorAttachRequestFail Usage

    var options = {
      id: "lab_inventory",
      rootDir: "labs",
      relativeInitDir: "black_mesa",
      initFilename: "inventory.yml",
      logging: console
    };
    var behavior = {
      "check_inventory": () => {
        // Behavior functionality
        // ...
      }
    }
    
    var labInventory = new System(options);
    labInventory.addBehaviors([behavior]).then(function(){
      console.log("Behavior added.");
    });

    Parameters

    Returns Promise<void>

behave

  • behave(this: Behavior, name: string): void
  • Triggers behaviors registered for name.

    Usage

    // Create a new instance of Behavior
    var behavior = new Behavior();
    
    // Add a behavior
    behavior.addBehavior("hello_behavior", () => console.log("Hello World"));
    
    // Call a behavior
    behavior.behave("hello_behavior");
    
    // Output:
    // "Hello World"

    Parameters

    • this: Behavior
    • name: string

      Behavior name

    Returns void

fire

  • fire(this: Behavior, name: string, message?: undefined | string): void
  • Fires a system event

    Parameters

    • this: Behavior
    • name: string

      Event name, as specified in {@link module:system.private#events}.

    • Optional message: undefined | string

      Message is not strictly required, but preferred. If not specified, will assume value of the name // TODO: @event module:system.private#events#eventFail // TODO: Throws {external:Error} Will throw error_hell. The inability to process error - if {@link module:system.private#events#event:eventFail} event fails.

      Usage

      var options = {
        id: "lab_inventory",
        rootDir: "labs",
        relativeInitDir: "black_mesa",
        initFilename: "inventory.yml",
        logging: "console"
      };
      
      var labInventory = new System(options);
      labInventory.fire("system_load_aux", "Auxiliary system loaded.");

    Returns void

Generated using TypeDoc