Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.
Merged
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
5 changes: 2 additions & 3 deletions packages/engine/src/avatar/components/AvatarIKComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ export const AvatarHeadDecapComponent = defineComponent({

useEffect(() => {
if (rig?.value) {
if (headDecap?.value) {
rig.value.rig.Head?.scale.setScalar(EPSILON)
} else {
if (headDecap?.value) rig.value.rig.Head?.scale.setScalar(EPSILON)
return () => {
rig.value.rig.Head?.scale.setScalar(1)
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/engine/src/ecs/functions/ComponentFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export const defineComponent = <
Component.toJSON = (entity, component) => null!
Component.errors = []
Object.assign(Component, def)
if (Component.reactor && (!Component.reactor.name || Component.reactor.name === 'reactor'))
Object.defineProperty(Component.reactor, 'name', { value: `${Component.name}Reactor` })
Component.reactorMap = new Map()
// We have to create an stateful existence map in order to reactively track which entities have a given component.
// Unfortunately, we can't simply use a single shared state because hookstate will (incorrectly) invalidate other nested states when a single component
Expand Down Expand Up @@ -197,9 +199,7 @@ export const setComponent = <C extends Component>(
})
} else Component.stateMap[entity]!.set(value)
bitECS.addComponent(Engine.instance, Component, entity, false) // don't clear data on-add
if (Component.reactor) {
if (!Component.reactor.name || Component.reactor.name === 'reactor')
Object.defineProperty(Component.reactor, 'name', { value: `${Component.name}Reactor-${entity}` })
if (Component.reactor && !Component.reactorMap.has(entity)) {
const root = startReactor(Component.reactor) as EntityReactorRoot
root.entity = entity
Component.reactorMap.set(entity, root)
Expand Down Expand Up @@ -269,18 +269,18 @@ export const addComponent = <C extends Component>(
}

export const hasComponent = <C extends Component>(entity: Entity, component: C) => {
return bitECS.hasComponent(Engine.instance, component, entity)
return component.existenceMap[entity]?.value ?? false
}

export const getOrAddComponent = <C extends Component>(entity: Entity, component: C, args?: SetComponentType<C>) => {
return hasComponent(entity, component) ? getComponent(entity, component) : addComponent(entity, component, args)
}

export const removeComponent = <C extends Component>(entity: Entity, component: C) => {
if (!bitECS.entityExists(Engine.instance, entity) || !bitECS.hasComponent(Engine.instance, component, entity)) return
if (!hasComponent(entity, component)) return
component.existenceMap[entity].set(false)
component.onRemove(entity, component.stateMap[entity]!)
bitECS.removeComponent(Engine.instance, component, entity, false)
component.existenceMap[entity].set(false)
component.stateMap[entity]?.set(none)
delete component.valueMap[entity]
const root = component.reactorMap.get(entity)
Expand Down