public static bool ConfirmFeature(FeatureBuilder feature, string methodName)
        {
            const ConsoleColor ColorPrompt    = Log.ColorPrompt;
            const ConsoleColor ColorSelection = Log.ColorPrintInfo;
            string             name           = feature.FeatureName;
            string             type           = feature.FeatureType;

            void LogSelection(string prompt, string selection)
            {
                Log.Write(prompt, ColorPrompt);
                Log.WriteLine(selection, ColorSelection);
            }

            Log.WriteLine();
            LogSelection("FEATURE NAME: ", name);
            LogSelection("FEATURE TYPE: ", type);
            LogSelection("CLASS NAME: ", feature.ClassName);
            LogSelection("TEMPLATE NAME: ", feature.TemplateName);
            LogSelection("METHOD NAME: ", $"{methodName}()");
            Log.WriteLine();

            Log.Write("Type ", ColorPrompt);
            Log.Write("Y", ColorSelection);
            Log.Write("/", ColorPrompt);
            Log.Write("y", ColorSelection);
            Log.WriteLine(" to confirm.", ColorPrompt);
            string line = Log.ReadStringFromConsole();

            Log.WriteLine();

            bool ret = line.Equals("y", StringComparison.InvariantCultureIgnoreCase);

            return(ret);
        }
Exemple #2
0
        /// <summary>
        /// Attaches a new feature to a given the Unity object of a given Object Pool
        /// by adding an entry for the given feature's prefab to the metadata
        /// of the Object Pool.
        /// </summary>
        /// <param name="feature">The feature to add.</param>
        /// <param name="guidPrefab">The GUID of the new feature's prefab.</param>
        /// <param name="fileId">The file ID of the new feature's prefab.</param>
        private static void AppendPoolListPrefabData(FeatureBuilder feature, string guidPrefab, string fileId)
        {
            string poolPrefabPath = feature.PathObjectPool.Prefab;
            string featureName    = feature.FeatureName;

            Debug.Assert(File.Exists(poolPrefabPath));
            string prefabToAdd = $"  {featureName}Prefab: {{fileID: {fileId}, guid: {guidPrefab},\r\n    type: 3}}\r\n";

            File.AppendAllText(poolPrefabPath, prefabToAdd);
        }
Exemple #3
0
        /// <summary>
        /// Inserts a given GUID into the metadata file of a given feature's
        /// code template file, then writes the results to its proper destination.
        /// </summary>
        /// <param name="feature">The feature to add.</param>
        /// <param name="guidCs">The GUID to insert.</param>
        private static void WriteCsMetaContents(FeatureBuilder feature, string guidCs)
        {
            string templatePath      = feature.PathTemplate.CsMeta;
            string csMetaDestination = feature.PathDestination.CsMeta;

            Debug.Assert(File.Exists(templatePath));
            Debug.Assert(!File.Exists(csMetaDestination));

            string contents = File.ReadAllText(templatePath);

            contents = contents.Replace(TagGuidCS, guidCs);

            File.WriteAllText(csMetaDestination, contents);
        }
Exemple #4
0
        /// <summary>
        /// Inserts a given GUID and file ID into the prefab file of a given feature,
        /// then writes the results to its proper destination.
        /// </summary>
        /// <param name="feature">The feature to add.</param>
        /// <param name="guidCs">The GUID to insert.</param>
        /// <param name="fileId">The file ID to insert.</param>
        private static void WritePrefabContents(FeatureBuilder feature, string guidCs, string fileId)
        {
            string templatePath      = feature.PathTemplate.Prefab;
            string prefabDestination = feature.PathDestination.Prefab;

            Debug.Assert(File.Exists(templatePath));
            Debug.Assert(!File.Exists(prefabDestination));

            StringBuilder sb = StringBuilderFromFile(templatePath);

            sb.Replace(TagFileId, fileId);
            sb.Replace(TagGuidCS, guidCs);

            string contents = sb.ToString();

            File.WriteAllText(prefabDestination, contents);
        }
