fuzzy variable is now avaiable
This commit is contained in:
parent
032f633597
commit
805226d9eb
4 changed files with 60 additions and 35 deletions
|
|
@ -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<string, float> placeholderDictionary, EntityResource resource, Node searchScene)
|
||||
public static void FillPlaceholders(Dictionary<string, float> placeholderDictionary, EntityResource resource, Node searchScene)
|
||||
{
|
||||
var searchList = new List<GodotObject>() { 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<string, float> 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<string, float> dictionary, string text)
|
||||
public static string ContainsVariable(Dictionary<string, float> 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<string, float> dictionary, string text)
|
||||
{
|
||||
var resStr = text;
|
||||
foreach (var key in dictionary.Keys)
|
||||
|
|
@ -170,4 +194,5 @@ public static class DescriptionParser
|
|||
}
|
||||
return resStr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue