GodotECS / godex

Godex is a Godot Engine ECS library.
MIT License
1.22k stars 67 forks source link

Add `Create` filter. #264

Closed AndreaCatania closed 3 years ago

AndreaCatania commented 3 years ago

This filter is useful when you want to create a component for the entities that match the query.

Let's suppose you have a Car component, and you want that by default the entities with such component have also the FuelTank component. Instead of letting the user to manually add it, you can use the Create filter: godex will create and add the component if doesn't exist.

void move_car(Query<Car, Create<FuelTank>> &p_query) {
    for(auto [car, fuel_tank] : p_query) {
        if(fuel_tank.fuel_level > 0.0) {
            // Move the car
        }
    }
}

This filter is an ergonomic improvements, the user can just add the Car component and not know about FuelTank at all.