Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xhayper committed Jun 16, 2024
1 parent 2aacd57 commit def654d
Show file tree
Hide file tree
Showing 31 changed files with 168 additions and 202 deletions.
2 changes: 1 addition & 1 deletion COTL_API/CustomFollowerCommand/CustomFollowerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class CustomFollowerCommand : CommandItem
public abstract string InternalName { get; }

public virtual List<FollowerCommandCategory> Categories { get; } =
new() { FollowerCommandCategory.DEFAULT_COMMAND };
[FollowerCommandCategory.DEFAULT_COMMAND];

public virtual Sprite CommandIcon { get; } =
TextureHelper.CreateSpriteFromPath(PluginPaths.ResolveAssetPath("placeholder.png"));
Expand Down
8 changes: 4 additions & 4 deletions COTL_API/CustomInventory/Patches/CustomItemRefineryPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public static void Structures_Refinery_GetCost(Structures_Refinery __instance, I
{
if (!CustomItemList.ContainsKey(Item)) return;

__result = new List<StructuresData.ItemCost>
{
new(CustomItemList[Item].RefineryInput, CustomItemList[Item].RefineryInputQty)
};
__result =
[
new StructuresData.ItemCost(CustomItemList[Item].RefineryInput, CustomItemList[Item].RefineryInputQty)
];
}

[HarmonyPostfix]
Expand Down
2 changes: 1 addition & 1 deletion COTL_API/CustomLocalization/CustomLocalizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace COTL_API.CustomLocalization;
public partial class CustomLocalizationManager
{
public static Dictionary<string, Dictionary<string, string>> LocalizationMap { get; } = new();
public static List<string> LanguageList { get; } = new();
public static List<string> LanguageList { get; } = [];

/// <summary>
/// Loads a localization file from a path.
Expand Down
24 changes: 10 additions & 14 deletions COTL_API/CustomMission/CustomMissionPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace COTL_API.CustomMission;
public static partial class CustomMissionManager
{
private static MissionButton? _newMissionButton;
private static readonly List<MissionInstance> MissionInstanceList = new();
private static readonly List<MissionInstance> MissionInstanceList = [];

[HarmonyPostfix]
[HarmonyPatch(typeof(MissionInfoCard), nameof(MissionInfoCard.Configure))]
Expand Down Expand Up @@ -138,19 +138,15 @@ public static bool GetReward(ref InventoryItem.ITEM_TYPE type, ref float chance,
return false;
}

public class MissionInstance
public class MissionInstance(
int instance,
MissionButton? button,
InventoryItem.ITEM_TYPE type,
CustomMission mission)
{
public MissionInstance(int instance, MissionButton? button, InventoryItem.ITEM_TYPE type, CustomMission mission)
{
Instance = instance;
Button = button;
Type = type;
Mission = mission;
}

public int Instance { get; }
public MissionButton? Button { get; }
private InventoryItem.ITEM_TYPE Type { get; }
public CustomMission Mission { get; }
public int Instance { get; } = instance;
public MissionButton? Button { get; } = button;
private InventoryItem.ITEM_TYPE Type { get; } = type;
public CustomMission Mission { get; } = mission;
}
}
15 changes: 4 additions & 11 deletions COTL_API/CustomObjectives/CustomObjective.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
namespace COTL_API.CustomObjectives;

public class CustomObjective
public class CustomObjective(int questID, string initialQuestText, ObjectivesData objectiveData)
{
public CustomObjective(int questID, string initialQuestText, ObjectivesData objectiveData)
{
QuestID = questID;
InitialQuestText = initialQuestText;
ObjectiveData = objectiveData;
}

public int QuestID { get; internal set; }
public string InitialQuestText { get; set; }
public ObjectivesData ObjectiveData { get; internal set; }
public int QuestID { get; internal set; } = questID;
public string InitialQuestText { get; set; } = initialQuestText;
public ObjectivesData ObjectiveData { get; internal set; } = objectiveData;
}
5 changes: 5 additions & 0 deletions COTL_API/CustomRelics/CustomRelicData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public virtual void OnUseDamned(bool forceConsumableAnimation = false)
OnUse(forceConsumableAnimation);
}

public virtual void OnUseAny(bool forceConsumableAnimation = false)
{
OnUse(forceConsumableAnimation);
}

public CustomRelicData ToBlessed()
{
var clone = (CustomRelicData)MemberwiseClone();
Expand Down
3 changes: 3 additions & 0 deletions COTL_API/CustomRelics/CustomRelicPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ private static void PlayerRelic_UseRelic(RelicType relicType, bool forceConsumab
case RelicSubType.Dammed:
CustomRelicDataList[relicType].OnUseDamned(forceConsumableAnimation);
break;
case RelicSubType.Any:
CustomRelicDataList[relicType].OnUseAny(forceConsumableAnimation);
break;
default:
CustomRelicDataList[relicType].OnUse(forceConsumableAnimation);
break;
Expand Down
2 changes: 1 addition & 1 deletion COTL_API/CustomRituals/CustomRitual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class CustomRitual : Ritual
TextureHelper.CreateSpriteFromPath(PluginPaths.ResolveAssetPath("placeholder.png"));

public virtual List<StructuresData.ItemCost> ItemCosts { get; } =
new() { new StructuresData.ItemCost(InventoryItem.ITEM_TYPE.LOG, 1) };
[new StructuresData.ItemCost(InventoryItem.ITEM_TYPE.LOG, 1)];

public override UpgradeSystem.Type RitualType => UpgradeType;
public virtual string GetLocalizedName => $"Custom_Ritual_{InternalName}";
Expand Down
2 changes: 1 addition & 1 deletion COTL_API/CustomSettings/CustomSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace COTL_API.CustomSettings;

public static class CustomSettingsManager
{
internal static List<ISettingsElement> SettingsElements { get; } = new();
internal static List<ISettingsElement> SettingsElements { get; } = [];

internal static ReadOnlyCollection<Slider> Sliders => SettingsElements.OfType<Slider>().ToList().AsReadOnly();
internal static ReadOnlyCollection<Dropdown> Dropdowns => SettingsElements.OfType<Dropdown>().ToList().AsReadOnly();
Expand Down
139 changes: 56 additions & 83 deletions COTL_API/CustomSettings/Elements/SettingComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,120 +10,93 @@ public interface ISettingsElement
public string Text { get; }
}

public class Slider : ISettingsElement
public class Slider(
string? category,
string text,
float value,
float min,
float max,
int increment,
MMSlider.ValueDisplayFormat displayFormat,
Action<float>? onValueChanged)
: ISettingsElement
{
public Slider(string? category, string text, float value, float min, float max, int increment,
MMSlider.ValueDisplayFormat displayFormat, Action<float>? onValueChanged)
{
Category = category;
Text = text;
Value = value;
Min = min;
Max = max;
Increment = increment;
DisplayFormat = displayFormat;
OnValueChanged = onValueChanged;
}

public string? Category { get; set; }

public string Text { get; set; }

public float Value { get; set; }
public float Min { get; set; }
public float Max { get; set; }
public int Increment { get; set; }
public MMSlider.ValueDisplayFormat DisplayFormat { get; set; }

public Action<float>? OnValueChanged { get; set; }
public string? Category { get; set; } = category;

public string Text { get; set; } = text;

public float Value { get; set; } = value;
public float Min { get; set; } = min;
public float Max { get; set; } = max;
public int Increment { get; set; } = increment;
public MMSlider.ValueDisplayFormat DisplayFormat { get; set; } = displayFormat;

public Action<float>? OnValueChanged { get; set; } = onValueChanged;

string? ISettingsElement.Category => Category;

string ISettingsElement.Text => Text;
}

public class Dropdown : ISettingsElement
public class Dropdown(string? category, string text, string? value, string?[] options, Action<int>? onValueChanged)
: ISettingsElement
{
public Dropdown(string? category, string text, string? value, string?[] options, Action<int>? onValueChanged)
{
Category = category;
Text = text;
Value = value;
Options = options;
OnValueChanged = onValueChanged;
}
public string? Category { get; set; } = category;

public string? Category { get; set; }
public string Text { get; set; } = text;

public string Text { get; set; }

public string? Value { get; set; }
public string?[] Options { get; set; }
public Action<int>? OnValueChanged { get; set; }
public string? Value { get; set; } = value;
public string?[] Options { get; set; } = options;
public Action<int>? OnValueChanged { get; set; } = onValueChanged;

string? ISettingsElement.Category => Category;

string ISettingsElement.Text => Text;
}

public class KeyboardShortcutDropdown : ISettingsElement
public class KeyboardShortcutDropdown(
string? category,
string text,
KeyCode? value,
Action<KeyboardShortcut>? onValueChanged)
: ISettingsElement
{
public KeyboardShortcutDropdown(string? category, string text, KeyCode? value,
Action<KeyboardShortcut>? onValueChanged)
{
Category = category;
Text = text;
Value = value;
OnValueChanged = onValueChanged;
}

public KeyCode? Value { get; set; }
public Action<KeyboardShortcut>? OnValueChanged { get; set; }
public string? Category { get; set; }
public string Text { get; set; }
public KeyCode? Value { get; set; } = value;
public Action<KeyboardShortcut>? OnValueChanged { get; set; } = onValueChanged;
public string? Category { get; set; } = category;
public string Text { get; set; } = text;
}

public class HorizontalSelector : ISettingsElement
public class HorizontalSelector(
string? category,
string text,
string? value,
string?[] options,
Action<int>? onValueChanged)
: ISettingsElement
{
public HorizontalSelector(string? category, string text, string? value, string?[] options,
Action<int>? onValueChanged)
{
Category = category;
Text = text;
Value = value;
Options = options;
OnValueChanged = onValueChanged;
}

public string? Category { get; set; }
public string? Category { get; set; } = category;

public string Text { get; set; }
public string Text { get; set; } = text;

public string? Value { get; set; }
public string?[] Options { get; set; }
public Action<int>? OnValueChanged { get; set; }
public string? Value { get; set; } = value;
public string?[] Options { get; set; } = options;
public Action<int>? OnValueChanged { get; set; } = onValueChanged;

string? ISettingsElement.Category => Category;

string ISettingsElement.Text => Text;
}

public class Toggle : ISettingsElement
public class Toggle(string? category, string text, bool value, Action<bool>? onValueChanged)
: ISettingsElement
{
public Toggle(string? category, string text, bool value, Action<bool>? onValueChanged)
{
Category = category;
Text = text;
Value = value;
OnValueChanged = onValueChanged;
}

public string? Category { get; set; }
public string? Category { get; set; } = category;

public string Text { get; set; }
public string Text { get; set; } = text;

public bool Value { get; set; }
public Action<bool>? OnValueChanged { get; set; }
public bool Value { get; set; } = value;
public Action<bool>? OnValueChanged { get; set; } = onValueChanged;

string? ISettingsElement.Category => Category;

Expand Down
30 changes: 15 additions & 15 deletions COTL_API/CustomSkins/CustomFollowerSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public abstract class CustomFollowerSkin : CustomSkin
public virtual bool Unlocked { get; } = true;
public virtual bool Invariant { get; } = false;

public virtual List<WorshipperData.SlotsAndColours> Colors { get; } = new()
{
public virtual List<WorshipperData.SlotsAndColours> Colors { get; } =
[
new WorshipperData.SlotsAndColours
{
SlotAndColours = new List<WorshipperData.SlotAndColor>
{
new("ARM_LEFT_SKIN", new Color(1, 0, 1)),
new("ARM_RIGHT_SKIN", new Color(0, 0, 0)),
new("LEG_LEFT_SKIN", new Color(1, 0, 1)),
new("LEG_RIGHT_SKIN", new Color(0, 0, 0)),
new("Body_Naked", new Color(1, 0, 1)),
new("Body_Naked_Up", new Color(1, 0, 1)),
new("BODY_BTM", new Color(1, 0, 1)),
new("BODY_BTM_UP", new Color(1, 0, 1)),
new("BODY_TOP", new Color(0, 0, 0))
}
SlotAndColours =
[
new WorshipperData.SlotAndColor("ARM_LEFT_SKIN", new Color(1, 0, 1)),
new WorshipperData.SlotAndColor("ARM_RIGHT_SKIN", new Color(0, 0, 0)),
new WorshipperData.SlotAndColor("LEG_LEFT_SKIN", new Color(1, 0, 1)),
new WorshipperData.SlotAndColor("LEG_RIGHT_SKIN", new Color(0, 0, 0)),
new WorshipperData.SlotAndColor("Body_Naked", new Color(1, 0, 1)),
new WorshipperData.SlotAndColor("Body_Naked_Up", new Color(1, 0, 1)),
new WorshipperData.SlotAndColor("BODY_BTM", new Color(1, 0, 1)),
new WorshipperData.SlotAndColor("BODY_BTM_UP", new Color(1, 0, 1)),
new WorshipperData.SlotAndColor("BODY_TOP", new Color(0, 0, 0))
]
}
};
];
}
6 changes: 3 additions & 3 deletions COTL_API/CustomSkins/CustomPlayerSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void Action()
if (CustomSkinManager.PlayerSkinDict.TryGetValue(simpleName, out var simplified))
{
region.name = simplified.Item1 + ":" + simplified.Item2 + add;
return new List<Tuple<int, string>> { simplified };
return [simplified];
}

var atts = from.Attachments.Where(x => x.Name == simpleName);
List<Tuple<int, string>> tuples = new();
if (from.Attachments.All(x => x.Name != simpleName)) return new List<Tuple<int, string>>();
List<Tuple<int, string>> tuples = [];
if (from.Attachments.All(x => x.Name != simpleName)) return [];

foreach (var att in atts)
{
Expand Down
Loading

0 comments on commit def654d

Please sign in to comment.