Skip to content

Commit

Permalink
text export of missing color ids of a species
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Jan 31, 2023
1 parent 9e13fa2 commit 6599d3e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ARKBreedingStats/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ARKBreedingStats/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3629,5 +3629,12 @@ private void colorDefinitionsToClipboardToolStripMenuItem_Click(object sender, E
// copy currently loaded color definitions to the clipboard
Clipboard.SetText(string.Join("\n", Values.V.Colors.ColorsList.Select(c => $"{c.Id,3}: {c}")));
}

private void copyColorInformationToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
{
var colorInfo = _creatureCollection.GetColorInfo(speciesSelector1.SelectedSpecies);
Clipboard.SetText(string.IsNullOrEmpty(colorInfo) ? $"no color info available for species {speciesSelector1.SelectedSpecies}" : colorInfo);
SetMessageLabelText($"Color information about {speciesSelector1.SelectedSpecies} has been copied to the clipboard, you can paste it in a text editor to view it.", MessageBoxIcon.Information);
}
}
}
95 changes: 95 additions & 0 deletions ARKBreedingStats/library/CreatureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using ARKBreedingStats.mods;

namespace ARKBreedingStats.Library
Expand Down Expand Up @@ -560,5 +561,99 @@ public enum ColorExisting
/// </summary>
ColorIsNew
}

/// <summary>
/// Returns information about what color ids exist in which regions of the creatures of a species.
/// </summary>
internal string GetColorInfo(Species species)
{
if (species == null) return null;

var colorsExistPerRegion = new HashSet<byte>[Ark.ColorRegionCount];
var colorsDontExistPerRegion = new HashSet<byte>[Ark.ColorRegionCount];
var allAvailableColorIds = Values.V.Colors.ColorsList.Select(c => c.Id).ToArray();
for (int i = 0; i < Ark.ColorRegionCount; i++)
{
colorsExistPerRegion[i] = new HashSet<byte>();
colorsDontExistPerRegion[i] = new HashSet<byte>(allAvailableColorIds);
}


foreach (var cr in creatures)
{
if (cr.speciesBlueprint != species.blueprintPath
|| cr.colors == null)
continue;

var ci = 0;
foreach (var co in cr.colors)
{
if (colorsExistPerRegion[ci].Contains(co)) continue;
colorsExistPerRegion[ci].Add(co);
colorsDontExistPerRegion[ci].Remove(co);
ci++;
}
}

var sb = new StringBuilder($"Color information about {species.DescriptiveNameAndMod} ({species.blueprintPath})\n\n");
for (int i = 0; i < Ark.ColorRegionCount; i++)
{
if (!species.EnabledColorRegions[i]) continue;
sb.AppendLine($"Color region {i}: {species.colors[i].name}");
var colorsExist = colorsExistPerRegion[i].Count;
sb.AppendLine($"{colorsExist} color id{(colorsExist != 1 ? "s" : "")} available in your library:");
CreateNumberRanges(colorsExistPerRegion[i]);
sb.AppendLine();
var colorsDontExist = colorsDontExistPerRegion[i].Count;
sb.AppendLine($"{colorsDontExist} color id{(colorsDontExist != 1 ? "s" : "")} missing in your library:");
CreateNumberRanges(colorsDontExistPerRegion[i]);
sb.AppendLine();
sb.AppendLine();
}

void CreateNumberRanges(HashSet<byte> numbers)
{
var count = numbers.Count;
if (count == 0) return;
if (count == 1)
{
sb.Append(numbers.First());
return;
}

int lastNumber = -2;
bool currentlyInRange = false;
foreach (var number in numbers.OrderBy(c => c))
{
var lastNumberOfSet = --count == 0;
if (lastNumber + 1 == number)
{
if (lastNumberOfSet)
{
if (currentlyInRange)
sb.Append($"-{number}");
else sb.Append($", {number}");
}
currentlyInRange = true;
}
else if (currentlyInRange)
{
// was a number range that now ends
sb.Append($"-{lastNumber}, {number}");
currentlyInRange = false;
}
else
{
if (lastNumber == -2)
sb.Append($"{number}"); // first number of row
else
sb.Append($", {number}");
}
lastNumber = number;
}
}

return sb.ToString();
}
}
}

0 comments on commit 6599d3e

Please sign in to comment.