示例#1
0
        /// <summary>
        /// How to use:
        /// Specify file path of the game script that want to change.
        /// Then this tool will make directory as 'Output' to the same directory that specified it, output the changed game script to 'Output' directory.
        /// If there are some problem, output log to 'Log' directory.
        /// </summary>
        /// <param name="args">Specify file path of the game script that want to change.</param>
        public static void Main(string[] args)
        {
            // Read all of the game script lines.
            string gameScriptPath = null;

            // If the game script is not specified, notify usage.
            if (args.Length <= 0)
            {
                //if no arguments specified, look in the repository for the game file
                if (File.Exists(defaultGamePath))
                {
                    Console.WriteLine("Detected program is run from git repository - Using latest question arcs script");
                    gameScriptPath = defaultGamePath;
                }
                else
                {
                    Console.WriteLine("ERROR: No arguments provided, and game script not found in default path.");
                    Console.WriteLine("Please specify file path of the game script that want to change.");
                    Console.WriteLine("Usage: VoicesPuter <file path>");
                    return;
                }
            }
            else
            {
                gameScriptPath = args[0];
            }

            ChangedGameScriptMaker changedGameScriptMaker = new ChangedGameScriptMaker(gameScriptPath);
            List <string>          gameScriptLines        = changedGameScriptMaker.ReadGameScript();

            //setup logging
            string voiceDatabaseLogPath = Path.Combine(Path.GetDirectoryName(gameScriptPath), "Log", $"voiceDatabaseLog.utf");

            Utils.DeleteIfExists(voiceDatabaseLogPath);
            Logger voiceDatabaseLogger = new LoggerConfiguration().WriteTo.File(voiceDatabaseLogPath, outputTemplate: outputTemplate).CreateLogger();

            string voiceDelayLogPath = Path.Combine(Path.GetDirectoryName(gameScriptPath), "Log", $"voiceDelayLog.utf");

            Utils.DeleteIfExists(voiceDelayLogPath);
            Logger logger = new LoggerConfiguration().WriteTo.File(voiceDelayLogPath, outputTemplate: outputTemplate).CreateLogger();

            //scan script for dwave commands and construct a database of all dwave commands
            VoicesDatabase voicesDatabase = new VoicesDatabase(gameScriptPath, voiceDatabaseLogger);

            // Put voice scripts into Japanese line and change voice script's function name of both.
            VoicesPuter   voicesPuter            = new VoicesPuter(gameScriptPath, overwrite: true, voicesDatabase: voicesDatabase);
            List <string> changedGameScriptLines = voicesPuter.PutVoiceScriptsIntoLines(gameScriptLines, voicesDatabase);

            //fix 'voiceDelay' commands
            FixVoiceDelay.FixVoiceDelaysInScript(changedGameScriptLines, logger, logNoOldDelay: false, logSuccessfulInsertions: false);

            // Make the changed game script into output directory.
            changedGameScriptMaker.MakeChangedGameScript(changedGameScriptLines);
            Console.WriteLine("Completed putting voice scripts into Japanese lines.");
            Console.WriteLine("Press any key to close this window...");
            Console.ReadKey();
        }
示例#2
0
        /// <summary>
        /// Initialize the logger.
        /// </summary>
        /// <param name="gameScriptPath">Path of the game script.</param>
        public VoicesPuter(string gameScriptPath, bool overwrite, VoicesDatabase voicesDatabase)
        {
            this.voicesDatabase = voicesDatabase;

            string errorLogFilePath = Path.Combine(Path.GetDirectoryName(gameScriptPath), LOG_DIRECTORY_NAME, $"errlog {DateTime.Now.ToString(@"yyyy MM dd yyyy h mm ss tt")}.utf");
            string warningFilePath  = Path.Combine(Path.GetDirectoryName(gameScriptPath), LOG_DIRECTORY_NAME, $"warnlog {DateTime.Now.ToString(@"yyyy MM dd yyyy h mm ss tt")}.utf");

            if (overwrite)
            {
                errorLogFilePath = Path.Combine(Path.GetDirectoryName(gameScriptPath), LOG_DIRECTORY_NAME, $"errlog.utf");
                warningFilePath  = Path.Combine(Path.GetDirectoryName(gameScriptPath), LOG_DIRECTORY_NAME, $"warnlog.utf");
                Utils.DeleteIfExists(errorLogFilePath);
                Utils.DeleteIfExists(warningFilePath);
            }

            string outputTemplate = ">>> [{Level:u3}] {Message:lj}{NewLine}{Exception}";

            logger        = new LoggerConfiguration().WriteTo.File(errorLogFilePath, outputTemplate: outputTemplate).CreateLogger();
            warningLogger = new LoggerConfiguration().WriteTo.File(warningFilePath, outputTemplate: outputTemplate).CreateLogger();

            errorCount = 0;
        }
