Skip to content

Commit

Permalink
Fix a bug and add missing functionality relating to ExperienceTrait (#45
Browse files Browse the repository at this point in the history
)
  • Loading branch information
IO5 authored Jul 3, 2024
1 parent b433547 commit c9ba036
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public override bool EQ(ExperienceTrait a, ExperienceTrait b)
return true;
}

return a.TypeName == b.TypeName;
return a?.TypeName == b?.TypeName;
}

public override ExperienceTrait ParseIdentifier(Token token)
Expand All @@ -110,17 +110,13 @@ public override ExperienceTrait ParseIdentifier(Token token)
return null;
}

for (int index = 0; index < GameDatabase.Instance.ExperienceConfigs.Categories.Count; ++index)
var result = ConfigNodeUtil.ParseExperienceTrait(identifier);
if (result == null)
{
if (identifier == GameDatabase.Instance.ExperienceConfigs.Categories[index].Name)
{
Type type = KerbalRoster.GetExperienceTraitType(identifier) ?? typeof(ExperienceTrait);
return ExperienceTrait.Create(type, GameDatabase.Instance.ExperienceConfigs.Categories[index], null);
}
LoggingUtil.LogError(this, StringBuilderCache.Format("Unknown experience trait '{0}'.", identifier));
}

LoggingUtil.LogError(this, StringBuilderCache.Format("Unknown experience trait '{0}'.", identifier));
return null;
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ public static string OutputValue(object value, out Type type)
Biome b = (Biome)value;
strValue = b.body.name + ";" + b.biome;
}
else if (type == typeof(Experience.ExperienceTrait))
{
strValue = ((Experience.ExperienceTrait)(value)).TypeName;
}
else if (type.Name == "List`1")
{
strValue = "[ ";
Expand Down
18 changes: 18 additions & 0 deletions source/ContractConfigurator/Util/ConfigNodeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ public static T ParseSingleValue<T>(string key, string stringValue, bool allowEx
{
value = (T)(object)ParseLaunchSiteValue(stringValue);
}
else if (typeof(T) == typeof(Experience.ExperienceTrait))
{
value = (T)(object)ParseExperienceTrait(stringValue);
}
// Do newline conversions
else if (typeof(T) == typeof(string))
{
Expand Down Expand Up @@ -1073,6 +1077,20 @@ private static ProtoCrewMember ParseProtoCrewMemberValue(string name)
return null;
}

public static Experience.ExperienceTrait ParseExperienceTrait(string traitName)
{
for (int index = 0; index < GameDatabase.Instance.ExperienceConfigs.Categories.Count; ++index)
{
if (traitName == GameDatabase.Instance.ExperienceConfigs.Categories[index].Name)
{
Type type = KerbalRoster.GetExperienceTraitType(traitName) ?? typeof(Experience.ExperienceTrait);
return Experience.ExperienceTrait.Create(type, GameDatabase.Instance.ExperienceConfigs.Categories[index], null);
}
}

return null;
}

private static void AddFoundKey(ConfigNode configNode, string key)
{
// Initialize the list
Expand Down

0 comments on commit c9ba036

Please sign in to comment.