Skip to content

Commit 25bff74

Browse files
committed
added support to define sprite paths in config, refactored sprite paths
1 parent 9ce8f65 commit 25bff74

6 files changed

Lines changed: 89 additions & 49 deletions

File tree

MiniMapLibrary/Interactible/InteractibleSetting.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class InteractibleSetting
1313
public Color ActiveColor { get; set; }
1414
public Color InactiveColor { get; set; }
1515
public string Description { get; set; }
16+
public string IconPath { get; set; }
1617
public ISettingConfigGroup Config;
1718
}
1819
}

MiniMapLibrary/Interfaces/wrappers/SettingConfigGroup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public interface ISettingConfigGroup
1313
IConfigEntry<float> Width { get; }
1414
IConfigEntry<Color> ActiveColor { get; }
1515
IConfigEntry<Color> InactiveColor { get; }
16+
IConfigEntry<string> IconPath { get; }
1617
}
1718
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MiniMapLibrary.Interfaces;
1+
using MiniMapLibrary;
2+
using MiniMapLibrary.Interfaces;
23
using System;
34
using System.Collections.Generic;
45
using System.Text;
@@ -8,19 +9,21 @@ namespace MiniMapMod.wrappers
89
{
910
public class SettingConfigGroup : ISettingConfigGroup
1011
{
11-
public SettingConfigGroup(IConfigEntry<bool> enabled, IConfigEntry<float> height, IConfigEntry<float> width, IConfigEntry<Color> activeColor, IConfigEntry<Color> inactiveColor)
12+
public SettingConfigGroup(IConfigEntry<bool> enabled, IConfigEntry<float> height, IConfigEntry<float> width, IConfigEntry<Color> activeColor, IConfigEntry<Color> inactiveColor, IConfigEntry<string> iconPath)
1213
{
1314
Enabled = enabled;
1415
Height = height;
1516
Width = width;
1617
ActiveColor = activeColor;
1718
InactiveColor = inactiveColor;
19+
IconPath = iconPath;
1820
}
1921

2022
public IConfigEntry<bool> Enabled { get; }
2123
public IConfigEntry<float> Height { get; }
2224
public IConfigEntry<float> Width { get; }
2325
public IConfigEntry<Color> ActiveColor { get; }
2426
public IConfigEntry<Color> InactiveColor { get; }
27+
public IConfigEntry<string> IconPath { get; }
2528
}
2629
}

MiniMapLibrary/Settings.cs

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,22 @@ public static class Settings
2525

2626
public static Color DefaultInactiveColor { get; set; } = Color.grey;
2727

28+
public const string DefaultResourcePath = "Textures/MiscIcons/texMysteryIcon";
29+
2830
static Settings()
2931
{
3032
InitializeDefaultSettings();
3133
}
3234

3335
private static void InitializeDefaultSettings()
3436
{
35-
static void AddSize(InteractableKind type, float width = -1, float height = -1, Color ActiveColor = default, Color InactiveColor = default, string description = "")
37+
static void AddSize(InteractableKind type,
38+
float width = -1,
39+
float height = -1,
40+
Color ActiveColor = default,
41+
Color InactiveColor = default,
42+
string description = "",
43+
string path = DefaultResourcePath)
3644
{
3745
ActiveColor = ActiveColor == default ? DefaultActiveColor : ActiveColor;
3846
InactiveColor = InactiveColor == default ? DefaultInactiveColor : InactiveColor;
@@ -52,21 +60,59 @@ static void AddSize(InteractableKind type, float width = -1, float height = -1,
5260
};
5361

5462
setting.Description = description;
63+
setting.IconPath = path;
5564

5665
InteractibleSettings.Add(type, setting);
5766
}
5867

59-
AddSize(InteractableKind.Chest, 10, 8, description: "Chests, including shops");
60-
AddSize(InteractableKind.Shrine, description: "All shrines (excluding Newt)");
61-
AddSize(InteractableKind.Teleporter, 15, 15, ActiveColor: Color.white, InactiveColor: Color.green, description: "Boss teleporters");
62-
AddSize(InteractableKind.Player, 8, 8, ActiveColor: PlayerIconColor, InactiveColor: PlayerIconColor, description: "");
63-
AddSize(InteractableKind.Barrel, 5, 5, description: "Barrels");
64-
AddSize(InteractableKind.Drone, 7, 7, description: "Drones");
65-
AddSize(InteractableKind.Special, 7, 7, description: "Special interactibles such as the landing pod");
66-
AddSize(InteractableKind.Enemy, 3, 3, ActiveColor: Color.red, description: "Enemies");
67-
AddSize(InteractableKind.Utility, description: "Scrappers");
68-
AddSize(InteractableKind.Printer, 10, 8, description: "Printers");
69-
AddSize(InteractableKind.LunarPod, 7, 7, description: "Lunar pods (chests)");
68+
AddSize(InteractableKind.Chest, 10, 8,
69+
description: "Chests, including shops",
70+
path: "Textures/MiscIcons/texInventoryIconOutlined");
71+
72+
AddSize(InteractableKind.Shrine,
73+
description: "All shrines (excluding Newt)",
74+
path: "Textures/MiscIcons/texShrineIconOutlined");
75+
76+
AddSize(InteractableKind.Teleporter, 15, 15,
77+
ActiveColor: Color.white,
78+
InactiveColor: Color.green,
79+
description: "Boss teleporters",
80+
path: "Textures/MiscIcons/texTeleporterIconOutlined");
81+
82+
AddSize(InteractableKind.Player, 8, 8,
83+
ActiveColor: PlayerIconColor,
84+
InactiveColor: PlayerIconColor,
85+
description: "",
86+
path: "Textures/MiscIcons/texBarrelIcon");
87+
88+
AddSize(InteractableKind.Barrel, 5, 5,
89+
description: "Barrels",
90+
path: "Textures/MiscIcons/texBarrelIcon");
91+
92+
AddSize(InteractableKind.Drone, 7, 7,
93+
description: "Drones",
94+
path: "Textures/MiscIcons/texDroneIconOutlined");
95+
96+
AddSize(InteractableKind.Special, 7, 7,
97+
description: "Special interactibles such as the landing pod",
98+
path: DefaultResourcePath);
99+
100+
AddSize(InteractableKind.Enemy, 3, 3,
101+
ActiveColor: Color.red,
102+
description: "Enemies",
103+
path: "Textures/MiscIcons/texBarrelIcon");
104+
105+
AddSize(InteractableKind.Utility,
106+
description: "Scrappers",
107+
path: "Textures/MiscIcons/texLootIconOutlined");
108+
109+
AddSize(InteractableKind.Printer, 10, 8,
110+
description: "Printers",
111+
path: "Textures/MiscIcons/texInventoryIconOutlined");
112+
113+
AddSize(InteractableKind.LunarPod, 7, 7,
114+
description: "Lunar pods (chests)",
115+
path: "Textures/MiscIcons/texLootIconOutlined");
70116
}
71117

