Replace a bunch of string concatenations with stringbuilders

This commit is contained in:
lutepickle 2022-09-09 21:55:56 -07:00
parent 003f5d6d29
commit b2da75d9e6
7 changed files with 49 additions and 37 deletions

Binary file not shown.

View File

@ -1,6 +1,7 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Verse;
@ -264,13 +265,14 @@ namespace RJW_Menstruation
public string GetIngredients()
{
string res = "";
StringBuilder res = new StringBuilder();
if (!cums.NullOrEmpty()) for (int i = 0; i < cums.Count; i++)
{
res += cums[i];
if (i < cums.Count - 1) res += ", ";
res.Append(cums[i]);
if (i < cums.Count - 1) res.Append(", ");
}
return res;
return res.ToString();
}
}
}

View File

@ -4,6 +4,7 @@ using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
@ -423,19 +424,19 @@ namespace RJW_Menstruation
{
if (eggs.NullOrEmpty()) return "";
string res = "";
StringBuilder res = new StringBuilder();
int fertilized = eggs.Count(egg => egg.fertilized);
if (fertilized != 0) res += fertilized + " " + Translations.Dialog_WombInfo05;
if (fertilized != 0 && eggs.Count - fertilized != 0) res += ", ";
if (fertilized != 0) res.AppendFormat("{0} {1}", fertilized, Translations.Dialog_WombInfo05);
if (fertilized != 0 && eggs.Count - fertilized != 0) res.Append(", ");
if (cums.NullOrEmpty() || TotalFertCum == 0)
{
if (eggs.Count - fertilized != 0) res += eggs.Count - fertilized + " " + Translations.Dialog_WombInfo07;
if (eggs.Count - fertilized != 0) res.AppendFormat("{0} {1}", eggs.Count - fertilized, Translations.Dialog_WombInfo07);
}
else
{
if (eggs.Count - fertilized != 0) res += eggs.Count - fertilized + " " + Translations.Dialog_WombInfo06;
if (eggs.Count - fertilized != 0) res.AppendFormat("{0} {1}", eggs.Count - fertilized, Translations.Dialog_WombInfo06);
}
return res;
return res.ToString();
}
}
public bool IsEggFertilizing

View File

@ -2,6 +2,7 @@
using rjw;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
@ -78,19 +79,19 @@ namespace RJW_Menstruation
if (babies.NullOrEmpty())
return "Null";
string res = "";
StringBuilder res = new StringBuilder();
IEnumerable<Pawn> babiesdistinct = babies.Distinct(new RaceComparer());
int iteration = 0;
foreach (Pawn baby in babiesdistinct)
{
int num = babies.Where(x => x.def.Equals(baby.def)).Count();
if (iteration > 0) res += ", ";
res += num + " " + baby.def.label;
if (iteration > 0) res.Append(", ");
res.AppendFormat("{0} {1}", num, baby.def.label);
iteration++;
}
res += " " + Translations.Dialog_WombInfo02;
return res;
res.AppendFormat(" {0}", Translations.Dialog_WombInfo02);
return res.ToString();
}
public string GetFatherInfo()
@ -98,20 +99,21 @@ namespace RJW_Menstruation
if (babies.NullOrEmpty())
return "Null";
string res = Translations.Dialog_WombInfo03 + ": ";
StringBuilder res = new StringBuilder();
res.AppendFormat("{0}: ", Translations.Dialog_WombInfo03);
if (!is_parent_known && Configurations.InfoDetail != Configurations.DetailLevel.All)
return res + Translations.Dialog_FatherUnknown;
return res.Append(Translations.Dialog_FatherUnknown).ToString();
IEnumerable<Pawn> babiesdistinct = babies.Distinct(new FatherComparer(pawn));
int iteration = 0;
foreach (Pawn baby in babiesdistinct)
{
if (iteration > 0) res += ", ";
res += Utility.GetFather(baby, pawn)?.LabelShort ?? Translations.Dialog_FatherUnknown;
if (iteration > 0) res.Append(", ");
res.Append(Utility.GetFather(baby, pawn)?.LabelShort ?? Translations.Dialog_FatherUnknown);
iteration++;
}
return res;
return res.ToString();
}
private void HumanlikeBirth(Pawn baby)

View File

@ -2,6 +2,7 @@
using rjw;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
@ -42,15 +43,20 @@ namespace RJW_Menstruation
private static Gizmo CreateGizmo_WombStatus(Pawn pawn, HediffComp_Menstruation comp)
{
Texture2D icon, icon_overay;
string description = "";
if (Configurations.Debug) {
description += comp.curStage + ": " + comp.curStageHrs + "\n" +
(comp.Pregnancy is Hediff_MultiplePregnancy preg ? "due: " + preg.DueDate() + "\n" : "") +
"fertcums: " + comp.TotalFertCum + "\n" +
"ovarypower: " + comp.ovarypower + "\n" +
"eggs: " + comp.GetNumOfEggs + "\n";
StringBuilder description = new StringBuilder();
if (Configurations.Debug)
{
description
.AppendFormat("{0}: {1}\n", comp.curStage, comp.curStageHrs);
if (comp.Pregnancy is Hediff_MultiplePregnancy preg) description
.AppendFormat("due: {0}\n", preg.DueDate());
description
.AppendFormat("fertcums: {0}\n" +
"ovarypower: {1}\n" +
"eggs: {2}\n",
comp.TotalFertCum, comp.ovarypower, comp.GetNumOfEggs);
}
else description += comp.GetCurStageLabel + "\n";
else description.AppendFormat("{0}\n", comp.GetCurStageLabel);
if (pawn.IsRJWPregnant())
{
Hediff_BasePregnancy hediff = comp.Pregnancy;
@ -84,14 +90,14 @@ namespace RJW_Menstruation
icon_overay = comp.GetCumIcon();
}
foreach (string s in comp.GetCumsInfo) description += s + "\n";
foreach (string s in comp.GetCumsInfo) description.AppendFormat("{0}\n", s);
Color c = comp.GetCumMixtureColor;
return new Gizmo_Womb
{
defaultLabel = pawn.LabelShort,
defaultDesc = description,
defaultDesc = description.ToString(),
icon = icon,
icon_overay = icon_overay,
shrinkable = Configurations.AllowShrinkIcon,

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Verse;
@ -38,13 +39,13 @@ namespace RJW_Menstruation.Sexperience
public override string GetInspectString()
{
string res = "";
StringBuilder res = new StringBuilder();
if (!ingredients.NullOrEmpty()) for (int i = 0; i < ingredients.Count; i++)
{
res += ingredients[i];
if (i != ingredients.Count - 1) res += ", ";
res.Append(ingredients[i]);
if (i != ingredients.Count - 1) res.Append(", ");
}
return res;
return res.ToString();
}
public void InitwithCum(CumMixture cum)

View File

@ -1,7 +1,7 @@
Version 1.0.7.5
- Fix error when one womb's concealed estrus is overwritten by another womb's visible estrus.
- Properly calculate cramp pain falloff again.
- Climacteric and menopause are now per-womb. Their effect on overall sex drive and satisfaction will depend on the health of any other wombs.
- Climacteric and menopause are now per-womb, appearing in the womb dialog instead of as hediffs. Any old hediffs should disappear upon loading the save.
- Added new property to vaginas to multiply the number of eggs available. Archotech vaginas will have quadruple the normal amount.
Version 1.0.7.4