Skip to content

Commit

Permalink
Clean up of DisplayName stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrossignol committed Oct 27, 2020
1 parent d208928 commit eb2906a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Contract Configurator 1.30.6
Contract Configurator 1.31.0
- Add FirstName and LastName methods to Kerbal.
- Kerbals and Celestial Bodies used as strings now include the correct Lingoona gender suffixes.
- Allow PNG/DSS to be auto-detected correctly in dialog boxes.

Contract Configurator 1.30.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public static void RegisterMethods()
cb.BiomeMap.Attributes.Select(att => new Biome(cb, att.name)).ToList() : new List<Biome>()));

RegisterMethod(new Method<CelestialBody, string>("Name", cb => cb?.name));
RegisterMethod(new Method<CelestialBody, string>("DisplayName", cb => cb?.displayName));

RegisterMethod(new Method<CelestialBody, double>("Multiplier", cb => cb != null ? GameVariables.Instance.GetContractDestinationWeight(cb) : 1.0));

Expand Down Expand Up @@ -113,7 +112,7 @@ public override U ConvertType<U>(CelestialBody value)
{
if (typeof(U) == typeof(string))
{
return (U)(object)value.CleanDisplayName();
return (U)(object)value.displayName;
}
return base.ConvertType<U>(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static void RegisterMethods()
RegisterMethod(new Method<Kerbal, ProtoCrewMember.RosterStatus>("RosterStatus", k => k == null ? ProtoCrewMember.RosterStatus.Dead : k.rosterStatus));
RegisterMethod(new Method<Kerbal, ProtoCrewMember.KerbalType>("Type", k => k == null ? ProtoCrewMember.KerbalType.Applicant : k.kerbalType));
RegisterMethod(new Method<Kerbal, ProtoCrewMember.Gender>("Gender", k => k == null ? ProtoCrewMember.Gender.Male : k.gender));
RegisterMethod(new Method<Kerbal, string>("DisplayName", k => k?.DisplayName()));
RegisterMethod(new Method<Kerbal, string>("FirstName", k => k?.FirstName()));
RegisterMethod(new Method<Kerbal, string>("LastName", k => k?.LastName()));

RegisterGlobalFunction(new Function<List<Kerbal>>("AllKerbals", () => HighLogic.CurrentGame == null ? new List<Kerbal>() :
HighLogic.CurrentGame.CrewRoster.AllKerbals().Select<ProtoCrewMember, Kerbal>(pcm => new Kerbal(pcm)).ToList(), false));
Expand Down Expand Up @@ -81,7 +81,7 @@ public override U ConvertType<U>(Kerbal value)
{
if (typeof(U) == typeof(string))
{
return (U)(object)(value == null ? "" : value.ToString());
return (U)(object)(value == null ? "" : value.DisplayName());
}
return base.ConvertType<U>(value);
}
Expand Down
20 changes: 16 additions & 4 deletions source/ContractConfigurator/ExpressionParser/Wrappers/Kerbal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,25 @@ public override string ToString()
/// Gets the full name with the Lingoona gender extension, e.g. "Valentina Kerman^f"
/// </summary>
public string DisplayName()
=> this.name + this.GetLingoonaExtension();
{
return StringBuilderCache.Format("{0}{1}", name, GetLingoonaExtension());
}

/// <summary>
/// Gets the full name with the Lingoona gender extension, e.g. "Jebediah^m"
/// Gets the first name with the Lingoona gender extension, e.g. "Jebediah^m"
/// </summary>
public string FirstName()
=> this.name.Split(new char[] { ' ' }).First() + this.GetLingoonaExtension();
{
return StringBuilderCache.Format("{0}{1}", name.Substring(0, name.IndexOf(' ')), GetLingoonaExtension());
}

/// <summary>
/// Gets the last name with the Lingoona gender extension, e.g. "Kerman^m"
/// </summary>
public string LastName()
{
return StringBuilderCache.Format("{0}{1}", name.Substring(name.IndexOf(' ') + 1), GetLingoonaExtension());
}

/// <summary>
/// Gets the Lingoona extension for the gender of the Kerbal. Ideally, we'd let
Expand Down Expand Up @@ -240,7 +252,7 @@ public static Kerbal Load(ConfigNode node)
return k;
}
}

public static void RemoveKerbal(Kerbal kerbal)
{
if (kerbal.pcm != null)
Expand Down
13 changes: 13 additions & 0 deletions test/Expression.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ CONTRACT_TYPE
nospace = "RandomKerbalName(Male) and RandomKerbalName(Female) something something (spoilers)"
space = " RandomKerbalName(Male) and RandomKerbalName(Female) something something (spoilers)"
qtest = "quoted " + "test"

firstName = @/k1.FirstName()
lastName = @/k2.LastName()
fullName = @/k2
fullName2 = "The Kerbal is @/k2"
}

DATA
{
type = Kerbal

k1 = Valentina Kerman
k2 = NewKerbal()
}

DATA
Expand Down

0 comments on commit eb2906a

Please sign in to comment.