MCPcopy Index your code
hub / github.com/processing/p5.js / createHookArguments

Function createHookArguments

src/strands/strands_api.js:645–707  ·  view source on GitHub ↗
(strandsContext, parameters)

Source from the content-addressed store, hash-verified

643// Per-Hook functions
644//////////////////////////////////////////////
645function createHookArguments(strandsContext, parameters){
646 const args = [];
647 const dag = strandsContext.dag;
648 for (const param of parameters) {
649 if(isStructType(param.type)) {
650 const structTypeInfo = structType(param);
651 const { id, dimension } = build.structInstanceNode(strandsContext, structTypeInfo, `${HOOK_PARAM_PREFIX}${param.name}`, []);
652 const structNode = createStrandsNode(id, dimension, strandsContext).withStructProperties(
653 structTypeInfo.properties.map(prop => prop.name)
654 );
655 for (let i = 0; i < structTypeInfo.properties.length; i++) {
656 const propertyType = structTypeInfo.properties[i];
657 Object.defineProperty(structNode, propertyType.name, {
658 get() {
659 const propNode = getNodeDataFromID(dag, dag.dependsOn[structNode.id][i])
660 const onRebind = (newFieldID) => {
661 const oldDeps = dag.dependsOn[structNode.id];
662 const newDeps = oldDeps.slice();
663 newDeps[i] = newFieldID;
664 const rebuilt = build.structInstanceNode(strandsContext, structTypeInfo, `${HOOK_PARAM_PREFIX}${param.name}`, newDeps);
665 structNode.id = rebuilt.id;
666 };
667 // TODO: implement member access operations
668 // const { id, components } = createMemberAccessNode(strandsContext, structNode, componentNodes[i], componentTypeInfo.dataType);
669 // const memberAccessNode = new StrandsNode(id, components);
670 // return memberAccessNode;
671 return createStrandsNode(propNode.id, propNode.dimension, strandsContext, onRebind);
672 },
673 set(val) {
674 const oldDependsOn = dag.dependsOn[structNode.id];
675 const newDependsOn = [...oldDependsOn];
676 let newValueID;
677 if (val?.isStrandsNode) {
678 newValueID = val.id;
679 }
680 else {
681 let newVal = build.primitiveConstructorNode(strandsContext, propertyType.dataType, val);
682 newValueID = newVal.id;
683 }
684 newDependsOn[i] = newValueID;
685 const newStructInfo = build.structInstanceNode(strandsContext, structTypeInfo, `${HOOK_PARAM_PREFIX}${param.name}`, newDependsOn);
686 structNode.id = newStructInfo.id;
687 }
688 })
689 }
690 args.push(structNode);
691 }
692 else /*if(isNativeType(paramType.typeName))*/ {
693 // Skip sampler parameters - they don't need strands nodes
694 if (param.type.typeName === 'sampler') {
695 continue;
696 }
697 if (!param.type.dataType) {
698 throw new Error(`Missing dataType for parameter ${param.name} of type ${param.type.typeName}`);
699 }
700 const typeInfo = param.type.dataType;
701 const { id, dimension } = build.variableNode(strandsContext, typeInfo, `${HOOK_PARAM_PREFIX}${param.name}`);
702 const arg = createStrandsNode(id, dimension, strandsContext);

Callers 1

setupHookFunction · 0.85

Calls 5

isStructTypeFunction · 0.90
structTypeFunction · 0.90
createStrandsNodeFunction · 0.90
withStructPropertiesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected