Skip to content

Commit

Permalink
fix: Avoid breaking changes with remove component event by adding mis…
Browse files Browse the repository at this point in the history
…sing function signatures without default values back for now
  • Loading branch information
0ffz committed Mar 24, 2024
1 parent d35be6f commit 77a247a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ value class Entity(val id: EntityId) {
*
* @return Whether the component was present before removal.
*/
inline fun <reified T : Component> remove(): Boolean =
remove(componentId<T>())
inline fun <reified T : Component> remove(noEvent: Boolean = false): Boolean =
remove(componentId<T>(), noEvent)

/** Removes a component whose class is [kClass] from this entity. */
fun remove(kClass: KClass<*>): Boolean =
remove(componentId(kClass))
fun remove(kClass: KClass<*>, noEvent: Boolean = false): Boolean =
remove(componentId(kClass), noEvent)

/** Removes a component with id [component] from this entity. */
fun remove(component: ComponentId, noEvent: Boolean = false): Boolean =
Expand Down Expand Up @@ -296,9 +296,8 @@ value class Entity(val id: EntityId) {
geary.write.addComponentFor(this, Relation.of(kind, target).id, noEvent)
}

/** Removes a relation key of type [K] and value of type [V]. */
inline fun <reified K : Component, reified T : Component> removeRelation(): Boolean {
return removeRelation<K>(component<T>())
inline fun <reified K : Component, reified T : Component> removeRelation(noEvent: Boolean = false): Boolean {
return removeRelation<K>(component<T>(), noEvent)
}

inline fun <reified K : Any> removeRelation(target: Entity, noEvent: Boolean = false): Boolean {
Expand Down Expand Up @@ -391,4 +390,8 @@ value class Entity(val id: EntityId) {
@DangerousComponentOperation
fun setPersisting(components: Collection<Component>): Collection<Component> =
setPersisting(component = components)

// Marked for removal. Avoid breaking changes from adding the remove event.
fun remove(kClass: KClass<*>): Boolean = remove(kClass, false)
fun remove(component: ComponentId): Boolean = remove(component, false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ interface EntityMutateOperations {
/** Removes a [componentId] from an [entity] and clears any data previously associated with it. */
fun removeComponentFor(entity: Entity, componentId: ComponentId, noEvent: Boolean): Boolean

// To avoid breaking changes from component remove events, marked for removal
@Deprecated("Use removeComponentFor(entity, componentId, noEvent) instead.")
fun removeComponentFor(entity: Entity, componentId: ComponentId): Boolean

/** Removes all components from an entity. */
fun clearEntity(entity: Entity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ArchetypeMutateOperations : EntityMutateOperations {
return a || b // return whether anything was changed
}

override fun removeComponentFor(entity: Entity, componentId: ComponentId): Boolean =
removeComponentFor(entity, componentId, false)

override fun clearEntity(entity: Entity) {
records.runOn(entity) { archetype, row ->
archetype.removeEntity(row)
Expand Down

0 comments on commit 77a247a

Please sign in to comment.