UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

33 lines (26 loc) 892 B
/** * Remove all components from an entity except the specified whitelist * @param {EntityComponentDataset} ecd * @param {number} entity * @param {Array} whitelist */ export function removeComponentsExcept(ecd, entity, whitelist) { const exception_count = whitelist.length; const components = ecd.getAllComponents(entity); const component_count = components.length; l0:for (let i = 0; i < component_count; i++) { const component = components[i]; if (component === undefined) { // not set continue; } for (let i = 0; i < exception_count; i++) { if (component instanceof whitelist[i]) { //keep continue l0; } } //not in the whitelist, remove ecd.removeComponentFromEntityByIndex(entity, i); } }