diff --git a/scripts/systems/DescriptionParser.cs b/scripts/systems/DescriptionParser.cs index fbe3434..32a4885 100644 --- a/scripts/systems/DescriptionParser.cs +++ b/scripts/systems/DescriptionParser.cs @@ -16,6 +16,7 @@ public static class DescriptionParser var unparsedDescription = TranslationServer.Translate(resource.DescriptionKey); var keys = GetRequestedKeys(unparsedDescription); FillPlaceholders(keys, resource, searchScene); + ApplyModifiers(keys); descriptionText = ReplaceTextUsingDict(keys, unparsedDescription); resource.parsedDescription = descriptionText; @@ -41,14 +42,16 @@ public static class DescriptionParser if (text[i] == '}') { if (start == -1) continue; - result.Add(text.Substr(start + 1, i - start - 1), 0); + var substr = text.Substr(start + 1, i - start - 1); + if (result.ContainsKey(substr) == false) + result.Add(substr, 0); start = -1; } } return result; } - private static void FillPlaceholders(Dictionary placeholderDictionary, EntityResource resource, Node searchScene) + public static void FillPlaceholders(Dictionary placeholderDictionary, EntityResource resource, Node searchScene) { var searchList = new List() { resource, searchScene }; while (searchList.Count > 0) @@ -104,14 +107,15 @@ public static class DescriptionParser } - - // Apply any modifiers - foreach (var key in placeholderDictionary.Keys) + } + public static void ApplyModifiers(Dictionary toDictionary) + { + foreach (var key in toDictionary.Keys) { if (key.Split('|').Length < 2) continue; string[] modifiers = key.Split('|')[1..]; - float value = placeholderDictionary[key]; + float value = toDictionary[key]; for (int i = 0; i < modifiers.Length; i++) { @@ -123,45 +127,65 @@ public static class DescriptionParser value *= 100; break; case '*': - if (placeholderDictionary.ContainsKey(modifiers[i][1..])) - { - value *= placeholderDictionary[modifiers[i][1..]]; - } - else if (float.TryParse(modifiers[i][1..], out float mult)) - { - value *= mult; - } + value *= GetNumberOrVar(1.0f); break; case '/': - if (placeholderDictionary.ContainsKey(modifiers[i][1..])) - { - value /= placeholderDictionary[modifiers[i][1..]]; - } - else if (float.TryParse(modifiers[i][1..], out float div)) - { - value /= div; - } + value /= GetNumberOrVar(1.0f); break; case '+': - if (float.TryParse(modifiers[i][1..], out float add)) - { - value += add; - } + value += GetNumberOrVar(0.0f); break; case '-': - if(float.TryParse(modifiers[i][1..], out float sub)) - { - value -= sub; - } + value -= GetNumberOrVar(0.0f); break; } } + float GetNumberOrVar(float defaultVal) + { + var contained = ContainsVariable(toDictionary, modifiers[i][1..]); + if (contained != null) + { + return toDictionary[contained]; + } + else if (float.TryParse(modifiers[i][1..], out float mult)) + { + return mult; + } + return defaultVal; + } } - placeholderDictionary[key] = value; + toDictionary[key] = value; } + } - private static string ReplaceTextUsingDict(Dictionary dictionary, string text) + public static string ContainsVariable(Dictionary dictionary, string variableName, bool ignoreParent = false) + { + foreach (var key in dictionary.Keys) + { + var keyAsVar = key.Split('|')[0]; + if (ignoreParent) + { + if (keyAsVar.Split('.').Length == 2) + { + if (keyAsVar.Split('.')[1] == variableName) return key; + } + else if (keyAsVar == variableName) + { + return key; + } + } + else + { + if (keyAsVar == variableName) + { + return key; + } + } + } + return null; + } + public static string ReplaceTextUsingDict(Dictionary dictionary, string text) { var resStr = text; foreach (var key in dictionary.Keys) @@ -170,4 +194,5 @@ public static class DescriptionParser } return resStr; } + } diff --git a/translations/plants.csv b/translations/plants.csv index 2a3e89b..8d50652 100644 --- a/translations/plants.csv +++ b/translations/plants.csv @@ -41,7 +41,7 @@ spikeweed,Spikeweed,Колючка spikeweed_desc,"Health points: [color=DARK_RED]{MaxHP}[/color]. Reload time: [color=DARK_RED]{ReloadTime} seconds[/color]. Damage per second: [color=DARK_RED]{_damage|*invokationsPerSecond}[/color]. -[color=transparent]{invokationsPerSecond}[/color].","Очки здоровья: [color=DARK_RED]{MaxHP}[/color]. +[color=transparent]{invokationsPerSecond}[/color]","Очки здоровья: [color=DARK_RED]{MaxHP}[/color]. Время перезарядки: [color=DARK_RED]{ReloadTime} секунд[/color]. Урон в секунду: [color=DARK_RED]{_damage|*invokationsPerSecond}[/color]. [color=transparent]{invokationsPerSecond}[/color]." @@ -56,10 +56,10 @@ Sun production time: [color=DARK_RED]{Timer.wait_time} seconds[/color](After fir threepeater,Threepeater,Тристрел threepeater_desc,"Health points: [color=DARK_RED]{MaxHP}[/color]. Reload time: [color=DARK_RED]{ReloadTime} seconds[/color]. -Pea damage: [color=DARK_RED]{_damage}[/color]. +Pea damage: [color=DARK_RED]{_damage}[/color] ([color=darkred]{_damage|*3}[/color] in close proximity). Firerate: [color=DARK_RED]{FireTimer.wait_time} seconds[/color].","Очки здоровья: [color=DARK_RED]{MaxHP}[/color]. Время перезарядки: [color=DARK_RED]{ReloadTime} секунд[/color]. -Урон от гороха: [color=DARK_RED]{_damage}[/color]. +Урон от гороха: [color=DARK_RED]{_damage}[/color] ([color=darkred]{_damage|*3}[/color] вблизи). Задержка стрельбы: [color=DARK_RED]{FireTimer.wait_time} секунд[/color]." wallnut,Wallnut,Стенорех wallnut_desc,"Health points: [color=DARK_RED]{MaxHP}[/color] diff --git a/translations/plants.en.translation b/translations/plants.en.translation index 3787638..7d65083 100644 Binary files a/translations/plants.en.translation and b/translations/plants.en.translation differ diff --git a/translations/plants.ru.translation b/translations/plants.ru.translation index d7124e6..436e21c 100644 Binary files a/translations/plants.ru.translation and b/translations/plants.ru.translation differ