72118
public static InteractibleSetting GetSetting(InteractableKind type)
@@ -115,14 +161,15 @@ public static void LoadConfigEntries(InteractableKind type, IConfig config)
115161
IConfigEntry<Color> inactiveColor = config.Bind<Color>($"Icon.{type}", "inactiveColor", setting.InactiveColor, "The color the icon should be when it has used/bought");
116162
IConfigEntry<float> width = config.Bind<float>($"Icon.{type}", "width", setting.Dimensions.Width, "Width of the icon");
117163
IConfigEntry<float> height = config.Bind<float>($"Icon.{type}", "height", setting.Dimensions.Height, "Width of the icon");
164+
IConfigEntry<string> path = config.Bind<string>($"Icon.{type}", "icon", setting.IconPath ?? DefaultResourcePath, $"The streaming assets path of the icon");
118165

119-
120-
InteractibleSettings[type].Config = new SettingConfigGroup(enabled, height, width, activeColor, inactiveColor);
166+
InteractibleSettings[type].Config = new SettingConfigGroup(enabled, height, width, activeColor, inactiveColor, path);
121167

122168
setting.ActiveColor = activeColor.Value;
123169
setting.InactiveColor = inactiveColor.Value;
124170
setting.Dimensions.Height = height.Value;
125171
setting.Dimensions.Width = width.Value;
172+
setting.IconPath = path.Value;
126173
}
127174

128175
public static void UpdateSetting(InteractableKind type, float width, float height, Color active, Color inactive)

MiniMapLibrary/SpriteManager.cs

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,8 @@ public sealed class SpriteManager : IDisposable, ISpriteManager
1212
{
1313
public const string DefaultResourcePath = "Textures/MiscIcons/texMysteryIcon";
1414

15-
private static readonly Dictionary<InteractableKind, string> s_ResourceDictionary = new Dictionary<InteractableKind, string>();
16-
1715
private readonly Dictionary<string, Sprite> SpriteCache = new Dictionary<string, Sprite>();
1816

19-
static SpriteManager()
20-
{
21-
InitializeResources();
22-
}
23-
24-
private static void InitializeResources()
25-
{
26-
static void Add(InteractableKind type, string ResourcePath)
27-
{
28-
s_ResourceDictionary.Add(type, ResourcePath);
29-
}
30-
31-
Add(InteractableKind.Shrine, "Textures/MiscIcons/texShrineIconOutlined");
32-
Add(InteractableKind.Special, DefaultResourcePath);
33-
Add(InteractableKind.Teleporter, "Textures/MiscIcons/texTeleporterIconOutlined");
34-
Add(InteractableKind.Chest, "Textures/MiscIcons/texInventoryIconOutlined");
35-
Add(InteractableKind.Drone, "Textures/MiscIcons/texDroneIconOutlined");
36-
Add(InteractableKind.Utility, "Textures/MiscIcons/texLootIconOutlined");
37-
Add(InteractableKind.Barrel, "Textures/MiscIcons/texBarrelIcon");
38-
Add(InteractableKind.Enemy, "Textures/MiscIcons/texBarrelIcon");
39-
Add(InteractableKind.Player, "Textures/MiscIcons/texBarrelIcon");
40-
Add(InteractableKind.Printer, "Textures/MiscIcons/texInventoryIconOutlined");
41-
Add(InteractableKind.LunarPod, "Textures/MiscIcons/texLootIconOutlined");
42-
Add(InteractableKind.All, DefaultResourcePath);
43-
}
44-
4517
public void Dispose()
4618
{
4719
SpriteCache.Clear();
@@ -54,12 +26,11 @@ public void Dispose()
5426
return null;
5527
}
5628

57-
if (s_ResourceDictionary.TryGetValue(type, out string? path))
29+
string? path = Settings.GetSetting(type)?.Config?.IconPath?.Value;
30+
31+
if (path != null)
5832
{
59-
if (path != null)
60-
{
61-
return GetOrCache(path);
62-
}
33+
return GetOrCache(path);
6334

6435
throw new Exception($"MissingTextureException: Interactible.{type} does not have a registered texture path to load.");
6536
}

MiniMapLibrary/StubConfigEntry.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using MiniMapLibrary.Interfaces;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace MiniMapLibrary
7+
{
8+
public class StubConfigEntry<T> : IConfigEntry<T>
9+
{
10+
public T Value { get; }
11+
12+
public StubConfigEntry(T value)
13+
{
14+
Value = value;
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)