예제 #1
0
        private VectorType() : base("Vector")
        {
            CanBeDeleted  = false;
            CanBeExtended = false;
            Kind          = "struct";

            X = CreateInternalVar("X", "The X component of the vector.");
            Y = CreateInternalVar("Y", "The Y component of the vector.");
            Z = CreateInternalVar("Z", "The Z component of the vector.");
            HorizontalAngle = CreateInternalVar("HorizontalAngle", "The horizontal angle of the vector.");
            VerticalAngle   = CreateInternalVar("VerticalAngle", "The vertical angle of the vector.");
            Zero            = CreateInternalVar("Zero", "Equal to `Vector(0, 0, 0)`.", true);

            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <DistanceTo>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <CrossProduct>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <DotProduct>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <Normalize>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <DirectionTowards>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <FarthestPlayer>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <ClosestPlayer>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <IsInLineOfSight>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <Towards>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <AsLocalVector>());
            objectScope.AddNativeMethod(CustomMethodData.GetCustomMethod <AsWorldVector>());
        }
예제 #2
0
 public AssetClass() : base("Asset")
 {
     Description = "Contains functions for displaying assets in the world.";
     StaticScope.AddNativeMethod(CustomMethodData.GetCustomMethod <ShowModel>());
     StaticScope.AddNativeMethod(CustomMethodData.GetCustomMethod <CreateTextWithFont>());
     StaticScope.AddNativeMethod(CustomMethodData.GetCustomMethod <CreateTextFancy>());
     StaticScope.AddNativeMethod(CustomMethodData.GetCustomMethod <CreateText>());
 }
예제 #3
0
        public IMethod GetMethod(ScopeGroup getter, string name, Location location)
        {
            // Get the method by it's name.
            IMethod method = GetScopeable <UserMethod>(getter, name)
                             // If it is not found, check if its a workshop method.
                             ?? (IMethod)Element.GetElement(name)
                             // Then check if its a custom method.
                             ?? (IMethod)CustomMethodData.GetCustomMethod(name);

            // Throw if not found.
            if (method == null && location != null)
            {
                throw SyntaxErrorException.NonexistentMethod(name, location);
            }
            return(method);
        }
예제 #4
0
        public override void ResolveElements()
        {
            if (elementsResolved)
            {
                return;
            }
            base.ResolveElements();

            serveObjectScope.AddMethod(CustomMethodData.GetCustomMethod <Pathfind>(), null, null);
            serveObjectScope.AddMethod(CustomMethodData.GetCustomMethod <PathfindAll>(), null, null);
            serveObjectScope.AddMethod(CustomMethodData.GetCustomMethod <GetPath>(), null, null);

            staticScope.AddMethod(CustomMethodData.GetCustomMethod <StopPathfind>(), null, null);
            staticScope.AddMethod(CustomMethodData.GetCustomMethod <IsPathfinding>(), null, null);
            staticScope.AddMethod(CustomMethodData.GetCustomMethod <IsPathfindStuck>(), null, null);
            staticScope.AddMethod(CustomMethodData.GetCustomMethod <FixPathfind>(), null, null);
            staticScope.AddMethod(CustomMethodData.GetCustomMethod <NextNode>(), null, null);
            staticScope.AddMethod(CustomMethodData.GetCustomMethod <WalkPath>(), null, null);
        }
예제 #5
0
        public PathmapClass() : base("Pathmap")
        {
            this.Constructors = new Constructor[] {
                new PathmapClassConstructor(this)
            };
            Description = "A pathmap can be used for pathfinding.";

            ObjectScope = new Scope("class Pathmap");
            ObjectScope.AddMethod(CustomMethodData.GetCustomMethod <Pathfind>(), null, null);
            ObjectScope.AddMethod(CustomMethodData.GetCustomMethod <PathfindAll>(), null, null);
            ObjectScope.AddMethod(CustomMethodData.GetCustomMethod <GetPath>(), null, null);

            StaticScope = new Scope("class Pathmap");
            StaticScope.AddMethod(CustomMethodData.GetCustomMethod <StopPathfind>(), null, null);
            StaticScope.AddMethod(CustomMethodData.GetCustomMethod <IsPathfinding>(), null, null);
            StaticScope.AddMethod(CustomMethodData.GetCustomMethod <IsPathfindStuck>(), null, null);
            StaticScope.AddMethod(CustomMethodData.GetCustomMethod <FixPathfind>(), null, null);
            StaticScope.AddMethod(CustomMethodData.GetCustomMethod <NextNode>(), null, null);
            StaticScope.AddMethod(CustomMethodData.GetCustomMethod <WalkPath>(), null, null);
        }
 public IMethod GetMethod(string name)
 {
     return((IMethod)UserMethods?.FirstOrDefault(um => um.Name == name)
            ?? (IMethod)CustomMethodData.GetCustomMethod(name)
            ?? (IMethod)Element.GetElement(name));
 }