示例#3
0
        /// <summary>
        /// Return line that put voice scripts from English line into Japanese line.
        /// </summary>
        /// <param name="englishLine">English line that includes voice scripts.</param>
        /// <param name="japaneseLine">Japanese line.</param>
        /// <returns>Line that put voice scripts from English line into Japanese line.</returns>
        private string GetInsertedVoiceScriptsFromEnglishIntoJapanese(List <string> allLines, int currentLineIndex, string englishLine, string japaneseLine, VoicesDatabase voicesDatabase)
        {
            string insertedJapaneseLine = string.Empty;

            // Get voice scripts with regix.
            List <string> voiceScripts = GetVoiceScripts(englishLine);

            if (voiceScripts.Count > 0)
            {
                string[] splitEnglishLine  = englishLine.Split('@');
                string[] splitJapaneseLine = japaneseLine.Split('@');

                // If English line and Japanese one's structure is not same, just return not changing Japanese line.
                if ((splitEnglishLine.Length != splitJapaneseLine.Length))
                {
                    List <string> customSplit = SplitJapaneseLineOnInsertionPoints(japaneseLine);

                    //note:returned dwaves are just 'dwave 0, thing' not 'dwave_jp 0, thing'
                    List <string> fixedDwaves = new List <string>();
                    DwaveDatabase.AutoFixResult fixResult;
                    try
                    {
                        fixResult = voicesDatabase.DwaveDatabase.FixMissingDwaves(voiceScripts, customSplit.Count - 1, out fixedDwaves);
                    }
                    catch (DwaveArgument.LastCharacterOfDwaveNotDigitException e)
                    {
                        logger.Error("An error occured while trying to fix the below:\n" + e.ToString());
                        fixResult = DwaveDatabase.AutoFixResult.Failure;
                    }
                    catch (DwaveDatabase.PrefixOfDwaveArgNotTheSame e)
                    {
                        logger.Error("An error occured while trying to fix the below:\n" + e.ToString());
                        fixResult = DwaveDatabase.AutoFixResult.Failure;
                    }

                    switch (fixResult)
                    {
                    //if fix was successful, return the new japanese line
                    case DwaveDatabase.AutoFixResult.OK:     //don't count error, but log
                        StringBuilder sb = new StringBuilder();
                        int           i  = 0;
                        for (; i < fixedDwaves.Count; i++)
                        {
                            sb.Append(customSplit[i]);
                            sb.Append(fixedDwaves[i]);
                        }
                        sb.Append(customSplit[i]);

                        string fixedJapaneseLine = sb.ToString();

                        HandleErrorUnmatchedCountOfLangjpAndLangenAtSign(allLines, currentLineIndex, englishLine, japaneseLine, splitEnglishLine, splitJapaneseLine, fixedJapaneseLine);
                        Console.WriteLine($"Auto-fixed line: ");
                        Console.WriteLine($"   (EN): {englishLine}");
                        Console.WriteLine($"   (JP): {japaneseLine}");
                        Console.WriteLine($"(JPFIX): {fixedJapaneseLine}\n");
                        return(fixedJapaneseLine);

                    //if fix was unsuccessful, return the original japanese line
                    case DwaveDatabase.AutoFixResult.NeedsManualCheck: //don't apply fix, print, count as error, and log (return original japanese line)
                    case DwaveDatabase.AutoFixResult.Failure:          //don't apply fix, count as error, and log (return original japanese line)
                        HandleErrorUnmatchedCountOfLangjpAndLangenAtSign(allLines, currentLineIndex, englishLine, japaneseLine, splitEnglishLine, splitJapaneseLine, null);
                        return(japaneseLine);
                    }
                }

                // If a split english string has voice script, append voice script to a split japanese string.
                int countOfVoiceScript = 0;
                for (int englishLineIndex = 0; englishLineIndex < splitEnglishLine.Length; englishLineIndex++)
                {
                    if (englishLineIndex > 0 && !string.IsNullOrEmpty(splitJapaneseLine[englishLineIndex]))
                    {
                        insertedJapaneseLine += "@";
                    }
                    if (splitEnglishLine[englishLineIndex].Contains(BEGINNING_OF_VOICE_SCRIPT))
                    {
                        if (splitJapaneseLine[englishLineIndex].StartsWith(JAPANESE_LINE_IDENTIFIER))
                        {
                            insertedJapaneseLine = splitJapaneseLine[englishLineIndex].Replace(JAPANESE_LINE_IDENTIFIER, $"{JAPANESE_LINE_IDENTIFIER}{voiceScripts[countOfVoiceScript]}");
                            countOfVoiceScript++;
                        }
                        else
                        {
                            insertedJapaneseLine += $"{voiceScripts[countOfVoiceScript]}{splitJapaneseLine[englishLineIndex]}";
                            countOfVoiceScript++;
                        }
                    }
                    else
                    {
                        insertedJapaneseLine += splitJapaneseLine[englishLineIndex];
                    }
                }

                // If count of voice scripts and count of used it don't match, log about it.
                if (countOfVoiceScript != voiceScripts.Count)
                {
                    // TODO Have to log about count of voice scripts and count of used it don't match, log about it.
                }

                // If japanese line has at sign in the end of line, add at sign because of split line with at sign.
                Regex hasAtSignInEndOfLineRegex = new Regex(@"[\w\W]*@$");
                if (hasAtSignInEndOfLineRegex.IsMatch(japaneseLine))
                {
                    insertedJapaneseLine += "@";
                }
            }

            if (string.IsNullOrEmpty(insertedJapaneseLine))
            {
                return(japaneseLine);
            }
            else
            {
                return(insertedJapaneseLine);
            }
        }