Exemple #5
0
        /// <summary>
        /// Generates a new GUID and File ID for a given feature.
        /// Then, it uses this information to copy a metadata file, a prefab file,
        /// and a prefab metadata file based on the feature's information.
        /// </summary>
        public static void CopyPrefabData(FeatureBuilder feature)
        {
            FileInfo csFileInfo = new FileInfo(feature.PathTemplate.Cs);

            #region Assert
            Debug.Assert(csFileInfo.Exists);
            Debug.Assert(csFileInfo.Extension == ".cs");
            Debug.Assert(Directory.Exists(feature.DirDestination));
            #endregion Assert

            string guidCs     = NewGuid();
            string guidPrefab = NewGuid();
            string fileId     = NewFileId();

            WriteCsMetaContents(feature, guidCs);
            WritePrefabContents(feature, guidCs, fileId);
            WritePrefabMetaContents(feature, guidPrefab);
            AppendPoolListPrefabData(feature, guidPrefab, fileId);
        }
        /// <summary>
        /// Reads a feature's template file,
        /// replaces the template name inside file with the feature's name,
        /// and writes the feature file to its destination.
        /// </summary>
        public static void CopyNewFeatureCsFile(FeatureBuilder feature)
        {
            string templateFilePath     = feature.PathTemplate.Cs;
            string destinationDirectory = feature.DirDestination;
            string destinationPath      = feature.PathDestination.Cs;
            string featureName          = feature.FeatureName;
            string templateName         = feature.TemplateName;

            #region Assert
            FileInfo fileInfo = new FileInfo(templateFilePath);
            Debug.Assert(fileInfo.Exists);
            Debug.Assert(fileInfo.Extension == ".cs");
            Debug.Assert(Directory.Exists(destinationDirectory));
            Debug.Assert(!File.Exists(destinationPath));
            #endregion Assert

            string fileContents = feature.ReadTemplateCsFileContents();
            fileContents = fileContents.Replace(templateName, featureName);

            File.WriteAllText(destinationPath, fileContents);

            AddCsFileToProjectCompile(feature);
        }
        /// <summary>
        /// Adds a given feature's source code file path
        /// to the project's compilation files list.
        /// </summary>
        public static void AddCsFileToProjectCompile(FeatureBuilder feature)
        {
            string filePath        = feature.PathDestination.Cs;
            string filePathTrimmed = filePath.Replace(UnityPaths.DirProject, "");
            string pathCsProj      = UnityPaths.PathCsproj;

            #region Assert
            Debug.Assert(File.Exists(filePath));
            Debug.Assert(File.Exists(pathCsProj));
            Debug.Assert(filePathTrimmed.StartsWith("Assets\\"));
            Debug.Assert(filePathTrimmed.EndsWith(".cs"));
            #endregion Assert

            string[] lines      = File.ReadAllLines(pathCsProj);
            int      endTagLine = FindCsprojCompilationItemGroupLine(lines);

            const string CompileTagStart = "    <Compile Include=\"";
            const string CompileTagEnd   = "\" />";

            string compileTag = $"{CompileTagStart}{filePathTrimmed}{CompileTagEnd}";

            InsertLineToFile(pathCsProj, lines, compileTag, endTagLine, true);
        }
        /// <summary>
        /// Adds a variable for a feature's prefab inside the appropriate Object Pool file.
        /// </summary>
        /// <param name="feature">The feature to add.</param>
        public static void AppendPrefabVariableToPoolListCs(FeatureBuilder feature)
        {
            string filePath = feature.PathObjectPool.Cs;

            Debug.Assert(File.Exists(filePath));

            string endTag      = feature.TagPrefab;
            string featureName = feature.FeatureName;
            string className   = feature.ClassName;

            string[] lines      = File.ReadAllLines(filePath);
            int      endTagLine = FindEndTagLine(endTag, lines, filePath);

            #region Assert
            // Assert coding style - one line of blank space
            // between last prefab and end tag.
            string _blankLine      = lines[endTagLine + 1];
            string _lastPrefabLine = lines[endTagLine];
            Debug.Assert(String.IsNullOrWhiteSpace(_blankLine));
            Debug.Assert(!String.IsNullOrWhiteSpace(_lastPrefabLine));
            #endregion Assert

            const string SerializeTag = "        [SerializeField]";
            const string Private      = "        private";

            string variableName = $"{featureName}Prefab";
            string variableLine = $"{Private} {className} {variableName} = null;";

            string[] linesToAdd = new string[]
            {
                SerializeTag,
                variableLine
            };

            int insertLineNumber = endTagLine - 1;
            InsertLinesToFile(filePath, lines, linesToAdd, insertLineNumber, true);
        }
 public static void LogProgress(string descriptor, FeatureBuilder feature)
 {
     Log.WriteLine($"Adding {descriptor} {feature.ClassName}...", Log.ColorMetaInfo);
 }
 public static void LogProgress(FeatureBuilder feature)
 {
     Log.WriteLine($"Adding {feature.ClassName}...", Log.ColorMetaInfo);
 }
 public static void AddFeatureWithPrefab(FeatureBuilder feature)
 {
     FileUtil.CopyNewFeatureCsFile(feature);
     PrefabUtil.CopyPrefabData(feature);
     FileUtil.AppendPrefabVariableToPoolListCs(feature);
 }