private JinjaUserDefinedFunction ConvertMacroToUserDefinedFunction(MacroNode macro)
        {
            var usesCaller = macro.Contents.Transform(CallerFinderVisitor.Instance).Any(x => x);
            Func <UserDefinedArgumentData, object?> func = arguments =>
            {
                using var checkout = StringBuilderPool.Instance.Checkout();
                var stringBuilder = checkout.CheckedOutObject;

                Scopes.Push($"Macro: {macro.FunctionDeclaration.Name}");
                foreach (var arg in arguments.AllArguments)
                {
                    Scopes.Current.DefineAndSetVariable(arg.Name, arg.Value);
                }

                Scopes.Current.DefineAndSetVariable("varargs", arguments.AdditionalPositionalArguments.Select(arg => arg.Value));
                Scopes.Current.DefineAndSetVariable("kwargs", arguments.AdditionalKeywordArguments);

                foreach (var output in macro.Contents.Transform(this))
                {
                    stringBuilder.Append(output);
                }

                Scopes.Pop($"Macro: {macro.FunctionDeclaration.Name}");
                return(stringBuilder.ToString());
            };

            UserDefinedFunction.UserDefinedFunctionDelegate del = args => func(args);

            return(new JinjaUserDefinedFunction(macro.FunctionDeclaration, del, usesCaller));
        }
Пример #2
0
        public IEnumerable <ASTNode> Transform(MacroNode item)
        {
            yield return(item);

            foreach (var child in TransformAll(item.Contents))
            {
                yield return(child);
            }
        }
        public IEnumerable <string> Transform(MacroNode item)
        {
            _EncounteredOutputStyleBlock = true;
            if (!(ShouldRender && _EncounteredOutputStyleBlock))
            {
                yield break;
            }

            Scopes.Current.DefineAndSetVariable(item.FunctionDeclaration.Name, ConvertMacroToUserDefinedFunction(item));

            yield break;
        }
Пример #4
0
        static public void TestJSCreationFunction()
        {
            VarNode m_1 = new VarNode("link");
            StrNode m_2 = new StrNode("to,text");
            StrNode m_3 = new StrNode("[[_to|_text]]");

            MacroNode m = new MacroNode("macro", new List <ASTNode>()
            {
                m_1, m_2, m_3
            });

            Console.WriteLine(m.ToTaggedJS());
        }
Пример #5
0
 public void SetFrequencyScale()
 {
     // find generators that have frequency
     foreach (Node n in nodes)
     {
         if (n is GeneratorNode)
         {
             GeneratorNode g = (GeneratorNode)n;
             g.frequency *= frequencyScale;
         }
         if (n is MacroNode)
         {
             MacroNode m = (MacroNode)n;
             m.frequencyScale = frequencyScale;
         }
     }
 }
Пример #6
0
    public NodeWindow(Node node)
    {
        this.windowIndex = indexCount;
        indexCount++;

        // cast to specific type
        if (node is GeneratorNode)
        {
            generatorNode = (GeneratorNode)node;
            type          = WINDOWTYPE.GENERATOR;
        }
        if (node is OperatorNode)
        {
            operatorNode = (OperatorNode)node;
            type         = WINDOWTYPE.OPERATOR;
        }
        if (node is OutputNode)
        {
            outputNode  = (OutputNode)node;
            type        = WINDOWTYPE.OUTPUT;
            previewSize = PreviewSize.x4;
            //autoGeneratePreview = false;
        }
        if (node is MacroNode)
        {
            macroNode = (MacroNode)node;
            type      = WINDOWTYPE.MACRO;
        }

        // also save general reference
        this.node = node;

        // random connection color
        connectionColor = new Color(Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f, Random.Range(100, 200) / 255f);

        preview          = Generate((int)previewSize);
        node.rect.height = controlHeight + (int)previewSize;
        node.rect.width  = (int)previewSize + 20;
        if (node.rect.width < 200)
        {
            node.rect.width = 200;
        }
    }
    /// <inheritdoc/>
    public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
    {
        var jObject = JObject.Load(reader);
        var jType   = jObject["$type"]?.Value <string>();

        if (jType == this.SimpleName(typeof(MacroNode)))
        {
            var obj = new MacroNode();
            serializer.Populate(jObject.CreateReader(), obj);
            return(obj);
        }
        else if (jType == this.SimpleName(typeof(FolderNode)))
        {
            var obj = new FolderNode();
            serializer.Populate(jObject.CreateReader(), obj);
            return(obj);
        }
        else
        {
            throw new NotSupportedException($"Node type \"{jType}\" is not supported.");
        }
    }
