Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: component #1477

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/foundation/core/EntityRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { WellKnownComponentTIDs } from '../components/WellKnownComponentTIDs';
import { SceneGraphComponent } from '../components/SceneGraph/SceneGraphComponent';
import { SkeletalComponent } from '../components/Skeletal/SkeletalComponent';
import { ISceneGraphEntity } from '../helpers';
import { Logger } from '../misc';

/**
* The class that generates and manages entities.
Expand All @@ -28,7 +29,7 @@ export class EntityRepository {
// check dead entity
let deadUid = -1;
for (let i = 0; i < this.__entities.length; i++) {
if (this.__entities[i] != null && this.__entities[i]!._isAlive === false) {
if (this.__entities[i] == null) {
deadUid = i;
}
}
Expand Down Expand Up @@ -187,6 +188,12 @@ export class EntityRepository {
}
}

/**
* Try to add a component to the entity by componentTID.
* @param componentTID - the componentTID
* @param entity - the entity
* @returns the entity added a component
*/
public static tryToAddComponentToEntityByTID(
componentTID: ComponentTID,
entity: IEntity
Expand All @@ -212,7 +219,7 @@ export class EntityRepository {
entity: EntityType
): EntityType & ComponentToComponentMethods<ComponentType> {
if (entity.hasComponent(componentClass)) {
// console.log('This entity already has the Component.');
Logger.info('This entity already has the Component.');
return entity as EntityType & ComponentToComponentMethods<ComponentType>;
}

Expand All @@ -223,6 +230,7 @@ export class EntityRepository {
this
);

// set this component to this._components' map
const map = valueWithCompensation({
value: this._components[entity.entityUID],
compensation: () => {
Expand Down
Loading