Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/core/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const set = <T extends ComponentRef>(component: T, data: any): { componen
})

/**
* Recursvely inherits components from one entity to another.
* Recursively inherits components from one entity to another.
* @param {World} world - The world object.
* @param {number} baseEid - The ID of the entity inheriting components.
* @param {number} inheritedEid - The ID of the entity being inherited from.
Expand Down
13 changes: 8 additions & 5 deletions src/core/Relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ type RelationData<T> = {
* @param {RelationTarget} target - The target of the relation.
* @returns {T} The relation component.
*/
export type Relation<T> = (target: RelationTarget) => T
export interface Relation<T> {
(target: RelationTarget):T
[$relationData]: RelationData<T>
}

/**
* Creates a base relation.
Expand Down Expand Up @@ -100,7 +103,7 @@ const createBaseRelation = <T>(): Relation<T> => {
* @returns {function(Relation<T>): Relation<T>} A function that modifies the relation.
*/
export const withStore = <T>(createStore: (eid: EntityId) => T) => (relation: Relation<T>): Relation<T> => {
const ctx = relation[$relationData] as RelationData<T>
const ctx = relation[$relationData]
ctx.initStore = createStore
return relation
}
Expand All @@ -112,7 +115,7 @@ export const withStore = <T>(createStore: (eid: EntityId) => T) => (relation: Re
* @returns {Relation<T>} The modified relation.
*/
export const makeExclusive = <T>(relation: Relation<T>): Relation<T> => {
const ctx = relation[$relationData] as RelationData<T>
const ctx = relation[$relationData]
ctx.exclusiveRelation = true
return relation
}
Expand All @@ -124,7 +127,7 @@ export const makeExclusive = <T>(relation: Relation<T>): Relation<T> => {
* @returns {Relation<T>} The modified relation.
*/
export const withAutoRemoveSubject = <T>(relation: Relation<T>): Relation<T> => {
const ctx = relation[$relationData] as RelationData<T>
const ctx = relation[$relationData]
ctx.autoRemoveSubject = true
return relation
}
Expand All @@ -136,7 +139,7 @@ export const withAutoRemoveSubject = <T>(relation: Relation<T>): Relation<T> =>
* @returns {function(Relation<T>): Relation<T>} A function that modifies the relation.
*/
export const withOnTargetRemoved = <T>(onRemove: OnTargetRemovedCallback) => (relation: Relation<T>): Relation<T> => {
const ctx = relation[$relationData] as RelationData<T>
const ctx = relation[$relationData]
ctx.onTargetRemoved = onRemove
return relation
}
Expand Down