Skip to content

Commit

Permalink
Fix to AddComponent: index !== undefined, since (... && index) where …
Browse files Browse the repository at this point in the history
…index: 0 evaluates as False
  • Loading branch information
joaqim committed Jun 27, 2021
1 parent 439812b commit e84cbd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/utils/ecs/entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ describe('>>> Entity', () => {
expect(e.HasComponent(C3)).toBeTruthy()
})

it('should be able to remove every component', () => {
e.AddComponent(c1)
e.AddComponent(c2)
e.AddComponent(c3)

e.RemoveComponent(C1)
e.RemoveComponent(C2)
e.RemoveComponent(C3)
expect(e.Components.length).toBe(0)
})

it('should throw error if component wasn\'t found', () => {
expect(e.HasComponent(C1)).toBeFalsy()
expect(() => e.GetComponent(C1)).toThrow()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ecs/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export abstract class Entity implements IAwake, IUpdate {
}
}

if (toRemove && index) {
if (toRemove && index !== undefined) {
toRemove.Entity = null
this._components.splice(index, 1)
}
Expand Down

0 comments on commit e84cbd0

Please sign in to comment.