Create a new BitMask instance.

Param: states

An object containing valid states and their corresponding initial boolean values (default is null).

Hierarchy

  • Number
    • BitMask

Properties

states: Record<string, string>

The enum associated with this structure.

#value: number

The real value behind the bitmask instance.

#validStates: Map<string, number>

The structure of valid states and their associated values.

Accessors

  • get isEmpty(): boolean
  • True if this bitmask is empty (no active states).

    Returns boolean

Methods

  • Check if a specific state is active.

    Parameters

    • state: string

      The state to check.

    Returns boolean

    True if the state is active, false otherwise.

  • Add a state to the bitmask.

    Parameters

    • state: string

      The state to add.

    Returns void

    Throws

    Throws an error if the provided state is not valid.

  • Remove a state from the bitmask.

    Parameters

    • state: string

      The state to remove.

    Returns void

    Throws

    Throws an error if the provided state is not valid.

  • Toggle the state of a specific state in the bitmask.

    Parameters

    • state: string

      The state to toggle.

    • Optional enabled: boolean

      Toggle on (true) or off (false)? If undefined, the state is switched automatically.

    Returns number

    Throws

    Throws an error if the provided state is not valid.

  • Clear the bitmask, setting all states to inactive.

    Returns void

  • Get the current value of the bitmask.

    Returns number

    The current value of the bitmask.

  • Get a string representation of the bitmask in binary format.

    Returns string

    The string representation of the bitmask.

  • Checks if two bitmasks structures are compatible (the same valid states).

    Parameters

    • otherBitMask: BitMask

      The bitmask structure to compare with.

    Returns boolean

    True if the two bitmasks have the same structure, false otherwise.

  • Serializes the bitmask to a JSON string.

    Returns string

    The JSON string representing the bitmask.

  • Convert value of this BitMask to object representation according to structure.

    Returns Object

    The data represented by the bitmask.

  • Creates a clone of this BitMask instance.

    Returns BitMask

    A new BitMask instance with the same value and valid states as this instance.

  • Generates the valid states and their associated values.

    Parameters

    • Optional states: Record<string, boolean>

      The structure defining the valid states and their associated values.

    Returns void

  • Generates an enum based on the provided valid states.

    Returns void

  • Calculate the default value of the bitmask based on the initial states

    Parameters

    • Optional initialStates: Record<string, boolean> = {}

      The structure defining the valid states and their associated values.

    Returns number

  • Checks a state and throws an error if it doesn't exist.

    Parameters

    • state: string

      Name of the state to check.

    Returns void

  • Creates a new BitMask instance from a JSON string.

    Parameters

    • jsonString: string

      The JSON string representing the bitmask.

    Returns BitMask

    A new BitMask instance created from the JSON string.

  • Generates shader constants based on the provided states.

    Parameters

    • states: string[]

      An array containing valid states.

    Returns string

    Shader bit mask constants generated from the states.