示例#4
0
        /// <summary>
        /// Put voice scripts into lines that includes langen or lanjp while changing properly voice script's function name.
        /// </summary>
        /// <param name="allOfLines">Lines that is used by the game.</param>
        /// <returns>Lines that put voice scripts into langjp and changed properly voice script's function name of each language.</returns>
        public List <string> PutVoiceScriptsIntoLines(List <string> allOfLines, VoicesDatabase voicesDatabase)
        {
            List <string> newAllOfLines = new List <string>();

            // Make new all of lines from original all of lines while putting voice scripts into Japanese line and changing to voice script's function name of English and Japan.
            List <TypeOfLanguage> orderOfAddedTypeOfLanguage = new List <TypeOfLanguage>();
            List <string>         tempJapaneseLines          = new List <string>();
            List <string>         tempEnglishLines           = new List <string>();
            List <string>         tempOtherStatementLines    = new List <string>();
            int lineIndex = -1; //need to count lineIndex this way because sometimes the for loop is continue'd

            foreach (string currentLine in allOfLines)
            {
                lineIndex++;
                // In the first place, search Japanese line.
                // Then if a Japanese line is found, retain the Japanese line until disappearing it.
                // retain also the English line like a way of retained Japanese lines.
                // If there are lines that exist between Japanese lines and English ones, retain lines as other statement, then it would add between Japanese and English ones.
                // If counts of both lines are not mutch, don't put voice scripts into Japanese line and just add Japanese lines to new all of lines and add English line to it after changing to voice script's function name of English.
                // If it is not able to search Japanese lines and it found English lines, add English line after changing to voice script's function name of English.
                // fix matching some lines which are entirely comments.
                if (!COMMENT_OR_BLANK_LINE.IsMatch(currentLine) && currentLine.Contains(ENGLISH_LINE_IDENTIFIER))
                {
                    if (tempJapaneseLines.Count <= 0)
                    {
                        newAllOfLines.Add(ChangeToVoiceScriptFunctionNameOfEnglish(currentLine));

                        HandleErrorLangenWithoutLangjp(allOfLines, lineIndex);
                        continue;
                    }
                    else
                    {
                        tempEnglishLines.Add(currentLine);
                        orderOfAddedTypeOfLanguage.Add(TypeOfLanguage.ENGLISH);
                        continue;
                    }
                }
                else if (tempJapaneseLines.Count > 0)
                {
                    bool shouldClearRetainedLines = false;
                    if (tempEnglishLines.Count <= 0)
                    {
                        if (!currentLine.Contains(JAPANESE_LINE_IDENTIFIER))
                        {
                            tempOtherStatementLines.Add(currentLine);
                            orderOfAddedTypeOfLanguage.Add(TypeOfLanguage.OTHER_STATEMENTS);
                            continue;
                        }
                    }
                    else if (tempJapaneseLines.Count == tempEnglishLines.Count)
                    {
                        // Put voice scripts into Japanese line and change to voice script's function name of English and Japan.
                        List <string> convertedVoiceScriptsToJapanese = new List <string>();
                        List <string> convertedVoiceScriptsToEnglish  = new List <string>();
                        for (int japaneseLinesIndex = 0; japaneseLinesIndex < tempJapaneseLines.Count; japaneseLinesIndex++)
                        {
                            string insertedVoiceScriptsJapaneseLine = GetInsertedVoiceScriptsFromEnglishIntoJapanese(allOfLines, lineIndex, tempEnglishLines[japaneseLinesIndex], tempJapaneseLines[japaneseLinesIndex], voicesDatabase);
                            convertedVoiceScriptsToJapanese.Add(ChangeToVoiceScriptFunctionNameOfJapan(insertedVoiceScriptsJapaneseLine));
                            convertedVoiceScriptsToEnglish.Add(ChangeToVoiceScriptFunctionNameOfEnglish(tempEnglishLines[japaneseLinesIndex]));
                        }
                        List <string> orderedLines = GetOrderedLines(orderOfAddedTypeOfLanguage, convertedVoiceScriptsToEnglish, convertedVoiceScriptsToJapanese, tempOtherStatementLines, false);
                        newAllOfLines.AddRange(orderedLines);
                        shouldClearRetainedLines = true;
                    }
                    else if (COMMENT_OR_BLANK_LINE.IsMatch(currentLine)) //comment or whitespace line - don't end current section
                    {
                        tempOtherStatementLines.Add(currentLine);
                        orderOfAddedTypeOfLanguage.Add(TypeOfLanguage.OTHER_STATEMENTS);
                        continue;
                    }
                    else
                    {
                        List <string> orderedLines = GetOrderedLines(orderOfAddedTypeOfLanguage, tempEnglishLines, tempJapaneseLines, tempOtherStatementLines);
                        newAllOfLines.AddRange(orderedLines);
                        shouldClearRetainedLines = true;

                        HandleErrorUnmatchedCountOfLangjpAndLangen(allOfLines, lineIndex, tempEnglishLines, tempJapaneseLines);
                    }

                    // If each line are added, clear them.
                    if (shouldClearRetainedLines)
                    {
                        orderOfAddedTypeOfLanguage.Clear();
                        tempJapaneseLines.Clear();
                        tempEnglishLines.Clear();
                        tempOtherStatementLines.Clear();
                    }
                }

                // Japanese line is added here because chunk of Japanese and English line should be added one by one.
                if (!COMMENT_OR_BLANK_LINE.IsMatch(currentLine) && currentLine.Contains(JAPANESE_LINE_IDENTIFIER))
                {
                    tempJapaneseLines.Add(currentLine);
                    orderOfAddedTypeOfLanguage.Add(TypeOfLanguage.JAPANESE);
                    continue;
                }

                // Put line that is not English line and Japanese line.
                newAllOfLines.Add(currentLine);
            }

            // If counts of new all lines and original ones don't match, notice error.
            if (newAllOfLines.Count != allOfLines.Count)
            {
                throw new UnmatchedNewLinesWithOriginalLinesException("Unmatch changed count of new all of lines and count of original ones.");
            }
            logger.Information($"Number of Errors: {errorCount}");

            return(newAllOfLines);
        }