/**
 * 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);
    }

}
