/*
ecsjs is an entity component system library for JavaScript
Copyright (C) 2014 Peter Flannery
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
/**
* Property key used for ComponentMap identification during serialization
* @category Constants
*/
export const ComponentMapKey = "ComponentMap"
/**
* Property key used for ComponentClassesMap identification during serialization
* @category Constants
*/
export const ComponentClassesMapKey = "ComponentClassesMap"
/**
* Variadic type helper that preserves the strongly typed parameter interfaces used by the compiler and intellisense.
* Works with single returned types or spread array returned types.
* @category Types
*/
export type SingleOrArray =
// return a single variadic item when only 1 item is specified
T['length'] extends 1 ? T[0]
// otherwise return an array of variadic types
: { [Index in keyof T]: T[Index] }
/**
* Used to return component instance data.
*
* Note: This is not used for registering components or extending component classes
* @category Types
*/
export interface Component { }
/**
* @category Types
* @example
*
* class PositionComponent {
* constructor(x, y) {
* this.x = x;
* this.y = y;
* }
* }
*/
export type ComponentClass = (new (...args: any[]) => ComponentInstance) & {
// static property
hashId?: number;
};
/**
* Used for inferring generic type spread for classes
* @category Types
*/
export type ComponentClasses =
{ [Index in keyof T]: ComponentClass }
/**
* Custom iterator interface that includes a reset function
* @category Types
*/
export type Iterator = {
/**
* Gets the next result in the iteration
*/
next: () => IteratorResult
/**
* Resets the iterator back to the beginning
*/
reset: () => void
/**
* Returns the iterator instance
*/
[Symbol.iterator]: () => Iterator
}
/**
* Helper type for late-bound iterator assignment with IntelliSense support
* @category Types
* @example
*
* let someIterator: IComponentIterator<[Player, Position]>
*
* // assignment made somewhere else in the code
* const [player, position] = someIterator(Player, Position) ?? []
* position?.x = 123 // position will have IntelliSense
*/
export type IComponentIterator
= Iterator>