Пример #8
0
 public void Transform(MacroNode item)
 {
     throw new NotImplementedException();
 }
Пример #9
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            NodeComponent comp = target as NodeComponent;

            if (comp == null)
            {
                return;
            }
            EditorGUI.BeginChangeCheck();
            if (comp is MacroNode)
            {
                MacroNode node = comp as MacroNode;
                VariableEditorUtility.DrawVariable(node.variables, node,
                                                   (v) => {
                    node.variables = v;
                }, null);

                VariableEditorUtility.DrawCustomList(
                    node.inputFlows,
                    "Input Flows",
                    (position, index, element) => {                    //Draw Element
                    EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon))));
                }, null, null);
                VariableEditorUtility.DrawCustomList(
                    node.outputFlows,
                    "Output Flows",
                    (position, index, element) => {                    //Draw Element
                    EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon))));
                }, null, null);
                VariableEditorUtility.DrawCustomList(
                    node.inputValues,
                    "Input Values",
                    (position, index, element) => {                    //Draw Element
                    position.width -= EditorGUIUtility.labelWidth;
                    EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType())));
                    position.x += EditorGUIUtility.labelWidth;
                    uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element);
                }, null, null);
                VariableEditorUtility.DrawCustomList(
                    node.outputValues,
                    "Output Values",
                    (position, index, element) => {                    //Draw Element
                    position.width -= EditorGUIUtility.labelWidth;
                    EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType())));
                    position.x += EditorGUIUtility.labelWidth;
                    uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element);
                }, null, null);
            }
            else if (comp is LinkedMacroNode)
            {
                LinkedMacroNode node = comp as LinkedMacroNode;
                if (node.macroAsset != null)
                {
                    VariableEditorUtility.DrawLinkedVariables(node, node.macroAsset, publicOnly: false);
                    EditorGUI.BeginDisabledGroup(true);
                    VariableEditorUtility.DrawCustomList(
                        node.inputFlows,
                        "Input Flows",
                        (position, index, element) => {                        //Draw Element
                        EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon))));
                    }, null, null);
                    VariableEditorUtility.DrawCustomList(
                        node.outputFlows,
                        "Output Flows",
                        (position, index, element) => {                        //Draw Element
                        EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.FlowIcon))));
                    }, null, null);
                    VariableEditorUtility.DrawCustomList(
                        node.inputValues,
                        "Input Values",
                        (position, index, element) => {                        //Draw Element
                        position.width -= EditorGUIUtility.labelWidth;
                        EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType())));
                        position.x += EditorGUIUtility.labelWidth;
                        uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element);
                    }, null, null);
                    VariableEditorUtility.DrawCustomList(
                        node.outputValues,
                        "Output Values",
                        (position, index, element) => {                        //Draw Element
                        position.width -= EditorGUIUtility.labelWidth;
                        EditorGUI.LabelField(position, new GUIContent(element.GetName(), uNodeEditorUtility.GetTypeIcon(element.ReturnType())));
                        position.x += EditorGUIUtility.labelWidth;
                        uNodeGUIUtility.EditValue(position, GUIContent.none, "type", element, element);
                    }, null, null);
                    EditorGUI.EndDisabledGroup();
                }
            }

            uNodeGUIUtility.ShowField("comment", comp, comp);
            if (comp.GetType().GetCustomAttributes(typeof(DescriptionAttribute), false).Length > 0)
            {
                DescriptionAttribute descriptionEvent = (DescriptionAttribute)comp.GetType().GetCustomAttributes(typeof(DescriptionAttribute), false)[0];
                if (descriptionEvent.description != null && descriptionEvent != null)
                {
                    GUI.backgroundColor = Color.yellow;
                    EditorGUILayout.HelpBox("Description: " + descriptionEvent.description, MessageType.None);
                    GUI.backgroundColor = Color.white;
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                uNodeEditorUtility.MarkDirty(comp);
                uNodeGUIUtility.GUIChanged(comp);
            }
        }