예제 #7
0
        string GetAutocomplete(string json)
        {
            /*
             *  Format:
             *      textDocument
             *      caret
             *          caret.line
             *          caret.character
             */
            PosData posData = GetPosData(json);

            if (posData == null)
            {
                return(null);
            }

            List <CompletionItem> completion = new List <CompletionItem>();

            if (posData.SelectedNode != null)
            {
                switch (posData.SelectedNode.FirstOrDefault())
                {
                // Ruleset
                case RulesetNode rulesetNode:

                    completion.AddRange(new CompletionItem[]
                    {
                        new CompletionItem("rule")
                        {
                            kind = CompletionItem.Keyword, textEdit = TextEdit.Insert(posData.Caret, Extras.Lines(
                                                                                          "rule: \"My Rule\"",
                                                                                          "Event.OngoingGlobal",
                                                                                          "{",
                                                                                          "}"
                                                                                          ))
                        },
                        new CompletionItem("define")
                        {
                            kind = CompletionItem.Keyword
                        },
                        new CompletionItem("method")
                        {
                            kind = CompletionItem.Keyword, textEdit = TextEdit.Insert(posData.Caret, Extras.Lines(
                                                                                          "method myMethod()",
                                                                                          "{",
                                                                                          "}"
                                                                                          ))
                        }
                    });
                    break;

                // Rule node
                case RuleNode ruleNode:

                    // Event type
                    if (ruleNode.IsEventOptionSelected(posData.Caret))
                    {
                        completion.AddRange(EnumData.GetEnum <RuleEvent>().GetCompletion());
                    }

                    // Player
                    else if (ruleNode.IsPlayerOptionSelected(posData.Caret))
                    {
                        completion.AddRange(EnumData.GetEnum <PlayerSelector>().GetCompletion());
                    }

                    // Team
                    else if (ruleNode.IsTeamOptionSelected(posData.Caret))
                    {
                        completion.AddRange(EnumData.GetEnum <Team>().GetCompletion());
                    }

                    else if (ruleNode.IsIfSelected(posData.Caret))
                    {
                        completion.AddRange(Element.GetCompletion(true, false));
                    }

                    else
                    {
                        completion.AddRange(new CompletionItem[]
                        {
                            new CompletionItem("Event")
                            {
                                kind = CompletionItem.Enum
                            },
                            new CompletionItem("Team")
                            {
                                kind = CompletionItem.Enum
                            },
                            new CompletionItem("Player")
                            {
                                kind = CompletionItem.Enum
                            },
                        });
                    }
                    break;

                // Actions
                case BlockNode blockNode:

                    // Get all action methods
                    completion.AddRange(Element.GetCompletion(true, true));
                    completion.AddRange(CustomMethodData.GetCompletion());

                    if (parserData.Success)
                    {
                        // Get all variables
                        if (blockNode.RelatedScopeGroup != null)
                        {
                            completion.AddRange(blockNode.RelatedScopeGroup.GetCompletionItems(posData.Caret));
                        }
                        // Get custom methods
                        if (parserData.UserMethods != null)
                        {
                            completion.AddRange(UserMethod.CollectionCompletion(parserData.UserMethods.ToArray()));
                        }
                        // Get structs
                        if (parserData.DefinedTypes != null)
                        {
                            completion.AddRange(DefinedType.CollectionCompletion(parserData.DefinedTypes.ToArray()));
                        }
                    }

                    break;

                // Values
                case MethodNode methodNode:

                    completion.AddRange(Element.GetCompletion(true, false));
                    completion.AddRange(EnumData.GetAllEnumCompletion());
                    completion.AddRange(CustomMethodData.GetCompletion());

                    if (parserData.Success)
                    {
                        // Get all variables
                        if (methodNode.RelatedScopeGroup != null)
                        {
                            completion.AddRange(methodNode.RelatedScopeGroup?.GetCompletionItems(posData.Caret));
                        }
                        // Get custom methods
                        if (parserData.UserMethods != null)
                        {
                            completion.AddRange(UserMethod.CollectionCompletion(parserData.UserMethods.ToArray()));
                        }
                    }

                    break;

                // If the selected node is a string node, show all strings.
                case StringNode stringNode:

                    completion.AddRange(Constants.Strings.Select(str =>
                                                                 new CompletionItem(str)
                    {
                        kind = CompletionItem.Text
                    }
                                                                 ));

                    break;

                case EnumNode enumNode:
                    var add = EnumData.GetEnum(enumNode.Type)?.GetCompletion();

                    if (add != null)
                    {
                        completion.AddRange(add);
                    }

                    break;

                case ImportNode importNode:

                    string currentPath = importNode.File;

                    string path = Extras.CombinePathWithDotNotation(posData.File, importNode.File);

                    if (path != null)
                    {
                        completion.Add(new CompletionItem("../")
                        {
                            kind = CompletionItem.Folder
                        });

                        // GetDirectoryName can return null even if path isn't null.
                        path = Path.GetDirectoryName(path);

                        if (path != null)
                        {
                            foreach (string fullDirectoryPath in Directory.GetDirectories(path))
                            {
                                string directory = new DirectoryInfo(fullDirectoryPath).Name;
                                completion.Add(new CompletionItem(directory)
                                {
                                    kind = CompletionItem.Folder
                                });
                            }
                            foreach (string fullFilePath in Directory.GetFiles(path))
                            {
                                string file = Path.GetFileName(fullFilePath);
                                completion.Add(new CompletionItem(file)
                                {
                                    kind = CompletionItem.File
                                });
                            }
                        }
                    }

                    break;
                }
            }

            return(JsonConvert.SerializeObject(completion.ToArray()));
        }