UNPKG

duckengine

Version:
141 lines (140 loc) 4.04 kB
import { Duck } from '../../index'; import Game from '../game'; /** * @class Group * @classdesc Creates a DuckEngine Group * @description The Group Class. Contains and manages a group of items * @template t Stack Item type generic * @since 1.0.0-beta */ export default class Group<t> { protected stack: t[]; /** * @memberof Group * @description Game instance * @type Game * @since 1.0.0-beta */ game: Game; /** * @memberof Group * @description Group name * @type string * @since 1.0.0-beta */ readonly name: string; /** * @constructor * @description Creates a Group instance. * @param {string} name Name of group * @param {Game} game Game instance * @param {t[]} [defaultItems=[]] Default items, optional -> defaults: [] * @since 1.0.0-beta */ constructor(name: string, game: Game, defaultItems?: t[]); /** * @memberof Group * @description Adds an item to the Group * @param {t} item Item to add * @emits EVENTS.GROUP.ADD * @since 1.0.0-beta */ add(item: t): void; /** * @memberof Group * @description Removes an item from the Group * @param {t} item Item to remove * @emits EVENTS.GROUP.REMOVE * @since 1.0.0-beta */ remove(item: t): void; /** * @memberof Group * @description Finds an item in the Group * @param {t} item Item to find * @since 1.0.0-beta */ find(item: t): t | undefined; /** * @memberof Group * @description Gets the index of an item from the Group list array * @param {t} item Item to find the index of * @since 1.0.0-beta */ indexOf(item: t): number; /** * @memberof Group * @description Loops through each item in the Group array * @param {(item: t, index: number) => void} cb Callback function * @since 1.0.0-beta */ each(cb: (item: t, index: number) => void): void; /** * @memberof Group * @description Pops an item from the Group array * @returns {t | undefined} * @since 1.0.0-beta */ pop(): t | undefined; /** * @memberof Group * @description Shifts an item from the Group array * @returns {t | undefined} * @since 1.0.0-beta */ shift(): t | undefined; /** * @memberof Group * @description Splices an item from the Group array * @param {number} index Index to splice at * @param {number} [deleteCount] How many items to remove, optional * @returns {t[]} * @since 1.0.0-beta */ splice(index: number, deleteCount?: number): t[]; /** * @memberof Group * @description Filters items from the Group * @param {Duck.Types.Group.Filter} filter Filter string * @returns {t[]} * @since 1.0.0-beta */ filter(filter: Duck.Types.Group.Filter): t[]; /** * @memberof Group * @description Adds an event listener to Group * @param {Duck.Types.Group.ListenerType} type Listener type * @param {() => unknown} cb Callback function * @since 1.0.0-beta */ on(type: Duck.Types.Group.ListenerType, cb: () => unknown): void; /** * @memberof Group * @description Removes an event listener from Group * @param {Duck.Types.Group.ListenerType} type Listener type * @since 1.0.0-beta */ off(type: Duck.Types.Group.ListenerType): void; /** * @memberof Group * @description Returns an item or undefined at a specified index * @param {number} index The index to return a value from, 0-based like an array * @returns {t | undefined} * @since 2.1.0 */ at(index: number): t | undefined; /** * @memberof Group * @description Returns the array * @returns {t[]} * @since 1.0.0-beta */ get group(): t[]; /** * @memberof Group * @description Returns the length of the array * @returns {number} * @since 1.0.0-beta */ get length(): number; }