Skip to content

Commit

Permalink
simplified string.Join()
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Dec 28, 2023
1 parent 5542f8f commit bf8d233
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Binary file modified Assemblies/RimGPT.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/RecordKeeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static void AddHealthInformation(StringBuilder builder, ColonistData col
{
var lastElementIndex = hediffDescriptions.Count - 1;
hediffDescriptions[lastElementIndex] = "and " + hediffDescriptions[lastElementIndex];
hediffsText = string.Join(", ", hediffDescriptions);
hediffsText = hediffDescriptions.Join();
}

builder.Append($" {colonist.Name} has {hediffsText}.");
Expand Down
25 changes: 13 additions & 12 deletions Source/Tasks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RimWorld;
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -38,7 +39,7 @@ public static void Task(Map map)
{
lastTotal = total;
var colonistCount = map.mapPawns.FreeColonistsCount;
var amountList = string.Join(", ", amounts.Select(pair => $"{pair.Value} {pair.Key.label.CapitalizeFirst()}"));
var amountList = amounts.Select(pair => $"{pair.Value} {pair.Key.label.CapitalizeFirst()}").Join();
Personas.Add($"Minor update: total {colonistCount} colonist(s), {amountList}", 2);
}
}
Expand Down Expand Up @@ -79,7 +80,7 @@ public static void Task(Map map)
})
.Where(s => string.IsNullOrEmpty(s) == false);

var thoughtsMessage = $"{colonist.Name.ToStringShort}'s recent thoughts: {string.Join(", ", formattedThoughts)}";
var thoughtsMessage = $"{colonist.Name.ToStringShort}'s recent thoughts: {formattedThoughts.Join()}";
Personas.Add(thoughtsMessage, 2);
}
}
Expand Down Expand Up @@ -120,7 +121,7 @@ public static void Task(Map map)

if (opinionMessages.Any())
{
var consolidatedMessage = string.Join("\n", opinionMessages);
var consolidatedMessage = opinionMessages.Join(delimiter: "\n");
Personas.Add(consolidatedMessage, 2);
}
}
Expand Down Expand Up @@ -154,7 +155,7 @@ public static void Task(Map map)
if (allPowerGeneratingBuildings.Any() == false)
messages.Add("Power Generators: None");
else
messages.Add("Power Generators: " + string.Join(", ", powerGeneratorBuildings));
messages.Add("Power Generators: " + powerGeneratorBuildings.Join());

var totalPowerNeeds = CalculateTotalPowerNeeds(map, messages);

Expand All @@ -175,7 +176,7 @@ public static void Task(Map map)
messages.Add(totalPowerNeedsMessage);
if (totalPowerNeeds > 0 || totalPowerGenerated > 0)
// dont talk about power if there is no power
Personas.Add("Energy Analysis: " + powerStatus + "\n" + string.Join(", ", messages), priority);
Personas.Add("Energy Analysis: " + powerStatus + "\n" + messages.Join(), priority);
else
Logger.Message("Skip Power Generation evaluation.");
}
Expand Down Expand Up @@ -206,7 +207,7 @@ public static float CalculateTotalPowerNeeds(Map map, List<string> messages)
}

if (powerConsumptionMessages.Any())
messages.Add("Power Consumption: " + string.Join(", ", powerConsumptionMessages));
messages.Add("Power Consumption: " + powerConsumptionMessages.Join());

return totalPowerNeeds;
}
Expand Down Expand Up @@ -268,7 +269,7 @@ public static void Task(Map map)
}

if (roomsList.Count > 0)
Personas.Add("Notable Rooms in the Colony: " + string.Join("\n", roomsList), 1);
Personas.Add("Notable Rooms in the Colony: " + roomsList.Join(delimiter: "\n"), 1);
}
}

Expand All @@ -286,7 +287,7 @@ public static void Task(Map map)

// already researched projects
var completedResearch = DefDatabase<ResearchProjectDef>.AllDefsListForReading.Where(research => research.IsFinished);
var completedResearchNames = string.Join(", ", completedResearch.Select(r => r.label));
var completedResearchNames = completedResearch.Select(r => r.label).Join();
var completedMessage = $"Already Known: {completedResearchNames}";

// Now do current research
Expand All @@ -296,7 +297,7 @@ public static void Task(Map map)

// Now do available research that is not locked
var availableResearch = DefDatabase<ResearchProjectDef>.AllDefsListForReading.Where(research => !research.IsFinished && research.PrerequisitesCompleted);
var availableResearchNames = string.Join(", ", availableResearch.Select(r => r.label));
var availableResearchNames = availableResearch.Select(r => r.label).Join();
var availableMessage = $"Available Research: {availableResearchNames}";

Personas.Add($"Research Update: {completedMessage}\n{currentMessage}\n{availableMessage}", 1);
Expand Down Expand Up @@ -334,7 +335,7 @@ public static void Task(Map map)
var season = GenDate.Season((quadrumIndex * GenDate.DaysPerQuadrum + 5) * GenDate.TicksPerDay, tileLatLong);
quadrumsMonthsSeasons.Add($"{quadrum.Label()} is {season}");
}
var quadrumsMonthsSeasonsString = string.Join(", ", quadrumsMonthsSeasons);
var quadrumsMonthsSeasonsString = quadrumsMonthsSeasons.Join();

var message = $"Current Season: {seasonName}, Yearly Seasons Overview: {quadrumsMonthsSeasonsString}\n " +
$"Each Quadrum lasts 15 days, and there are 4 Quadrums per year\n" +
Expand Down Expand Up @@ -401,7 +402,7 @@ public static void Task(Map map)
}

RecordKeeper.CollectColonistData(colonists);
Log.Message(string.Join("\n\n", RecordKeeper.FetchColonistData()));
Log.Message(RecordKeeper.FetchColonistData().Join(delimiter: "\n\n"));
}
}
}

0 comments on commit bf8d233

Please sign in to comment.