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 unparsedDescription = TranslationServer.Translate(resource.DescriptionKey);
|
||||||
var keys = GetRequestedKeys(unparsedDescription);
|
var keys = GetRequestedKeys(unparsedDescription);
|
||||||
FillPlaceholders(keys, resource, searchScene);
|
FillPlaceholders(keys, resource, searchScene);
|
||||||
|
ApplyModifiers(keys);
|
||||||
descriptionText = ReplaceTextUsingDict(keys, unparsedDescription);
|
descriptionText = ReplaceTextUsingDict(keys, unparsedDescription);
|
||||||
|
|
||||||
resource.parsedDescription = descriptionText;
|
resource.parsedDescription = descriptionText;
|
||||||
|
|
@ -41,14 +42,16 @@ public static class DescriptionParser
|
||||||
if (text[i] == '}')
|
if (text[i] == '}')
|
||||||
{
|
{
|
||||||
if (start == -1) continue;
|
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;
|
start = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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 };
|
var searchList = new List<GodotObject>() { resource, searchScene };
|
||||||
while (searchList.Count > 0)
|
while (searchList.Count > 0)
|
||||||
|
|
@ -104,14 +107,15 @@ public static class DescriptionParser
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Apply any modifiers
|
public static void ApplyModifiers(Dictionary<string, float> toDictionary)
|
||||||
foreach (var key in placeholderDictionary.Keys)
|
{
|
||||||
|
foreach (var key in toDictionary.Keys)
|
||||||
{
|
{
|
||||||
if (key.Split('|').Length < 2) continue;
|
if (key.Split('|').Length < 2) continue;
|
||||||
string[] modifiers = key.Split('|')[1..];
|
string[] modifiers = key.Split('|')[1..];
|
||||||
|
|
||||||
float value = placeholderDictionary[key];
|
float value = toDictionary[key];
|
||||||
|
|
||||||
for (int i = 0; i < modifiers.Length; i++)
|
for (int i = 0; i < modifiers.Length; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -123,45 +127,65 @@ public static class DescriptionParser
|
||||||
value *= 100;
|
value *= 100;
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
if (placeholderDictionary.ContainsKey(modifiers[i][1..]))
|
value *= GetNumberOrVar(1.0f);
|
||||||
|
break;
|
||||||
|
case '/':
|
||||||
|
value /= GetNumberOrVar(1.0f);
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
value += GetNumberOrVar(0.0f);
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
value -= GetNumberOrVar(0.0f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float GetNumberOrVar(float defaultVal)
|
||||||
{
|
{
|
||||||
value *= placeholderDictionary[modifiers[i][1..]];
|
var contained = ContainsVariable(toDictionary, modifiers[i][1..]);
|
||||||
|
if (contained != null)
|
||||||
|
{
|
||||||
|
return toDictionary[contained];
|
||||||
}
|
}
|
||||||
else if (float.TryParse(modifiers[i][1..], out float mult))
|
else if (float.TryParse(modifiers[i][1..], out float mult))
|
||||||
{
|
{
|
||||||
value *= mult;
|
return mult;
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '+':
|
|
||||||
if (float.TryParse(modifiers[i][1..], out float add))
|
|
||||||
{
|
|
||||||
value += add;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '-':
|
|
||||||
if(float.TryParse(modifiers[i][1..], out float sub))
|
|
||||||
{
|
|
||||||
value -= sub;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return defaultVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
placeholderDictionary[key] = value;
|
toDictionary[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static string ReplaceTextUsingDict(Dictionary<string, float> dictionary, string text)
|
else
|
||||||
|
{
|
||||||
|
if (keyAsVar == variableName)
|
||||||
|
{
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static string ReplaceTextUsingDict(Dictionary<string, float> dictionary, string text)
|
||||||
{
|
{
|
||||||
var resStr = text;
|
var resStr = text;
|
||||||
foreach (var key in dictionary.Keys)
|
foreach (var key in dictionary.Keys)
|
||||||
|
|
@ -170,4 +194,5 @@ public static class DescriptionParser
|
||||||
}
|
}
|
||||||
return resStr;
|
return resStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ spikeweed,Spikeweed,Колючка
|
||||||
spikeweed_desc,"Health points: [color=DARK_RED]{MaxHP}[/color].
|
spikeweed_desc,"Health points: [color=DARK_RED]{MaxHP}[/color].
|
||||||
Reload time: [color=DARK_RED]{ReloadTime} seconds[/color].
|
Reload time: [color=DARK_RED]{ReloadTime} seconds[/color].
|
||||||
Damage per second: [color=DARK_RED]{_damage|*invokationsPerSecond}[/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]{ReloadTime} секунд[/color].
|
||||||
Урон в секунду: [color=DARK_RED]{_damage|*invokationsPerSecond}[/color].
|
Урон в секунду: [color=DARK_RED]{_damage|*invokationsPerSecond}[/color].
|
||||||
[color=transparent]{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,Threepeater,Тристрел
|
||||||
threepeater_desc,"Health points: [color=DARK_RED]{MaxHP}[/color].
|
threepeater_desc,"Health points: [color=DARK_RED]{MaxHP}[/color].
|
||||||
Reload time: [color=DARK_RED]{ReloadTime} seconds[/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].
|
Firerate: [color=DARK_RED]{FireTimer.wait_time} seconds[/color].","Очки здоровья: [color=DARK_RED]{MaxHP}[/color].
|
||||||
Время перезарядки: [color=DARK_RED]{ReloadTime} секунд[/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]."
|
Задержка стрельбы: [color=DARK_RED]{FireTimer.wait_time} секунд[/color]."
|
||||||
wallnut,Wallnut,Стенорех
|
wallnut,Wallnut,Стенорех
|
||||||
wallnut_desc,"Health points: [color=DARK_RED]{MaxHP}[/color]
|
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