public void Build(ActionSet actionSet, Element compressedNodeArray, Action <Element> printProgress, ILambdaInvocable onLoop) { var matcher = GetMatcher(actionSet); // Get the character matcher. var nodeArray = actionSet.VarCollection.Assign("compressedNodes", actionSet.IsGlobal, false); // The index the node array is stored in. var nodeCount = Element.CountOf(nodeArray.Get()); // The number of nodes. var bakeResult = actionSet.VarCollection.Assign("compressBakeResult", true, false); // Assign the nodeResult. var compressCurrentNodeArray = actionSet.VarCollection.Assign("compressCurrentNodeArray", true, false); // Assign the nodeResult. nodeArray.Set(actionSet, compressedNodeArray); bakeResult.Set(actionSet, Element.EmptyArray()); // Initialize the nodeResult. // Loop through each node. var nodeArrayLoop = new ForBuilder(actionSet, "compressBakeNodeLoop", nodeCount); printProgress(nodeArrayLoop.Value / nodeCount); // Print the node count. nodeArrayLoop.Init(); compressCurrentNodeArray.Set(actionSet, Element.EmptyArray()); var currentStringArray = nodeArray.Get()[nodeArrayLoop.Value]; // The current string array. // Loop through each string. var stringArrayLoop = new ForBuilder(actionSet, "compressBakeStringLoop", Element.CountOf(currentStringArray)); stringArrayLoop.Init(); var currentString = currentStringArray[stringArrayLoop.Value]; // The current string. // Create an array with the length of the number of characters in the string. var mapper = actionSet.VarCollection.Assign("compressMapper", actionSet.IsGlobal, false); mapper.Set(actionSet, Element.EmptyArray()); mapper.Set(actionSet, index: Element.StringLength(currentString) - 1, value: 0); actionSet.AddAction(compressCurrentNodeArray.ModifyVariable( operation: Operation.AppendToArray, value: Element.Map( mapper.Get(), Element.IndexOfArrayValue( matcher, Element.StringSlice(currentString, Element.ArrayIndex(), (Element)1) ) ) )); // Invoke onLoop. if (onLoop == null) { actionSet.AddAction(Element.Wait()); } else { onLoop.Invoke(actionSet); } stringArrayLoop.End(); actionSet.AddAction(bakeResult.SetVariable(index: nodeArrayLoop.Value, value: compressCurrentNodeArray.Get())); nodeArrayLoop.End(); Result = bakeResult.Get(); }
public Element Bake(Action <Element> progress) { if (_onLoop == null) { _bakeWait = ActionSet.VarCollection.Assign("bakeWait", ActionSet.IsGlobal, false); _bakeWait.Set(ActionSet, 0); } // Assign bakemap then set it to an empty array. _bakemap = ActionSet.VarCollection.Assign("bakemap", ActionSet.IsGlobal, false); _bakemap.Set(ActionSet, EmptyArray()); // Loop through each node. _nodeLoop = new ForBuilder(ActionSet, "bakemapNode", NodeArrayLength); _builder = new PathfindAlgorithmBuilder(this); progress(Progress); _nodeLoop.Init(); // Start the node loop. _builder.Get(); // Run pathfinder. _nodeLoop.End(); // End the node loop. // Create a new Bakemap class instance. var newBakemap = _bakemapClass.Instance.Create(ActionSet, ActionSet.Translate.DeltinScript.GetComponent <ClassData>()); _bakemapClass.Pathmap.SetWithReference(ActionSet, newBakemap.Get(), _pathmapObject); _bakemapClass.NodeBake.SetWithReference(ActionSet, newBakemap.Get(), _bakemap.Get()); return(newBakemap.Get()); }