import React, { useCallback } from 'react' import { Vector3 } from 'three' import { ApplyForceBehaviorJSON, BehaviorJSON, BehaviorJSONDefaults, ChangeEmitDirectionBehaviorJSON, ColorOverLifeBehaviorJSON, EmitSubParticleSystemBehaviorJSON, FrameOverLifeBehaviorJSON, GravityForceBehaviorJSON, NoiseBehaviorJSON, OrbitOverLifeBehaviorJSON, Rotation3DOverLifeBehaviorJSON, RotationOverLifeBehaviorJSON, SizeOverLifeBehaviorJSON, SpeedOverLifeBehaviorJSON, WidthOverLengthBehaviorJSON } from '@xrengine/engine/src/scene/components/ParticleSystemComponent' import { State } from '@xrengine/hyperflux' import InputGroup from '../../inputs/InputGroup' import NumericInputGroup from '../../inputs/NumericInputGroup' import SelectInput from '../../inputs/SelectInput' import StringInput from '../../inputs/StringInput' import Vector3Input from '../../inputs/Vector3Input' import ColorGenerator from './ColorGenerator' import ValueGenerator from './ValueGenerator' export default function BehaviorInput({ scope, value, onChange }: { scope: State value: BehaviorJSON onChange: (key: string) => (value: any) => void }) { const onChangeProp = useCallback( (scope: State, scopeKey: string) => (key: string) => { const topOnChange = onChange(scopeKey) return (keyVal: any) => { const nuVal = { ...JSON.parse(JSON.stringify(scope.value)), [key]: keyVal } topOnChange(nuVal) } }, [] ) const onChangeVec3 = useCallback((key: string) => { const thisOnChange = onChange(key) return (value: Vector3) => { thisOnChange(value.toArray()) } }, []) const onChangeBehaviorType = useCallback(() => { const onChangeType = onChange('type') return (type: typeof value.type) => { const nuVals = BehaviorJSONDefaults[type] scope.set(nuVals) onChangeType(type) } }, []) return ( <> {(() => { switch (value.type) { case 'ApplyForce': const forceScope = scope as State return ( <> ) case 'Noise': const noiseScope = scope as State return ( <> ) case 'TurbulenceField': const turbulenceScope = scope as State return ( <> ) case 'GravityForce': const gravityScope = scope as State return ( <> ) case 'ColorOverLife': const colorScope = scope as State return ( <> ) case 'RotationOverLife': const rotationScope = scope as State return ( <> ) case 'Rotation3DOverLife': const rotation3DScope = scope as State return <> case 'SizeOverLife': const sizeScope = scope as State return ( <> ) case 'SpeedOverLife': const speedScope = scope as State return ( <> ) case 'FrameOverLife': const frameScope = scope as State return ( <> ) case 'OrbitOverLife': const orbitScope = scope as State return ( <> ) case 'WidthOverLength': const widthScope = scope as State return ( <> ) case 'ChangeEmitDirection': const changeEmitDirectionScope = scope as State return ( <> ) case 'EmitSubParticleSystem': const emitSubParticleSystemScope = scope as State return ( <> ) } })()} ) }