Mercurial > games > semicongine
changeset 306:046f7e2b1e13
add: nicer api to prevent need of component casting
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 28 Jun 2023 00:35:09 +0700 |
parents | 44ecc0a01a9f |
children | f471426ef8e2 |
files | src/semicongine/scene.nim |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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