Пример #1
0
        private static void MainMenu()
        {
            IMenuOption[] menuOptions = new IMenuOption[]
            {
                new RunPresetOption(),
                new CollectionCreationOption(),
                new OutputListOption()
            };

            do
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"{currentGame.Name} Encount Music Editor");
                Console.ResetColor();

                for (int i = 0, total = menuOptions.Length; i < total; i++)
                {
                    Console.WriteLine($"{i + 1}. {menuOptions[i].Name}");
                }
                Console.WriteLine("0. Exit");

                int choice = ConsolePrompt.PromptInt("Choice");

                if (choice == 0)
                {
                    return;
                }
                else if (choice - 1 < menuOptions.Length)
                {
                    menuOptions[choice - 1].Run(currentGame);
                }
            }while (true);
        }
Пример #2
0
        private static void SetupGame()
        {
            int selectedGameInput = -1;

            do
            {
                Console.WriteLine("Select Persona Game");

                // display list of available games as choices, starting at 1
                foreach (GameTitle game in Enum.GetValues(typeof(GameTitle)))
                {
                    Console.WriteLine($"{(int)game + 1}. {game}");
                }

                // save temp choice
                int tempChoice = ConsolePrompt.PromptInt("Game");

                // save and exit prompt if game choice is valid
                if (Enum.IsDefined(typeof(GameTitle), tempChoice - 1))
                {
                    selectedGameInput = tempChoice - 1;
                }
            }while (selectedGameInput < 0);

            GameTitle selectedGame = (GameTitle)selectedGameInput;

            currentGame = new GameProps(selectedGame);
        }
        private string SelectPresetFile()
        {
            string[] allPresets = null;

            try
            {
                allPresets = Directory.GetFiles(presetsFolderDir, "*.preset", SearchOption.AllDirectories);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Problem reading presets from folder!");
                return(null);
            }

            // exit if no presets were found
            if (allPresets.Length < 1)
            {
                return(null);
            }

            // display all presets
            Console.WriteLine("Available Presets");
            for (int i = 0, total = allPresets.Length; i < total; i++)
            {
                Console.WriteLine($"{i + 1}. {Path.GetFileNameWithoutExtension(allPresets[i])}");
            }

            // get valid preset choice
            int presetSelection = -1;

            do
            {
                int tempChoice = ConsolePrompt.PromptInt("Preset Selection");
                if (tempChoice > allPresets.Length)
                {
                    Console.WriteLine("Invalid selection!");
                }
                else
                {
                    presetSelection = tempChoice;
                }
            } while (presetSelection < 1);

            return(allPresets[presetSelection - 1]);
        }
        public void ExtendSongsList()
        {
            int newNumSongs = ConsolePrompt.PromptInt("New Total Songs");

            string originalConversionFile = $@"{currentDir}\music manager\idtowaveindex_original.json";
            string outputConversionFile   = $@"{currentDir}\music manager\idtowaveindex.json";

            string originalNamesFile = $@"{currentDir}\music manager\songnames_original.json";
            string outputNamesFile   = $@"{currentDir}\music manager\songnames.json";

            idtowaveindex originalConversions = ParseConversionFile(originalConversionFile);

            if (originalConversions == null)
            {
                return;
            }

            songnames originalNames = ParseNamesFile(originalNamesFile);

            if (originalNames == null)
            {
                return;
            }

            int normalNumSongs = originalConversions.conversions.Length;

            // new array of conversion objects with new total
            conversionObject[] newConversionList = new conversionObject[newNumSongs];
            nameObject[]       newNamesList      = new nameObject[newNumSongs];

            // copy original list to new list
            Array.Copy(originalConversions.conversions, newConversionList, originalConversions.conversions.Length);
            Array.Copy(originalNames.names, newNamesList, originalNames.names.Length);

            int startingIndex = 886;

            for (int i = normalNumSongs, total = newNumSongs, indexCounter = 0; i < total; i++, indexCounter++)
            {
                conversionObject newConversion = new conversionObject();
                newConversion.trackID   = i.ToString();
                newConversion.uwusID    = null;
                newConversion.waveIndex = (startingIndex + indexCounter).ToString();
                newConversionList[i]    = newConversion;

                nameObject newName = new nameObject();
                newName.id        = i.ToString();
                newName.trackName = $"(BGME) Song Index {newConversion.waveIndex}";
                newNamesList[i]   = newName;
            }

            originalConversions.conversions = newConversionList;
            originalNames.names             = newNamesList;

            string newConversionText = JsonSerializer.Serialize <idtowaveindex>(originalConversions, new JsonSerializerOptions {
                WriteIndented = true
            });
            string newNamesText = JsonSerializer.Serialize <songnames>(originalNames, new JsonSerializerOptions {
                WriteIndented = true
            });

            File.WriteAllText(outputConversionFile, newConversionText);
            File.WriteAllText(outputNamesFile, newNamesText);
        }
        protected override void RunEncount()
        {
            Encounter[] encounters = GetEncountersList();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Collection Creation");
            Console.ResetColor();

            Console.WriteLine("Enter search term \"inaba\" to exit and save matches to file...");

            Dictionary <ushort, string> encounterMatches = new Dictionary <ushort, string>();

            while (true)
            {
                string searchString = ConsolePrompt.PromptString("Search Term").ToLower();
                if (searchString.Equals("inaba"))
                {
                    break;
                }

                string[] searchTerms       = searchString.Split(' ');
                bool     searchByOccurence = false;

                if (searchTerms.Length == 1)
                {
                    Console.WriteLine("Match encounters that contain only ONE instance (y) or any amount (n) of Search Term?");
                    searchByOccurence = ConsolePrompt.PromptYN("(y/n)");
                }

                int totalMatches = 0;
                for (int i = 0, total = encounters.Length; i < total; i++)
                {
                    Encounter currentEncounter = encounters[i];

                    bool foundMatch = false;

                    if (searchTerms.Length == 1)
                    {
                        if (searchByOccurence)
                        {
                            if (ContainsUnitTerm(currentEncounter.Units, searchTerms[0], 1))
                            {
                                Console.WriteLine("Found match!");
                                foundMatch = true;
                            }
                        }
                        else
                        {
                            if (ContainsUnitTerm(currentEncounter.Units, searchTerms[0]))
                            {
                                Console.WriteLine("Found match!");
                                foundMatch = true;
                            }
                        }
                    }
                    else
                    {
                        //Console.WriteLine("Searching for multiple terms...");
                        foundMatch = true;
                        // if multiple terms, check for each term in current encounter units
                        foreach (var term in searchTerms)
                        {
                            int count = searchTerms.Count(s => s.Equals(term));
                            // if encounter does not contain a term match not made
                            if (!ContainsUnitTerm(currentEncounter.Units, term, count))
                            {
                                foundMatch = false;
                                break;
                            }
                        }
                    }

                    // add to encounters list if match was found
                    if (foundMatch)
                    {
                        totalMatches++;
                        ushort matchKey = (ushort)i;
                        if (!encounterMatches.ContainsKey(matchKey))
                        {
                            Console.WriteLine($"EncounterID: {i} - Added match to collection list!");
                            StringBuilder enemiesList = new StringBuilder();
                            enemiesList.Append("//");
                            foreach (ushort enemyId in currentEncounter.Units)
                            {
                                enemiesList.Append($"{GetEnemyName(enemyId)}, ");
                            }
                            enemiesList.Append('\n');

                            encounterMatches.Add((ushort)i, enemiesList.ToString());
                        }
                    }
                }

                Console.WriteLine($"Total Matches: {totalMatches}");
            }

            string currentDir         = Directory.GetCurrentDirectory();
            string collectionName     = ConsolePrompt.PromptString("Collection Name (Lowercase)").ToLower();
            string collectionFilePath = $@"{currentDir}\collections\{collectionName}.enc";
            bool   addToFile          = false;

            if (File.Exists(collectionFilePath))
            {
                Console.WriteLine("Collection exists! Append to collection (y) or overwrite (n)?");
                addToFile = ConsolePrompt.PromptYN("(y/n)");
            }

            // write or overwrite collection file
            if (!File.Exists(collectionFilePath) || !addToFile)
            {
                StringBuilder collectionText = new StringBuilder();

                foreach (var match in encounterMatches)
                {
                    collectionText.AppendLine(match.Key.ToString());
                    collectionText.AppendLine(match.Value);
                }

                try
                {
                    File.WriteAllText(collectionFilePath, collectionText.ToString());
                    Console.WriteLine($"Collectione created! File: {collectionFilePath}");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("Problem writing collection to file!");
                }
            }
            else
            {
                // add to existing collection
                try
                {
                    string[]      originalCollectionLines = File.ReadAllLines(collectionFilePath);
                    StringBuilder newCollectionLines      = new StringBuilder();

                    // list of existing ids
                    List <ushort> existingIds = new List <ushort>();

                    // parse collection for existing ids
                    foreach (string line in originalCollectionLines)
                    {
                        newCollectionLines.AppendLine(line);
                        if (line.StartsWith("/") || line.Length < 1)
                        {
                            continue;
                        }
                        existingIds.Add(ushort.Parse(line));
                    }

                    foreach (var match in encounterMatches)
                    {
                        if (!existingIds.Contains(match.Key))
                        {
                            newCollectionLines.AppendLine(match.Key.ToString());
                            newCollectionLines.AppendLine($"{match.Value}");
                            Console.WriteLine($"EncounterID: {match.Key} added!");
                        }
                    }

                    File.WriteAllText(collectionFilePath, newCollectionLines.ToString());
                    Console.WriteLine($"Collectione edited! File: {collectionFilePath}");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("Problem adding to collection!");
                }
            }
        }