Replies: 5 comments 17 replies
-
You're not missing anything, that's actually an interesting idea to expand the Ashley DSL. @Jkly has designed the @pylvain, would you like to submit a pull request? |
Beta Was this translation helpful? Give feedback.
-
Listening to your suggestion, I wrote the following function : inline fun < reified T : Component> propertyFor() = MapperDelegate<T>(mapperFor<T>())
var Entity.location by propertyFor<Location>() Which is indeed much nicer. |
Beta Was this translation helpful? Give feedback.
-
This functionality was added in #422. Thanks again for the suggestion and implementation, @pylvain! |
Beta Was this translation helpful? Give feedback.
-
I never used delegation so far, I think. How does the generated byte code look like, that would be my only concern because you want to have your component access as fast as possible. It looks very similar to the approach that I always used where I was wondering if there is a way to have a general solution, and it looks like there is with this delegation approach! Here is an example how I did it for every necessary component: class StateComponent: Component {
companion object {
val MAPPER = mapperFor<StateComponent>()
}
}
/**
* Returns a [StateComponent] or throws a [GdxRuntimeException] if it doesn't exist.
*/
val Entity.stateCmp: StateComponent
get() = this[StateComponent.MAPPER]
?: throw GdxRuntimeException("StateComponent for entity '$this' is null") |
Beta Was this translation helpful? Give feedback.
-
I added a tag functionality, in the same spirit : class Visible : Component
var Entity.isVisible:Boolean by tag<Visible>() The val engine = Engine()
val e = Entity()
engine.addEntity(e)
println(e.isVisible) // false
e.isVisible = true
println(e.isVisible) // true
e.isVisible = false
println(e.isVisible) //false I will be happy to submit another pull request if you want me to |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm surprised that the many conveniences ashley.ktx offers don't contain property delegates to simplify components access. We can declare the following delegate :
With a simple component, we can then do that :
And then using it like that
Is this a good idea, or am I missing something ?
Beta Was this translation helpful? Give feedback.
All reactions