-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Event runner not updating entity archetype/row information after…
… modifications when calling multiple listeners
- Loading branch information
Showing
4 changed files
with
96 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
geary-core/src/jvmTest/kotlin/com/mineinabyss/geary/events/EntityRemoveListenerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.mineinabyss.geary.events | ||
|
||
import com.mineinabyss.geary.components.events.EntityRemoved | ||
import com.mineinabyss.geary.helpers.entity | ||
import com.mineinabyss.geary.helpers.tests.GearyTest | ||
import com.mineinabyss.geary.modules.geary | ||
import com.mineinabyss.geary.systems.builders.listener | ||
import com.mineinabyss.geary.systems.query.ListenerQuery | ||
import io.kotest.matchers.shouldBe | ||
import kotlin.test.Test | ||
|
||
class EntityRemoveListenerTest : GearyTest() { | ||
@Test | ||
fun `should correctly run multiple listeners on single event`() { | ||
var called = 0 | ||
|
||
val listener1 = geary.listener(object : ListenerQuery() { | ||
val data by get<Int>() | ||
override fun ensure() = event { has<EntityRemoved>() } | ||
}).exec { | ||
data shouldBe 1 | ||
entity.remove<Int>() | ||
called++ | ||
} | ||
|
||
val listener2 = geary.listener(object : ListenerQuery() { | ||
val data by get<String>() | ||
override fun ensure() = event { has<EntityRemoved>() } | ||
}).exec { | ||
data shouldBe "" | ||
} | ||
|
||
val entity1 = entity { | ||
set(1) | ||
set("") | ||
} | ||
|
||
val entity2 = entity { | ||
set(1) | ||
set("") | ||
} | ||
|
||
entity2.removeEntity() | ||
entity1.removeEntity() | ||
called shouldBe 2 | ||
} | ||
} |