Skip to content

Commit

Permalink
Make color to fungus translation more robust against bad colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Αθηνα 𒂗𒃶𒌌𒀭𒈾 Washington committed Aug 4, 2021
1 parent a27b2a8 commit 6f5c91e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
30 changes: 28 additions & 2 deletions Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,37 @@ public static class Utility {
public static Dictionary<string, string> ColorRenders = new Dictionary<string, string> { { "gold", "&W" }, { "rose", "&R" }, { "azure", "&B" }, { "jade", "&G" } };
public static string GetFungalGasFromColor(string Color) {
Stat.ReseedFrom("PufferType");
return Algorithms.RandomShuffle(SporePuffer.InfectionList)[ColorIndices[Color.ToLower()]];
if (Color == null) {
MaybeLog("Null Color in GetFungalGasFromColor");
Color = "gold";
}
if (!ColorIndices.ContainsKey(Color.ToLower())) {
MaybeLog($"Unrecognized Color {Color} in GetFungalGasFromColor");
Color = "gold";
}
var index = ColorIndices[Color.ToLower()];
if (index < 0 || index > SporePuffer.InfectionObjectList.Count) {
MaybeLog($"Index {index} out of bounds in GetFungalGasFromColor (max is {SporePuffer.InfectionObjectList.Count})");
index = 0;
}
return Algorithms.RandomShuffle(SporePuffer.InfectionObjectList)[index];
}
public static string GetFungalInfectionFromColor(string Color) {
Stat.ReseedFrom("PufferType");
return Algorithms.RandomShuffle(SporePuffer.InfectionObjectList)[ColorIndices[Color.ToLower()]];
if (Color == null) {
MaybeLog("Null Color in GetFungalInfectionFromColor");
Color = "gold";
}
if (!ColorIndices.ContainsKey(Color.ToLower())) {
MaybeLog($"Unrecognized Color {Color} in GetFungalInfectionFromColor");
Color = "gold";
}
var index = ColorIndices[Color.ToLower()];
if (index < 0 || index > SporePuffer.InfectionObjectList.Count) {
MaybeLog($"Index {index} out of bounds in GetFungalInfectionFromColor (max is {SporePuffer.InfectionObjectList.Count})");
index = 0;
}
return Algorithms.RandomShuffle(SporePuffer.InfectionObjectList)[index];
}

public static void Puff(string color, Cell cell, GameObject actor, GameObject source = null, bool includeCenter = false) {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "Limber",
"description": "Enriches interaction with limbs and fungi",
"tags": "Limbs,Fungus",
"version": "0.2.3-alpha",
"version": "0.2.4-alpha",
"author": "Kizby",
"previewImage": "preview.png"
}

0 comments on commit 6f5c91e

Please sign in to comment.