https://kotlinlang.org logo
#korge
Title
# korge
j

jeff

12/21/2020, 2:29 AM
Is there no way to list all components attached to a view?
d

Deactivated User

12/21/2020, 11:29 AM
What do you want to achieve with that/what's your use-case?
j

jeff

12/21/2020, 6:42 PM
Let's say I have 2 views shipA and shipB. I add some
FollowComponent
to shipA that tells it to follow shipB. Later something changes and I want to do
shipA.getComponent<FollowComponent>().target = shipC
I have that implemented this way, but it seemed a bit hacky...
Copy code
inline fun <reified T : Component> BaseView.getComponent(): T {
    return getOrCreateComponentOther<T> { error("No component of type ${T::class.simpleName}") }
}
d

Deactivated User

12/26/2020, 2:53 PM
So you don't need to iterate all the components, but to get a component that should be existing already, or throw an exception if it is not the case, right?
j

jeff

12/26/2020, 5:20 PM
Correct (for my specific case)
2 Views