Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to get signal that fires once a collection of components are present #40

Open
Nimblz opened this issue Nov 7, 2019 · 0 comments
Assignees
Labels
area-components Component-related APIs enhancement New feature or request

Comments

@Nimblz
Copy link
Contributor

Nimblz commented Nov 7, 2019

A common pattern I've dropped into when making systems is listening and checking for multiple components being added. An example of this is an animation system, which requires access to the AI and Rig components of an entity. To do this right now, you have to listen to the addition of all components you need to reason with, then check that all components exist in a component added method.

function AnimationSystem:onDependencyAdded(instance)
    local rig = self.core:getComponent(instance, RecsComponents.Rig)
    local ai = self.core:getComponent(instance, RecsComponents.AI)

    if rig and ai then
        -- do stuff
    end
end

function AnimationSystem:init()
    for instance in self.core:components(RecsComponents.Rig, RecsComponents.AI) do
        self:onDependencyAdded(instance)
    end

    self.core:getComponentAddedSignal(RecsComponents.Rig):connect(function(instance)
        self:onDependencyAdded(instance)
    end)
    self.core:getComponentAddedSignal(RecsComponents.AI):connect(function(instance)
        self:onDependencyAdded(instance)
    end)
end

Some equivalent to getComponentAddedSignal(identifier) that accepts multiple identifiers and only fires when all exist would clean this pattern up.

@Phalanxia Phalanxia self-assigned this Apr 8, 2022
@Phalanxia Phalanxia added enhancement New feature or request area-components Component-related APIs labels Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-components Component-related APIs enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants