Skip to content

Commit

Permalink
arbitrary enum display names
Browse files Browse the repository at this point in the history
fix buhnautica
  • Loading branch information
Govorunb committed Jun 14, 2024
1 parent 5920266 commit 8370b4f
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 22 deletions.
9 changes: 8 additions & 1 deletion SCHIZO/SwarmControl/Models/Game/EnumDefinitionModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;

namespace SwarmControl.Models.Game;
public class EnumDefinitionModel(Type enumType)
{
public string Name { get; set; } = enumType.Name;
public string[] Values { get; set; } = Enum.GetNames(enumType); // enumType.GetEnumNames(); // Nautilus only patches Enum.GetNames
public string[] Values { get; set; } = enumType.GetFields(BindingFlags.Public | BindingFlags.Static)
.Select(f => f.GetCustomAttribute<EnumMemberAttribute>() is { } customDisplayName
? customDisplayName.Value
: f.Name)
.ToArray();
}
6 changes: 6 additions & 0 deletions SCHIZO/SwarmControl/Redeems/CommonTechTypes.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Runtime.Serialization;

namespace SCHIZO.SwarmControl.Redeems;

public enum CommonTechTypes
Expand All @@ -7,7 +9,9 @@ public enum CommonTechTypes
Ermshark,
Tutel,
Anneel,
[EnumMember(Value = "Neuro fumo")]
NeuroFumoItem,
[EnumMember(Value = "Evil fumo")]
EvilFumoItem,

// resources
Expand All @@ -18,6 +22,7 @@ public enum CommonTechTypes
Silver,
Lead,
Gold,
[EnumMember(Value = "Scrap Metal")]
ScrapMetal,
Lithium,
Magnetite,
Expand All @@ -26,6 +31,7 @@ public enum CommonTechTypes
Diamond,

// creatures
[EnumMember(Value = "Arctic Peeper")]
ArcticPeeper,
Bladderfish,

Expand Down
4 changes: 4 additions & 0 deletions SCHIZO/SwarmControl/Redeems/Enums/AggressiveCreature.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System.Runtime.Serialization;

namespace SCHIZO.SwarmControl.Redeems.Enums;

public enum AggressiveCreature
{
Ermshark,
[EnumMember(Value = "Lily Paddler")]
LilyPaddler,
Cryptosuchus,
[EnumMember(Value = "Squid Shark")]
SquidShark,
}
29 changes: 29 additions & 0 deletions SCHIZO/SwarmControl/Redeems/Enums/CommonItems.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Runtime.Serialization;

namespace SCHIZO.SwarmControl.Redeems.Enums;

public enum CommonItems
{
Salt,
Quartz,
Titanium,
Copper,
Silver,
Lead,

[EnumMember(Value = "Neuro fumo")]
NeuroFumoItem,
[EnumMember(Value = "Evil fumo")]
EvilFumoItem,

Gold,
[EnumMember(Value = "Table Coral")]
JeweledDiskPiece,
[EnumMember(Value = "Ribbon Plant")]
GenericRibbon,

[EnumMember(Value = "Filtered Water")]
FilteredWater,
[EnumMember(Value = "Nutrient Block")]
NutrientBlock
}
14 changes: 0 additions & 14 deletions SCHIZO/SwarmControl/Redeems/Enums/CommonResources.cs

This file was deleted.

6 changes: 5 additions & 1 deletion SCHIZO/SwarmControl/Redeems/Enums/PassiveCreature.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace SCHIZO.SwarmControl.Redeems.Enums;
using System.Runtime.Serialization;

namespace SCHIZO.SwarmControl.Redeems.Enums;

public enum PassiveCreature
{
Ermfish,
Anneel,
Tutel,
[EnumMember(Value = "Arctic Peeper")]
ArcticPeeper,
Bladderfish,
Boomerang,
[EnumMember(Value = "Spinner Fish")]
SpinnerFish,
}
2 changes: 1 addition & 1 deletion SCHIZO/SwarmControl/Redeems/Helpful/GiveCommonResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SCHIZO.SwarmControl.Redeems.Helpful;
DisplayName = "Give Common Resource",
Export = false /// deprecated in favor of <see cref="SeaMonkeyDeliverySystem"/>
)]
internal class GiveCommonResource : ItemFiltered<CommonResources>
internal class GiveCommonResource : ItemFiltered<CommonItems>
{
protected override string SpawnThingName => "Item";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace SCHIZO.SwarmControl.Redeems.Helpful;
internal class SeaMonkeyDeliverySystem : Command, IParameters
{
public IReadOnlyList<Parameter> Parameters => [
new Parameter(new("item", "Item", "Item you wish delivered."), typeof(CommonResources))
new Parameter(new("item", "Item", "Item you wish delivered."), typeof(CommonItems))
];

protected override object ExecuteCore(CommandExecutionContext ctx)
Expand All @@ -32,7 +32,7 @@ protected override object ExecuteCore(CommandExecutionContext ctx)
TechType item;
try
{
if (!ctx.Input.GetNamedArguments().TryGetValue("item", out CommonResources itemFiltered))
if (!ctx.Input.GetNamedArguments().TryGetValue("item", out CommonItems itemFiltered))
return CommonResults.Error("Invalid item");
item = (TechType) Enum.Parse(typeof(TechType), itemFiltered.ToString());
}
Expand Down
5 changes: 2 additions & 3 deletions SCHIZO/SwarmControl/Redeems/Misc/BigErm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ namespace SCHIZO.SwarmControl.Redeems.Misc;
#nullable enable
[Redeem(Name = "redeem_bigerm",
DisplayName = "Big Erm",
Description = "It's time to Get Big",
RegisterConsoleCommand = true
)]
Description = "It's time to Get Big"
)]
internal class BigErm : Command, IParameters
{
public IReadOnlyList<Parameter> Parameters => [];
Expand Down
2 changes: 2 additions & 0 deletions SCHIZO/SwarmControl/Redeems/Misc/MidasTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public sealed class MidasTouch : Command, IParameters
TechType.Kyanite,
TechType.Nickel,

#if BELOWZERO // cba
TechType.TwistyBridgesMushroomChunk,
TechType.GenericRibbon,
TechType.JeweledDiskPiece, // table coral
Expand All @@ -53,6 +54,7 @@ public sealed class MidasTouch : Command, IParameters
TechType.BigFilteredWater,
TechType.DisinfectedWater,
TechType.FilteredWater,
#endif
];

public IReadOnlyList<Parameter> Parameters => [];
Expand Down

0 comments on commit 8370b4f

Please sign in to comment.