Skip to content

Commit 2051d7f

Browse files
committed
fix: abstract quality
1 parent adf3cca commit 2051d7f

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

S1API/Products/ProductInstance.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ internal ProductInstance(S1Product.ProductItemInstance productInstance) : base(p
4343
/// <summary>
4444
/// The quality of this product instance.
4545
/// </summary>
46-
public EQuality Quality => S1ProductInstance.Quality;
46+
public Quality Quality => S1ProductInstance.Quality.ToAPI();
47+
4748

4849
}
4950

S1API/Products/Quality.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#if IL2CPPBEPINEX || IL2CPPMELON
2+
using InternalQuality = Il2CppScheduleOne.ItemFramework.EQuality;
3+
#else
4+
using InternalQuality = ScheduleOne.ItemFramework.EQuality;
5+
#endif
6+
namespace S1API.Products
7+
{
8+
/// <summary>
9+
/// Represents the quality levels for items.
10+
/// </summary>
11+
/// <remarks>
12+
/// This enumeration defines various quality tiers that items can belong to. Each tier represents a specific
13+
/// standard or grade, ranging from the lowest to the highest.
14+
/// </remarks>
15+
public enum Quality
16+
{
17+
/// <summary>
18+
/// Represents the lowest quality level, indicating an item of no value or unusable condition.
19+
/// </summary>
20+
Trash = 0,
21+
22+
/// <summary>
23+
/// Represents a quality level that is below standard but better than trash-quality.
24+
/// </summary>
25+
Poor = 1,
26+
27+
/// <summary>
28+
/// Represents a standard level of quality in the predefined quality enumeration.
29+
/// Typically used to indicate an average or commonly acceptable quality level.
30+
/// </summary>
31+
Standard = 2,
32+
33+
/// <summary>
34+
/// Represents a higher-tier quality level compared to lower
35+
Premium = 3,
36+
37+
/// <summary>
38+
/// Represents the highest level of quality, denoted as "Heavenly".
39+
Heavenly = 4
40+
}
41+
42+
/// <summary>
43+
/// Provides extension methods for converting between <see cref="Il2CppScheduleOne.ItemFramework.EQuality"/> and
44+
/// <see cref="S1API.Products.Quality"/> enumerations.
45+
/// </summary>
46+
internal static class QualityExtensions
47+
{
48+
/// <summary>
49+
/// Converts an instance of <see cref="Il2CppScheduleOne.ItemFramework.EQuality"/> to its corresponding
50+
/// <see cref="S1API.Products.Quality"/> representation.
51+
/// </summary>
52+
/// <param name="quality">The <see cref="Il2CppScheduleOne.ItemFramework.EQuality"/> instance to convert.</param>
53+
/// <returns>A <see cref="S1API.Products.Quality"/> value that represents the converted quality.</returns>
54+
internal static Quality ToAPI(this InternalQuality quality)
55+
{
56+
return quality switch
57+
{
58+
InternalQuality.Trash => Quality.Trash,
59+
InternalQuality.Poor => Quality.Poor,
60+
InternalQuality.Standard => Quality.Standard,
61+
InternalQuality.Premium => Quality.Premium,
62+
InternalQuality.Heavenly => Quality.Heavenly,
63+
_ => Quality.Trash,
64+
};
65+
}
66+
67+
/// <summary>
68+
/// Converts an instance of the <see cref="Quality"/> enum to its corresponding
69+
/// <see cref="InternalQuality"/> enum representation.
70+
/// </summary>
71+
/// <param name="quality">The <see cref="Quality"/> enum value to convert.</param>
72+
/// <returns>The corresponding <see cref="InternalQuality"/> enum value.</returns>
73+
internal static InternalQuality ToInternal(this Quality quality)
74+
{
75+
return quality switch
76+
{
77+
Quality.Trash => InternalQuality.Trash,
78+
Quality.Poor => InternalQuality.Poor,
79+
Quality.Standard => InternalQuality.Standard,
80+
Quality.Premium => InternalQuality.Premium,
81+
Quality.Heavenly => InternalQuality.Heavenly,
82+
_ => InternalQuality.Trash,
83+
};
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)