Closed ludek17052 closed 3 weeks ago
Since you just have a single component, can you not just use
compareEntityBy(MyComponent)
and assign it to your comparator in the constructor?
The alternative is the compareEntitiy
method which already runs in the context of a world.
Imo those two things should be sufficient. The only reason for var is if someone needs to change the comparator at some point in the system but at least I never had this use case and no one complained so far.
Please try the two Fleks compare methods that I mentioned above. They should be sufficient. If not then let me know 😉
edit:
Here is an example of the compareEntity
comparator = compareEntity { entityA, entityB ->
entityB[SystemTestComponent].x.compareTo(entityA[SystemTestComponent].x)
},
It seems that compareEntity works fine. Thank you.
Hello, Is there any reason why "comparator" is "val"? I need Comparator with "world" parametr in System class and I guess I cannot define it in head of System class. So I need to create comparator later but comparator is "val" and I cannot set it.
I am using this comparator:
private class MyComparator(val world: World) : EntityComparator { override fun compare(o1: Entity, o2: Entity): Int = with(world) { if (o1.has(MyComponent) && o2.hasNo(MyComponent)) return -1 if (o1.hasNo(MyComponent) && o2.has(MyComponent)) return 1 return 0 } }