# HG changeset patch # User Sam # Date 1687887309 -25200 # Node ID 046f7e2b1e13e6b5d6dfb5f17cc709666ad0f396 # Parent 44ecc0a01a9fe4c28d0646e8ea17f44f669b6904 add: nicer api to prevent need of component casting diff -r 44ecc0a01a9f -r 046f7e2b1e13 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