Пример #10
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            MacroNode node = source as MacroNode;
            string    path = EditorUtility.SaveFilePanelInProject("Export to macro asset",
                                                                  "New Macro.prefab",
                                                                  "prefab",
                                                                  "Please enter a file name to save the macro to");

            if (path.Length != 0)
            {
                Undo.RegisterFullObjectHierarchyUndo(node, "");
                Undo.RegisterFullObjectHierarchyUndo(node.owner, "");
                var        tmpMacro = Object.Instantiate(node);
                GameObject go       = new GameObject("New Macro");
                var        macro    = go.AddComponent <uNodeMacro>();
                macro.Variables.AddRange(tmpMacro.Variables);
                if (macro.RootObject == null)
                {
                    macro.RootObject = new GameObject("Root");
                    macro.RootObject.transform.SetParent(macro.transform);
                }
                var behaviors = tmpMacro.GetComponentsInChildren <MonoBehaviour>(true);
                AnalizerUtility.RetargetNodeOwner(tmpMacro.owner, macro, behaviors, (obj) => {
                    MemberData member = obj as MemberData;
                    if (member != null && member.targetType == MemberData.TargetType.uNodeVariable && member.GetInstance() as Object == tmpMacro)
                    {
                        member.RefactorUnityObject(new Object[] { tmpMacro }, new Object[] { macro });
                    }
                });
                for (int i = 0; i < tmpMacro.transform.childCount; i++)
                {
                    tmpMacro.transform.GetChild(i).SetParent(macro.RootObject.transform);
                    i--;
                }
                macro.Refresh();
#if UNITY_2018_3_OR_NEWER
                GameObject prefab = PrefabUtility.SaveAsPrefabAsset(go, path);
#else
                GameObject prefab = PrefabUtility.CreatePrefab(path, go);
#endif
                AssetDatabase.SaveAssets();
                Object.DestroyImmediate(go);
                Object.DestroyImmediate(tmpMacro.gameObject);
                var macroAsset = prefab.GetComponent <uNodeMacro>();
                NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (LinkedMacroNode n) => {
                    n.macroAsset = macroAsset;
                    n.editorRect = node.editorRect;
                    NodeEditorUtility.AddNewObject(graph.editorData.graph, "pins", n.transform, (pin) => {
                        n.pinObject = pin;
                        n.Refresh();
                        RefactorUtility.RetargetNode(node, n);
                        if (n.inputFlows.Count == node.inputFlows.Count)
                        {
                            for (int i = 0; i < n.inputFlows.Count; i++)
                            {
                                RefactorUtility.RetargetNode(node.inputFlows[i], n.inputFlows[i]);
                            }
                        }
                        if (n.inputValues.Count == node.inputValues.Count)
                        {
                            for (int i = 0; i < n.inputValues.Count; i++)
                            {
                                n.inputValues[i].target = new MemberData(node.inputValues[i].target);
                            }
                        }
                        if (n.outputFlows.Count == node.outputFlows.Count)
                        {
                            for (int i = 0; i < n.outputFlows.Count; i++)
                            {
                                n.outputFlows[i].target = new MemberData(node.outputFlows[i].target);
                            }
                        }
                        if (n.outputValues.Count == node.outputValues.Count)
                        {
                            for (int i = 0; i < n.outputValues.Count; i++)
                            {
                                RefactorUtility.RetargetNode(node.outputValues[i], n.outputValues[i]);
                            }
                        }
                    });
                });
                NodeEditorUtility.RemoveNode(graph.editorData, node);
            }
            graph.Refresh();
        }
Пример #11
0
 public Expression Transform(MacroNode item)
 {
     throw new NotImplementedException();
 }
Пример #12
0
 public IEnumerable <bool> Transform(MacroNode item)
 {
     return(item.Contents.Transform(this));
 }
 public void Transform(MacroNode item)
 {
     TransformASTNode(item);
 }
Пример #14
0
 public ActiveMacro(MacroNode node, string contents)
 {
     this.Node  = node;
     this.Steps = MacroParser.Parse(contents).ToList();
 }
Пример #15
0
 public ActiveMacro(MacroNode node)
     : this(node, node.Contents)
 {
 }
Пример #16
0
            public static int Run(MacroNode macroNode, string path, string filename, int SnapCount, ImageExtensions extensions, bool saveScreen)
            {
                try
                {
                    ManualResetEvent stoppeing_event_ = new ManualResetEvent(false);
                    stoppeing_event_.Reset();

                    switch (macroNode.state)
                    {
                    case NodeStates.마우스_이동:
                        SetCursorPos(macroNode.x, macroNode.y);
                        break;

                    case NodeStates.마우스_왼쪽클릭:
                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                        break;

                    case NodeStates.마우스_오른쪽클릭:
                        mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
                        break;

                    case NodeStates.마우스_더블클릭:
                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                        break;

                    case NodeStates.마우스_휠클릭:
                        mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);

                        break;

                    case NodeStates.마우스_이동_후_왼쪽클릭:
                        SetCursorPos(macroNode.x, macroNode.y);
                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                        break;

                    /*
                     * case NodeStates.마우스_휠_내리기:
                     * mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 0, 2);
                     * break;
                     *
                     * case NodeStates.마우스_휠_올리기:
                     * mouse_event(MOUSEEVENTF_HWHEEL, 0, 0, 0, 2);
                     * break;
                     */
                    case NodeStates.마우스_누르기_왼쪽:
                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        break;

                    case NodeStates.마우스_떼기_왼쪽:
                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                        break;

                    case NodeStates.마우스_누르기_오른쪽:
                        mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
                        break;

                    case NodeStates.마우스_떼기_오른쪽:
                        mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
                        break;

                    case NodeStates.마우스_누르기_휠:
                        mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
                        break;

                    case NodeStates.마우스_떼기_휠:
                        mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
                        break;

                    case NodeStates.시스템_대기:
                        break;

                    case NodeStates.시스템_스크린샷찍기:
                        if (saveScreen)
                        {
                            ScreenSave(string.Format("{0}\\{1}", path, filename), SnapCount++, extensions);
                        }
                        break;

                    case NodeStates.키보드_키입력:
                        SendKeyInterval(macroNode.inputString);
                        break;
                    }
                    stoppeing_event_.WaitOne(macroNode.interval);
                    return(SnapCount);
                }
                catch (Exception e)
                {
                    MessageBox.Show("EXCEPTION : \r\n" + e.Message);
                    return(-1);
                }
            }
