# HG changeset patch # User Sam # Date 1687887309 -25200 # Node ID 3c0c5492e0b4e2df4c1298bf414219e38eb8f5f7 # Parent 85878096e9f0514bbed5f7e275c6280ca137b774 add: nicer api to prevent need of component casting diff -r 85878096e9f0 -r 3c0c5492e0b4 src/semicongine/scene.nim --- a/src/semicongine/scene.nim Tue Jun 27 00:51:36 2023 +0700 +++ b/src/semicongine/scene.nim Wed Jun 28 00:35:09 2023 +0700 @@ -132,17 +132,17 @@ proc add*(entity: Entity, child: Entity) = child.parent = entity entity.children.add child -proc `[]=`*(entity: var Entity, index: int, child: var Entity) = +proc `[]=`*[T](entity: var Entity, index: int, child: var T) = child.parent = entity entity.children[index] = child proc `[]`*(entity: Entity, index: int): Entity = entity.children[index] -proc `[]=`*(entity: Entity, name: string, component: Component) = +proc `[]=`*[T](entity: Entity, name: string, component: T) = component.entity = entity entity.components[name] = component -proc `[]`*(entity: Entity, name: string): Component = - entity.components[name] +proc `[]`*[T](entity: Entity, name: string, component: T): T = + T(entity.components[name]) func newEntity*(name: string, components: openArray[(string, Component)] = [], children: varargs[Entity]): Entity = result = new Entity