Exemplo n.º 1
0
        private static void TranslateDisplayList(CharaList charaList)
        {
            if (charaList == null || TranslationHelper.Instance == null ||
                !TranslationHelper.Instance.CurrentCardLoadTranslationEnabled)
            {
                return;
            }

            var cfiList = Traverse.Create(charaList)?.Field <CharaFileSort>("charaFileSort")?.Value?.cfiList;

            if (cfiList == null)
            {
                return;
            }

            var sex = Traverse.Create(charaList)?.Field <int>("sex")?.Value ?? -1;

            if (sex == -1)
            {
                return;
            }

            void HandleResult(CharaFileInfo charaFileInfo, ITranslationResult result)
            {
                if (!result.Succeeded)
                {
                    return;
                }
                charaFileInfo.name = charaFileInfo.node.text = result.TranslatedText;
            }

            var scope = new NameScope((CharacterSex)sex);

            foreach (var entry in cfiList)
            {
                var origName = entry.name;
                if (TryApplyAlternateTranslation(entry, origName))
                {
                    TreeNodeLimiter.EndImmediately();
                    return;
                }

                void Handler(ITranslationResult result)
                {
                    HandleResult(entry, result);
                    if (TryApplyAlternateTranslation(entry, origName))
                    {
                        TreeNodeLimiter.EndImmediately();
                    }

                    TreeNodeLimiter.EndImmediately();
                }

                TranslationHelper.Instance.StartCoroutine(TreeNodeLimiter.Start().AppendCo(
                                                              TranslationHelper.CardNameManager.TranslateCardName(origName, scope,
                                                                                                                  CardNameTranslationManager.CanForceSplitNameString(origName), Handler)));
            }
        }
Exemplo n.º 2
0
        private static IEnumerator TranslateFileInfoCoroutine(Func <string> nameGetter, Func <CharacterSex> sexGetter,
                                                              Action <string> nameSetter, params TranslationResultHandler[] handlers)
        {
            var origName      = nameGetter();
            var innerHandlers = new List <TranslationResultHandler>
            {
                r =>
                {
                    FileInfoLimiter.EndImmediately();
                    if (!r.Succeeded)
                    {
                        return;
                    }
                    nameSetter(r.TranslatedText);
                },
                Handlers.AddNameToCache(origName)
            };

            if (handlers.Length > 0)
            {
                innerHandlers.AddRange(handlers);
            }
            yield return(FileInfoLimiter.Start().AppendCo(
                             TranslationHelper.CardNameManager.TranslateCardName(origName,
                                                                                 new NameScope(sexGetter()),
                                                                                 innerHandlers.ToArray())));
        }