Skip to content

Category

hhh edited this page Feb 5, 2022 · 1 revision

Category

/**
 * Type of category tags.
 */
type CategoryTag = string | symbol;

/**
 * Type of category records.
 */
type CategoryRecord = [CategoryTag, number];

/**
 * Type of `Category` namespace.
 */
interface CategoryNamespace {
    /**
     * Max count of categories. (32)
     */
    readonly MAX_COUNT: number;
    /**
     * Full category mask. (0xFFFF_FFFF)
     */
    readonly FULL_MASK: number;
    /**
     * Category registry.
     * (Used by `Category.for` & `Category.tagFor`.)
     */
    registry: CategoryRecord[];
    /**
     * Current count of categories.
     */
    count: number;
    /**
     * Get next category.
     */
    readonly next: () => number;
    /**
     * Get a tagged category.
     */
    readonly for: (tag: CategoryTag) => number;
    /**
     * Get the tag of specific category.
     */
    readonly tagFor: (category: number) => CategoryTag | undefined;
}

/**
 * Category-related APIs.
 */
const Category: CategoryNamespace;
Clone this wiki locally