Beispiel #1
0
        async Task Listen()
        {
            var token = _cancellationTokenSource.Token;

            string last = null;

            while (!token.IsCancellationRequested && !token.WaitHandle.WaitOne(500))
            {
                string clipboard = Clipboard.GetText(); // Get clipboard.
                if (clipboard == last || clipboard == null)
                {
                    continue;                                         // Clipboard did not change.
                }
                last = clipboard;

                // Clipboard changed.

                try
                {
                    // As workshop actions
                    ConvertTextToElement tte      = new ConvertTextToElement(clipboard);
                    Workshop             workshop = tte.GetActionList();

                    if (workshop != null) // Determines if the clipboard is an action list.
                    {
                        DebuggerActionSetResult actionStream = new DebuggerActionSetResult(workshop);

                        // Action list successfully parsed.
                        // Get the DeltinScript.
                        VariableCollection = (await _languageServer.DocumentHandler.OnScriptAvailability())?.DebugVariables;

                        // Error obtaining debug variables.
                        if (VariableCollection == null)
                        {
                            return;
                        }

                        // Apply debugger variables.
                        VariableCollection.Apply(actionStream);

                        // Notify the adapter of the new state.
                        _languageServer.Server.SendNotification("debugger.activated");
                    }
                }
                catch (Exception ex)
                {
                    _languageServer.DebuggerException(ex);
                }
            }
        }
Beispiel #2
0
        public static Pathmap ImportFromActionSet(string text, IPathmapErrorHandler errorHandler)
        {
            ConvertTextToElement tte      = new ConvertTextToElement(text);
            Workshop             workshop = tte.GetActionList();

            Vertex[] nodeArray      = null;
            Vertex[] segmentArray   = null;
            Vertex[] attributeArray = null;

            const string nodesOut = "nodesOut", segmentsOut = "segmentsOut", attributesOut = "attributesOut";

            // Get the variable values.
            foreach (var action in workshop.Actions)
            {
                if (action is SetVariableAction setVariable)
                {
                    // Get the variable name.
                    switch (setVariable.Variable.Name)
                    {
                    // Nodes
                    case nodesOut:
                        nodeArray = ExtractVertexArray(nodesOut, errorHandler, setVariable.Value);
                        break;

                    // Segments
                    case segmentsOut:
                        segmentArray = ExtractVertexArray(segmentsOut, errorHandler, setVariable.Value);
                        break;

                    // Attributes
                    case attributesOut:
                        attributeArray = ExtractVertexArray(attributesOut, errorHandler, setVariable.Value);
                        break;
                    }
                }
            }

            if (nodeArray == null)
            {
                errorHandler.Error($"Incorrect format, '{nodesOut}' does not exist. Did you compile your pathmap?");
                return(null);
            }
            if (segmentArray == null)
            {
                errorHandler.Error($"Incorrect format, '{segmentsOut}' does not exist. Did you compile your pathmap?");
                return(null);
            }
            if (attributeArray == null)
            {
                errorHandler.Error($"Incorrect format, '{attributesOut}' does not exist. Did you compile your pathmap?");
                return(null);
            }

            Segment[] segments = new Segment[segmentArray.Length];
            for (int i = 0; i < segments.Length; i++)
            {
                segments[i] = new Segment((int)segmentArray[i].X, (int)segmentArray[i].Y);
            }

            MapAttribute[] attributes = new MapAttribute[attributeArray.Length];
            for (int i = 0; i < attributes.Length; i++)
            {
                attributes[i] = new MapAttribute(
                    (int)attributeArray[i].X,
                    (int)attributeArray[i].Y,
                    (int)attributeArray[i].Z
                    );
            }

            return(new Pathmap(nodeArray, segments, attributes));
        }