From 805226d9eb48cbf83e7795da60fea4462ba5e534 Mon Sep 17 00:00:00 2001 From: Rendo Date: Sat, 26 Jul 2025 06:02:06 +0500 Subject: [PATCH] fuzzy variable is now avaiable --- scripts/systems/DescriptionParser.cs | 89 +++++++++++++++++---------- translations/plants.csv | 6 +- translations/plants.en.translation | Bin 3306 -> 3354 bytes translations/plants.ru.translation | Bin 4677 -> 4725 bytes 4 files changed, 60 insertions(+), 35 deletions(-) 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 3787638d34a87bbf8446ac973c3231e4db35b022..7d650835e246935a9b891b74dc09b1e09cfea4dc 100644 GIT binary patch delta 241 zcmaDQIZJB8Jw~Sgtdk!w`U$eKGBEsNU|>*WWMJr-)A+e*vOQC{BqtkC2q+=~#6Seb zJly5We@|Y|WX~kPKKTQa8e`IAab|TvPId+cAY$ME;t*v^p0dgQ%+dzefxMScjUWTK z*)`5&1C{UqISxP!GG88u%Q+bs9CPwhCof>rpS+gEZ1aESJ{IQxjIo<1ax7ppV))Of z5nU>#_0Lwq|6jJE#DAvP>Uas3wLkx})My#kMjr*q#rnNti?1#I^+-SXpXO#mt~E?N NAP0f04GIo&1^_d|J7oX> delta 196 zcmbOw^-6NXJw_%5w#g3|{RG)q85n*sFfb@GGBEVaY5W{G*`6s}l8cRj;T%x(HV^|P zz?g@-eEFZr>zVAC?z2t)z@)}#I9Z%oUGN4_DLYUJ2M~uSTk^P0_GgwhxB=w7f@%aA zz|F34#tNu}2gq>%VxT4lc_4POMnFB7BJWIv{8)?`KohUCfXnEV;%PyWZG&UkOK8ne1k9~T3IAOi%4C|mLv za8HhB)>C-R!@zJ8r~!o8fYS0ne1wmI;lhLqyD#j!*gIK(U3v2b=JTA!3L4SL`8oMT zwke54*+r=-vDNV@iMfgCsWn>0wbA-uxmbk@n=Whw>fCW*`-L5vo9FXRXW?N78VNL= JAt*S=82~n>HD&++ delta 129 zcmeyWa#Ur5FB7BqWIv{8Rs%)`27}4#nEV-YCjVnnXIwp5jagkNnu~!!kO6{2lr4Gw za!rnB)>GKQ!@zJ8r~!o8fYS0nJduxq;lhLqyD#j!*gIK(U3v2b=JTAB2V$TmhM?deX8;Re9)SP=