const { ccclass, property } = cc._decorator;

@ccclass
export default class Utils extends cc.Component {
  public static BACKGROUND_WHITE_COLOR: string = "ebfaff";

  public static worldSpaceToLocal(worldSpace: cc.Vec2, local: Node) {}

  public static getRandomRainbowColor(): cc.Color {
    var primaryColor = this.random(0, 2);
    var secondaryColor = this.random(0, 2);
    var colorAsArray = [0, 0, 0];
    colorAsArray[secondaryColor] = this.random(0, 255);
    colorAsArray[primaryColor] = 255;

    return cc.color(colorAsArray[0], colorAsArray[1], colorAsArray[2]);
  }

  public static getOneOrMinusOne() {
    return this.random(0, 1) == 1 ? 1 : -1;
  }

  public static Vec2ToAngle(vec2: cc.Vec2): number {
    return (Math.atan2(vec2.y, vec2.x) * 180) / Math.PI;
  }

  public static RotateVec2Clockwise(vec2: cc.Vec2): cc.Vec2 {
    return cc.v2(vec2.y, -vec2.x);
  }

  public static RotateVec2CounterClockwise(vec2: cc.Vec2): cc.Vec2 {
    return cc.v2(-vec2.y, vec2.x);
  }

  public static random(minInclusive: number, maxInclusive: number): number {
    return (
      Math.floor(Math.random() * (maxInclusive - minInclusive + 1)) +
      minInclusive
    );
  }

  public static booleanRandom(
    trueChance: number = 1,
    totalChance: number = 1
  ): boolean {
    if (this.random(0, totalChance) <= trueChance) return true;
    else return false;
  }
}
