Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (scriptGroup.hasEntity(entity)) {
// ...remove the placeholder
entity.removeComponent(GLTFShape)
// ...create the host entity
const transform = entity.getComponent(Transform)
const hostTransform = new Transform()
hostTransform.position.copyFrom(transform.position)
hostTransform.rotation.copyFrom(transform.rotation)
hostTransform.scale.copyFrom(transform.scale)
const name = (entity as any).name // TODO fix this on the kernel's side
const placeholder = Object.values(engine.entities).find(entity => (entity as Entity).name === name)
if (placeholder) {
engine.removeEntity(placeholder)
}
const host = new Entity(name)
engine.addEntity(host)
host.addComponent(hostTransform)
// ...and execute the script on the host entity
const { assetId, values } = entity.getComponent(Script)
const script = scriptInstances.get(assetId)!
const channel = createChannel('channel-id', host as any, new MockMessageBus())
script.spawn(host, values, channel)
}
}
} else {
for (const entityId in engine.entities) {
const entity = engine.entities[entityId]
const staticEntities = engine.getComponentGroup(StaticEntity)
if (!staticEntities.hasEntity(entity)) {
entity.addComponentOrReplace(gizmo)
}
}
function createEntities(entities: Record) {
for (let id in entities) {
const builderEntity = entities[id]
let entity: IEntity = engine.entities[id]
if (!entity) {
entity = new Entity(builderEntity.name)
;(entity as any).uuid = id
if (!builderEntity.disableGizmos) {
entity.addComponentOrReplace(gizmo)
} else {
entity.addComponentOrReplace(staticEntity)
}
engine.addEntity(entity)
}
for (let componentId of builderEntity.components) {
const component = getComponentById(componentId)
if (component) {
entity.addComponentOrReplace(component)
if (component instanceof Script) {
entity.addComponentOrReplace(smartItemComponent)
}
}
}
}
}