Пример #17
0
 public void Transform(MacroNode item, bool inner = false)
 {
     SetTrim(item.WhiteSpaceControl.Start);
     item.Contents.Transform(this, inner: true);
     _WhiteSpaceMode = item.WhiteSpaceControl.End;
 }
Пример #18
0
    private void ShowModuleViewGUI()
    {
        GUI.Label(new Rect(10, 50, 160, 20), "Create Nodes:");

        if (GUI.Button(new Rect(10, 70, 100, 20), "New Generator"))
        {
            GeneratorNode g = new GeneratorNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
            g.seed = Random.Range(-10000, 10000);
            settings.nodes.Add(g);
            windows.Add(new NodeWindow(g));
        }
        if (GUI.Button(new Rect(120, 70, 100, 20), "New Operator"))
        {
            OperatorNode o = new OperatorNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
            settings.nodes.Add(o);
            windows.Add(new NodeWindow(o));
        }
        if (GUI.Button(new Rect(230, 70, 100, 20), "New Macro"))
        {
            MacroNode m = new MacroNode((int)scrollPos.x + 200, (int)scrollPos.y + 200);
            settings.nodes.Add(m);
            windows.Add(new NodeWindow(m));
        }

        scrollPos = GUI.BeginScrollView(new Rect(10, 95, this.position.width - 10, this.position.height - 105), scrollPos, scrollRect);

        BeginWindows();

        foreach (NodeWindow n in windows)
        {
            // show the window
            Rect rect = n.Show();

            // delete button
            if (!(n.node is OutputNode))
            {
                if (GUI.Button(new Rect(rect.x + rect.width - 20, rect.y - 16, 20, 16), "x"))
                {
                    toBeRemoved.Add(n);
                }
            }

            // input port buttons
            if (n.node.Inputs != null)
            {
                for (int i = 0; i < n.node.Inputs.Length; i++)
                {
                    Rect input = new Rect(rect.x - 14,
                                          (rect.y + rect.height / 2 - 7) + i * 20f - (n.node.Inputs.Length - 1) * 20f / 2,
                                          14,
                                          14);

                    if (!isConnecting)
                    {
                        if (GUI.Button(input, ""))
                        {
                            isConnecting = true;
                            isInput      = true;
                            selectedNode = n.node;
                            selectedPort = i;
                        }
                    }
                    else
                    {
                        if (!isInput)
                        {
                            if (GUI.Button(input, ""))
                            {
                                n.node.Connect(selectedNode, i);
                                n.UpdatePreview();
                                isConnecting = false;
                            }
                        }
                    }
                    // draw connections
                    if (n.node.Inputs[i] != null)
                    {
                        DrawBezier(n.node.Inputs[i].Rect.ToRect(), input, n.connectionColor);
                    }
                }
            }

            // output button
            if (n.node.HasOutput)
            {
                Rect output = new Rect(rect.x + rect.width - 2,
                                       rect.y + rect.height / 2 - 7,
                                       14,
                                       14);
                if (!isConnecting)
                {
                    if (GUI.Button(output, ""))
                    {
                        isConnecting = true;
                        isInput      = false;
                        selectedNode = n.node;
                    }
                }
                else
                {
                    if (isInput)
                    {
                        if (GUI.Button(output, ""))
                        {
                            selectedNode.Connect(n.node, selectedPort);
                            UpdateNodeWindow(selectedNode);
                            isConnecting = false;
                        }
                    }
                }
            }
        }

        EndWindows();

        GUI.EndScrollView();
    }