Ray Rahke
05/09/2024, 3:54 PMval (foo, bar, qux) = Context.getInstances(Foo::class, Bar::class, Qux::class)
Joffrey
05/09/2024, 3:56 PMgetInstances()
return a list, or anything that has componentN()
functionsGleb Minaev
05/09/2024, 4:06 PMcomponentN
manually for the result of getInstance
function. If it is even possible.ephemient
05/09/2024, 4:37 PMephemient
05/09/2024, 4:39 PMdata class ThreeInstances<One, Two, Three>(val one: One, val two: Two, val three: Three)
object Context {
fun getInstances<One : Any, Two : Any, Three : Any>(one: KClass<One>, two: KClass<Two>, three: KClass<Three>): ThreeInstances<One, Two, Three>
}
ephemient
05/09/2024, 4:42 PMinline fun <reified T : Any> Context.getValue(thisRef: Any?, property: KProperty<T>): T
val foo: Foo by Context
val bar: Bar by Context
val qux: Qux by Context
Ray Rahke
05/11/2024, 8:27 AMRay Rahke
05/11/2024, 8:27 AMRay Rahke
05/11/2024, 8:32 AMJoffrey
05/11/2024, 8:40 AMAny
for everything, so yeah it doesn't solve your problem.Joffrey
05/11/2024, 8:41 AMRay Rahke
05/11/2024, 8:49 AMval (physics, graphics, health) = entity.getComponents(Physics::class, Graphics::class, Health::class)
this is not hard to visually map types and has better readability then manually doing 3 val
assignments (in terms of speed, important metric in readability)Ray Rahke
05/11/2024, 8:50 AMval x = getComponents(X::class)
pattern, so you learn to ignore the right hand side of the equation etc.Ray Rahke
05/11/2024, 8:50 AMRay Rahke
05/11/2024, 8:50 AMRay Rahke
05/11/2024, 8:51 AMRay Rahke
05/11/2024, 8:57 AMx
val, by getting component X
.
next we have a y
val, by getting component Y
then a z
component, by getting component Z
"
that is a lot of distinct steps your brain has to parse.
versus
2:
"Okay we will have components x,y,z
by getting components X
,Y
,Z
that 2nd sort of expression is easier on the brainJoffrey
05/11/2024, 11:04 AMa - b - c = A - B - C
Or
a - A
b - B
c - C
You'll process all elements immediately anyway.
That said, the first option is more cluttered with extra syntax (e.g. ::class
), and more interlaced, so I would still argue it's slower to parse visually