UNPKG

complex-engine

Version:

JS Component Entity Framework for Gamedevelopment

51 lines (43 loc) 966 B
import Manager from '../Manager'; /** * */ class GroupManager extends Manager { constructor() { super(); this.groups = {}; } /** * Add entity to group * @param {Entity} entity * @param {string} groupName */ addToGroup(entity, groupName) { if (!this.groups[groupName]) { this.groups[groupName] = []; } this.groups[groupName].push(entity); } /** * * @param {Entity} entity * @param {string} groupName */ removeFromGroup(entity, groupName) { if (!this.groups[groupName]) { return; } this.groups[groupName] = this.groups[groupName].filter((entry) => { return entry.index !== entity.index; }) } /** * Get a group * @param {string} name * @return {Entity[]} */ getGroup(name) { return this.groups[name] || []; } } export default GroupManager;