diff --git a/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt b/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt index 035b385d..5aca91d4 100644 --- a/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt +++ b/addons/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt @@ -68,7 +68,10 @@ class AutoScannerDSL( scanned.forEach { scannedComponent -> runCatching { component(scannedComponent) } .onFailure { - this@AutoScannerDSL.logger.w("Failed to register component ${scannedComponent.simpleName}\n${it.stackTraceToString()}") + if (it is ClassNotFoundException) + this@AutoScannerDSL.logger.w("Failed to register component ${scannedComponent.simpleName}, class not found") + else + this@AutoScannerDSL.logger.w("Failed to register component ${scannedComponent.simpleName}\n${it.stackTraceToString()}") } } } diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/Entity.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/Entity.kt index db612faa..52ba4f12 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/Entity.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/Entity.kt @@ -55,6 +55,9 @@ value class Entity(val id: EntityId) { entityProvider.remove(this) } + /** Checks whether this entity has not been removed. */ + fun exists(): Boolean = read.exists(this) + /** * Sets a component that holds data for this entity * diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/maps/ArrayTypeMap.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/maps/ArrayTypeMap.kt index 5182321f..5590494d 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/maps/ArrayTypeMap.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/datatypes/maps/ArrayTypeMap.kt @@ -28,6 +28,6 @@ class ArrayTypeMap : TypeMap { override operator fun contains(entity: Entity): Boolean { val id = entity.id.toInt() - return map.size < id && map[id] != null + return map.size > id && map[id] != null } } diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/EntityReadOperations.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/EntityReadOperations.kt index 19a8b6f0..30c9a2a1 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/EntityReadOperations.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/EntityReadOperations.kt @@ -10,6 +10,9 @@ interface EntityReadOperations { /** Gets a list of all the components [entity] has, as well as relations in the form of [RelationComponent]. */ fun getComponentsFor(entity: Entity): Array + /** Checks whether an [entity] is still active in the engine. */ + fun exists(entity: Entity): Boolean + /** * Gets relations in the same format as [Archetype.getRelations], but when kind/target [HOLDS_DATA], the appropriate * data is written to a [RelationWithData] object. diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/archetypes/operations/ArchetypeReadOperations.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/archetypes/operations/ArchetypeReadOperations.kt index 0dd5af32..690cb915 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/archetypes/operations/ArchetypeReadOperations.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/engine/archetypes/operations/ArchetypeReadOperations.kt @@ -24,6 +24,10 @@ class ArchetypeReadOperations : EntityReadOperations { } } + override fun exists(entity: Entity): Boolean { + return records.contains(entity) + } + override fun getRelationsWithDataFor( entity: Entity, kind: ComponentId,