Ejemplo n.º 1
0
    // Checks a given string for spelling errors.
    // Returns a Dictionary in the form {index : word}
    public static Godot.Collections.Dictionary <int, string> CheckString(string input)
    {
        var outputDict = new Godot.Collections.Dictionary <int, string>();

        // For each character
        var currentWord = "";

        for (var i = 0; i < input.Length; i++)
        {
            var currentChar = input[i];

            // If at a space character or final character, current word is complete.
            var isLastCharacter = i >= input.Length - 1;

            if ((!char.IsLetterOrDigit(currentChar) && currentChar != '-' && currentChar != '\'') || isLastCharacter)
            {
                if (isLastCharacter && char.IsLetterOrDigit(currentChar))
                {
                    currentWord += currentChar;
                }

                Hunspell.Spell(currentWord);

                // If word has incorrect spelling, add index and word to dictionary.
                if (!IsWordCorrect(currentWord))
                {
                    outputDict.Add(i, currentWord);
                }


                // Clear and move onto next word
                currentWord = "";

                continue;
            }

            currentWord += currentChar;
        }

        return(outputDict);
    }
Ejemplo n.º 2
0
        public static void GenerateScriptsMetadata(string projectPath, string outputPath)
        {
            if (File.Exists(outputPath))
            {
                File.Delete(outputPath);
            }

            var oldDict = Internal.GetScriptsMetadataOrNothing();
            var newDict = new Godot.Collections.Dictionary <string, object>();

            foreach (var includeFile in ProjectUtils.GetIncludeFiles(projectPath, "Compile"))
            {
                string projectIncludeFile = ("res://" + includeFile).SimplifyGodotPath();

                ulong modifiedTime = File.GetLastWriteTime(projectIncludeFile).ConvertToTimestamp();

                if (oldDict.TryGetValue(projectIncludeFile, out var oldFileVar))
                {
                    var oldFileDict = (Dictionary)oldFileVar;

                    if (ulong.TryParse(oldFileDict["modified_time"] as string, out ulong storedModifiedTime))
                    {
                        if (storedModifiedTime == modifiedTime)
                        {
                            // No changes so no need to parse again
                            newDict[projectIncludeFile] = oldFileDict;
                            continue;
                        }
                    }
                }

                ScriptClassParser.ParseFileOrThrow(projectIncludeFile, out var classes);

                string searchName = System.IO.Path.GetFileNameWithoutExtension(projectIncludeFile);

                var classDict = new Dictionary();

                foreach (var classDecl in classes)
                {
                    if (classDecl.BaseCount == 0)
                    {
                        continue; // Does not inherit nor implement anything, so it can't be a script class
                    }
                    string classCmp = classDecl.Nested ?
                                      classDecl.Name.Substring(classDecl.Name.LastIndexOf(".", StringComparison.Ordinal) + 1) :
                                      classDecl.Name;

                    if (classCmp != searchName)
                    {
                        continue;
                    }

                    classDict["namespace"]  = classDecl.Namespace;
                    classDict["class_name"] = classDecl.Name;
                    classDict["nested"]     = classDecl.Nested;
                    break;
                }

                if (classDict.Count == 0)
                {
                    continue; // Not found
                }
                newDict[projectIncludeFile] = new Dictionary {
                    ["modified_time"] = $"{modifiedTime}", ["class"] = classDict
                };
            }

            if (newDict.Count > 0)
            {
                string json = JSON.Print(newDict);

                string baseDir = outputPath.GetBaseDir();

                if (!Directory.Exists(baseDir))
                {
                    Directory.CreateDirectory(baseDir);
                }

                File.WriteAllText(outputPath, json);
            }
        }