Exemplo n.º 1
0
        public static bool CheckLookup(StringKey input)
        {
            string output = input.fullKey;
            // While there are more lookups

            string regexKey = "{(ffg|val|qst):";

            if (!Regex.Match(output, regexKey).Success)
            {
                return(false);
            }

            int pos = Regex.Match(output, regexKey).Index;
            // Can be nested
            int bracketLevel = 1;
            // Start of lookup
            // ffg val and qst has the same length
            int lookupStart = pos + "{ffg:".Length;

            // Loop to find end of lookup
            int lookupEnd = lookupStart;

            while (bracketLevel > 0)
            {
                lookupEnd++;
                if (output[lookupEnd].Equals('{'))
                {
                    bracketLevel++;
                }
                if (output[lookupEnd].Equals('}'))
                {
                    bracketLevel--;
                }
            }

            // Extract lookup key
            string lookup = output.Substring(lookupStart, lookupEnd - lookupStart);

            // dict
            string dict = output.Substring(pos + 1, 3);

            // Get key result
            return(CheckDictQuery(dict, lookup));
        }
Exemplo n.º 2
0
        // Check for FFG text lookups and insert required text
        /// <summary>
        /// Replaces a FFG key with his current text
        /// </summary>
        /// <param name="input">{ffg:XXXX} like input</param>
        /// <returns>Translation to current language</returns>
        public static string FFGLookup(StringKey input)
        {
            string output = input.key;

            // While there are more lookups
            while (output.IndexOf("{ffg:") != -1)
            {
                // Can be nested
                int bracketLevel = 1;
                // Start of lookup
                int lookupStart = output.IndexOf("{ffg:") + "{ffg:".Length;

                // Loop to find end of lookup
                int lookupEnd = lookupStart;
                while (bracketLevel > 0)
                {
                    lookupEnd++;
                    if (output[lookupEnd].Equals('{'))
                    {
                        bracketLevel++;
                    }
                    if (output[lookupEnd].Equals('}'))
                    {
                        bracketLevel--;
                    }
                }

                // Extract lookup key
                string lookup = output.Substring(lookupStart, lookupEnd - lookupStart);
                // Get key result
                string result = FFGQuery(lookup);
                // We (unity) don't support underlines
                // Unity uses <> not []
                result = result.Replace("[u]", "<b>").Replace("[/u]", "</b>");
                result = result.Replace("[i]", "<i>").Replace("[/i]", "</i>");
                result = result.Replace("[b]", "<b>").Replace("[/b]", "</b>");
                // Replace the lookup
                output = output.Replace("{ffg:" + lookup + "}", result);
            }
            return(output);
        }
Exemplo n.º 3
0
        public static QuestButtonData FromSingleString(StringKey labelKey, string eventDataString)
        {
            if (string.IsNullOrWhiteSpace(eventDataString))
            {
                return(new QuestButtonData(labelKey));
            }

            // Extract event names
            var strings = eventDataString.Split(EVENT_PARAMETER_SEPARATOR);

            if (strings.Length <= 0)
            {
                return(new QuestButtonData(labelKey));
            }

            var questNames = strings[0].Split(EVENT_NAME_SEPARATOR, StringSplitOptions.RemoveEmptyEntries);

            // Backward compatibility with unreleased 2.4.11a

            // Skip conditional event parameters if not all parameters are present
            if (strings.Length < 4)
            {
                return(new QuestButtonData(labelKey, questNames.ToList()));
            }

            var          conditionString = string.Join(",", strings[1], strings[2], strings[3]);
            VarOperation condition       = new VarOperation(conditionString);
            var          varTests        = new VarTests();

            varTests.Add(condition);

            // Optional ButtonAction parameter (defaults to DISABLE, but can be HIDE or NONE as well)
            if (strings.Length > 4 && Enum.TryParse(strings[4], true, out QuestButtonAction action))
            {
                return(new QuestButtonData(labelKey, questNames.ToList(), varTests, action));
            }

            return(new QuestButtonData(labelKey, questNames.ToList(), varTests));
        }
Exemplo n.º 4
0
        // Check for FFG text lookups and insert required text
        /// <summary>
        /// Replaces a FFG key with his current text
        /// </summary>
        /// <param name="input">{ffg:XXXX} like input</param>
        /// <returns>Translation to current language</returns>
        public static string DictLookup(StringKey input)
        {
            string output = input.fullKey;
            // While there are more lookups

            // Count the number of replaces. One lookup should not replace more than RECURSIVE_LIMIT elements.
            int recursiveCount = 0;

            //while (output.IndexOf("{ffg:") != -1)
            while (Regex.Match(output, LookupRegexKey()).Success&& recursiveCount < RECURSIVE_LIMIT)
            {
                int pos = Regex.Match(output, LookupRegexKey()).Index;
                // Can be nested
                int bracketLevel = 1;
                // Start of lookup
                // ffg val and qst has the same length
                int lookupStart = pos + "{ffg:".Length;

                // Loop to find end of lookup
                int lookupEnd = lookupStart;
                while (bracketLevel > 0)
                {
                    lookupEnd++;
                    if (output[lookupEnd].Equals('{'))
                    {
                        bracketLevel++;
                    }
                    if (output[lookupEnd].Equals('}'))
                    {
                        bracketLevel--;
                    }
                }

                // Extract lookup key
                string lookup = output.Substring(lookupStart, lookupEnd - lookupStart);

                // dict
                string dict = output.Substring(pos + 1, 3);

                // Get key result
                string result = DictQuery(dict, lookup);

                // We (unity) don't support underlines
                // Unity uses <> not []
                result = result.Replace("[u]", "<b>").Replace("[/u]", "</b>");
                result = result.Replace("[i]", "<i>").Replace("[/i]", "</i>");
                result = result.Replace("[b]", "<b>").Replace("[/b]", "</b>");

                // Some FFG text doesn't close b/i like it should
                while (Regex.Matches(result, "<b>").Count > Regex.Matches(result, "</b>").Count)
                {
                    result += "</b>";
                }
                while (Regex.Matches(result, "<i>").Count > Regex.Matches(result, "</i>").Count)
                {
                    result += "</i>";
                }

                // Replace the lookup
                output = output.Replace("{" + dict + ":" + lookup + "}", result);
                // Increase the recursive count
                recursiveCount++;
            }

            if (recursiveCount == RECURSIVE_LIMIT)
            {
                ValkyrieDebug.Log("ERROR Recursive loop limit reached translating " + input.fullKey + ". Dictionary entry must be fixed.");
            }

            return(output);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor from a dict, key and one parameter
 /// </summary>
 /// <param name="newDict">dict to lookup</param>
 /// <param name="newKey">key to translate</param>
 /// <param name="numberZeroParam">first param for {0} replace</param>
 public StringKey(string newDict, string newKey, StringKey numberZeroKeyParam)
     : this(newDict, newKey, numberZeroKeyParam.fullKey)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Constructor from a dict, key and one parameter
 /// </summary>
 /// <param name="newKey">key to translate</param>
 /// <param name="param1">first param</param>
 /// <param name="param2">second param</param>
 public StringKey(StringKey templateStringKey, string param1, string param2)
 {
     dict       = templateStringKey.dict;
     key        = templateStringKey.key;
     parameters = param1 + ":" + param2;
 }
Exemplo n.º 7
0
 public static void RegisterKeyInGroup(StringKey translationKey, string groupId)
 {
     selectDictionary(translationKey.dict)?.SetKeyToGroup(translationKey.key, groupId);
 }