Node Script

Vec2 Array To Console

Downloads: 25
Download
Ads Support FTD

Description

Outputs a Vec2 Array to the console

//
// --------------------------------------------------------
// Vec2ArrayToConsole
// Outputs a Vector2f Array to the console
// Written by @FusedThreeD – https://FusedThreeD.com
// --------------------------------------------------------
//

@customNode()
export class LogVec2Array extends BasicScriptNode {

  @input()
  Vec2_Array: APJS.Vector2f[];

  // Name/label shown in console
  @input()
  Array_Name: string = "Vec2 Array";

  @input()
  Log_On: boolean = true;

  // true = one line, false = separate lines
  @input()
  One_Line: boolean = false;

  // true = pretty print, false = normal print
  @input()
  Pretty_Print: boolean = true;

  private formatVec2(v: APJS.Vector2f): string {
    if (!v) {
      return "(null)";
    }
    return `(${v.x}, ${v.y})`;
  }

  execute() {

    if (!this.Log_On) {
      return;
    }

    if (!this.Vec2_Array || this.Vec2_Array.length === 0) {
      if (this.Pretty_Print) {
        console.log(`┌─ ${this.Array_Name}`);
        console.log(` (empty or undefined)`);
        console.log(`└────────────`);
      } else {
        console.log(`${this.Array_Name}: array is empty or undefined`);
      }
      return;
    }

    // ONE LINE
    if (this.One_Line) {

      const line = this.Vec2_Array
        .map(v => this.formatVec2(v))
        .join(", ");

      if (this.Pretty_Print) {
        console.log(`┌─START ${this.Array_Name}[${this.Vec2_Array.length}]`);
        console.log(line);
        console.log(`└─END ${this.Array_Name}`);
      } else {
        console.log(`${this.Array_Name}: ${line}`);
      }

      return;
    }

    // MULTI LINE
    if (this.Pretty_Print) {
      console.log(`┌─START ${this.Array_Name}[${this.Vec2_Array.length}]`);
      for (let i = 0; i < this.Vec2_Array.length; i++) {
        console.log(`[${i}] ${this.formatVec2(this.Vec2_Array[i])}`);
      }
      console.log(`└─END ${this.Array_Name}`);
    } else {
      console.log(`${this.Array_Name}:`);
      for (let i = 0; i < this.Vec2_Array.length; i++) {
        console.log(`  [${i}] ${this.formatVec2(this.Vec2_Array[i])}`);
      }
    }
  }
}
Ads Support FTD