Skip to content

Commit f134b62

Browse files
committed
feat: get product properties
1 parent 2051d7f commit f134b62

6 files changed

Lines changed: 132 additions & 26 deletions

File tree

S1API/Products/CocaineDefinition.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,57 @@
66
using S1CocaineDefinition = ScheduleOne.Product.CocaineDefinition;
77
#endif
88

9+
using System.Collections.Generic;
910
using S1API.Internal.Utils;
1011
using S1API.Items;
1112

1213
namespace S1API.Products
1314
{
1415
/// <summary>
15-
/// Represents the definition of a Cocaine product.
16+
/// Represents the definition of a cocaine product within the system.
1617
/// </summary>
1718
public class CocaineDefinition : ProductDefinition
1819
{
1920
/// <summary>
20-
/// INTERNAL: Strongly typed access to the CocaineDefinition.
21+
/// INTERNAL: Strongly typed access to the CocaineDefinition within the Schedule One framework.
2122
/// </summary>
2223
internal S1CocaineDefinition S1CocaineDefinition =>
2324
CrossType.As<S1CocaineDefinition>(S1ItemDefinition);
2425

2526
/// <summary>
26-
/// Creates a new cocaine product definition.
27+
/// Represents the definition of a Cocaine product.
2728
/// </summary>
28-
/// <param name="definition">The original in-game cocaine definition.</param>
2929
internal CocaineDefinition(S1CocaineDefinition definition)
30-
: base(definition) { }
30+
: base(definition)
31+
{
32+
}
3133

3234
/// <summary>
33-
/// Creates an instance of this cocaine product.
35+
/// Creates an instance of this cocaine product with the specified quantity.
3436
/// </summary>
37+
/// <param name="quantity">The quantity of the product to create. Defaults to 1.</param>
38+
/// <returns>An instance of the cocaine product with the specified quantity.</returns>
3539
public override ItemInstance CreateInstance(int quantity = 1) =>
3640
new ProductInstance(CrossType.As<ProductItemInstance>(
3741
S1CocaineDefinition.GetDefaultInstance(quantity)));
42+
43+
/// <summary>
44+
/// Retrieves a list of properties associated with the current cocaine product definition.
45+
/// </summary>
46+
/// <returns>A list of properties specific to the cocaine product definition.</returns>
47+
public List<Il2CppScheduleOne.Properties.Property> GetProperties()
48+
{
49+
var result = new List<Il2CppScheduleOne.Properties.Property>();
50+
var list = S1CocaineDefinition?.Properties;
51+
if (list != null)
52+
{
53+
for (int i = 0; i < list.Count; i++)
54+
{
55+
result.Add(list[i]);
56+
}
57+
}
58+
return result;
59+
}
3860
}
61+
3962
}

S1API/Products/MethDefinition.cs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,60 @@
66
using S1MethDefinition = ScheduleOne.Product.MethDefinition;
77
#endif
88

9+
using System.Collections.Generic;
910
using S1API.Internal.Utils;
1011
using S1API.Items;
1112

1213
namespace S1API.Products
1314
{
1415
/// <summary>
15-
/// Represents the definition of a Meth product.
16+
/// Represents the definition of a Meth product in the product framework.
1617
/// </summary>
18+
/// <remarks>
19+
/// Provides methods for retrieving properties and creating instances of meth products. This class extends the base functionality provided by <see cref="ProductDefinition"/>.
20+
/// </remarks>
1721
public class MethDefinition : ProductDefinition
1822
{
1923
/// <summary>
20-
/// INTERNAL: Strongly typed access to the MethDefinition.
24+
/// INTERNAL: Strongly typed access to S1MethDefinition, representing the Il2CppScheduleOne.Product.MethDefinition entity.
2125
/// </summary>
2226
internal S1MethDefinition S1MethDefinition =>
2327
CrossType.As<S1MethDefinition>(S1ItemDefinition);
2428

2529
/// <summary>
26-
/// Creates a new meth product definition.
30+
/// Represents the definition of a Meth product.
2731
/// </summary>
28-
/// <param name="definition">The original in-game meth definition.</param>
2932
internal MethDefinition(S1MethDefinition definition)
30-
: base(definition) { }
33+
: base(definition)
34+
{
35+
}
3136

3237
/// <summary>
33-
/// Creates an instance of this meth product.
38+
/// Creates an instance of this meth product with a specified quantity.
3439
/// </summary>
40+
/// <param name="quantity">The quantity of the meth product to instantiate. Defaults to 1 if not provided.</param>
41+
/// <returns>An instance of the meth product as a <see cref="ItemInstance"/>.</returns>
3542
public override ItemInstance CreateInstance(int quantity = 1) =>
3643
new ProductInstance(CrossType.As<ProductItemInstance>(
3744
S1MethDefinition.GetDefaultInstance(quantity)));
45+
46+
/// <summary>
47+
/// Retrieves the list of properties associated with the meth product definition.
48+
/// </summary>
49+
/// <returns>A list of properties that belong to the meth product definition.</returns>
50+
public List<Il2CppScheduleOne.Properties.Property> GetProperties()
51+
{
52+
var result = new List<Il2CppScheduleOne.Properties.Property>();
53+
var list = S1MethDefinition?.Properties;
54+
if (list != null)
55+
{
56+
for (int i = 0; i < list.Count; i++)
57+
{
58+
result.Add(list[i]);
59+
}
60+
}
61+
62+
return result;
63+
}
3864
}
3965
}

S1API/Products/ProductDefinition.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using S1Product = ScheduleOne.Product;
66
#endif
77

8+
using System.Collections.Generic;
89
using S1API.Internal.Utils;
910
using S1API.Items;
1011
using UnityEngine;
@@ -26,7 +27,7 @@ public class ProductDefinition : ItemDefinition
2627
/// INTERNAL: Creates a product definition from the in-game product definition.
2728
/// </summary>
2829
/// <param name="productDefinition"></param>
29-
internal ProductDefinition(S1Product.ProductDefinition productDefinition) : base(productDefinition) { }
30+
internal ProductDefinition(Il2CppScheduleOne.ItemFramework.ItemDefinition productDefinition) : base(productDefinition) { }
3031

3132
/// <summary>
3233
/// The price associated with this product.
@@ -50,5 +51,9 @@ public Sprite Icon
5051
get { return S1ProductDefinition.Icon; }
5152
}
5253

53-
}
54+
private List<Properties.Property> properties; // or however properties are stored
55+
56+
// Add this public property if it doesn't exist yet
57+
public IReadOnlyList<Properties.Property> Properties => properties.AsReadOnly();
58+
}
5459
}

S1API/Products/ProductDefinitionWrapper.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,35 @@
22

33
#if (IL2CPPMELON || IL2CPPBEPINEX)
44
using S1Product = Il2CppScheduleOne.Product;
5+
56
#else
67
using S1Product = ScheduleOne.Product;
78
#endif
89

910
namespace S1API.Products
1011
{
1112
/// <summary>
12-
/// INTERNAL: A wrapper class for converting a product definition to its proper dedicated class.
13+
/// Provides functionality to wrap and convert generic product definitions into their specific type-derived definitions.
1314
/// </summary>
14-
internal static class ProductDefinitionWrapper
15+
public static class ProductDefinitionWrapper
1516
{
16-
internal static ProductDefinition Wrap(ProductDefinition def)
17+
/// <summary>
18+
/// Converts a generic <see cref="ProductDefinition"/> into its corresponding typed wrapper.
19+
/// </summary>
20+
/// <param name="def">The raw product definition to be processed and converted.</param>
21+
/// <returns>A wrapped instance of <see cref="ProductDefinition"/> with type-specific methods and properties, or the input definition if no specific wrapper applies.</returns>
22+
public static ProductDefinition Wrap(ProductDefinition def)
1723
{
1824
var item = def.S1ItemDefinition;
1925
if (CrossType.Is<S1Product.WeedDefinition>(item, out var weed))
2026
return new WeedDefinition(weed);
27+
2128
if (CrossType.Is<S1Product.MethDefinition>(item, out var meth))
2229
return new MethDefinition(meth);
30+
2331
if (CrossType.Is<S1Product.CocaineDefinition>(item, out var coke))
2432
return new CocaineDefinition(coke);
33+
2534
return def;
2635
}
2736
}

S1API/Products/ProductInstance.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using ScheduleOne.ItemFramework;
88
#endif
99

10+
using System.Collections.Generic;
1011
using S1API.Internal.Utils;
1112
using ItemInstance = S1API.Items.ItemInstance;
1213

@@ -27,7 +28,9 @@ public class ProductInstance : ItemInstance
2728
/// INTERNAL: Creates a product instance from the in-game product instance.
2829
/// </summary>
2930
/// <param name="productInstance"></param>
30-
internal ProductInstance(S1Product.ProductItemInstance productInstance) : base(productInstance) { }
31+
internal ProductInstance(S1Product.ProductItemInstance productInstance) : base(productInstance)
32+
{
33+
}
3134

3235
/// <summary>
3336
/// Whether this product is currently packaged or not.
@@ -40,12 +43,16 @@ internal ProductInstance(S1Product.ProductItemInstance productInstance) : base(p
4043
/// </summary>
4144
public PackagingDefinition AppliedPackaging =>
4245
new PackagingDefinition(S1ProductInstance.AppliedPackaging);
46+
4347
/// <summary>
4448
/// The quality of this product instance.
4549
/// </summary>
4650
public Quality Quality => S1ProductInstance.Quality.ToAPI();
4751

52+
// Expose the underlying definition's properties (if S1ProductInstance.Definition is available)
53+
public IReadOnlyList<Properties.Property> Properties => Definition.Properties;
4854

55+
// Add Definition property if you don't have one yet
56+
public ProductDefinition Definition => new ProductDefinition(S1ProductInstance.Definition);
4957
}
50-
5158
}

S1API/Products/WeedDefinition.cs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,69 @@
88

99
using S1API.Internal.Utils;
1010
using S1API.Items;
11+
using System.Collections.Generic;
1112

1213
namespace S1API.Products
1314
{
1415
/// <summary>
15-
/// Represents the definition of a Weed product.
16+
/// Represents a specific type of weed product definition. This class extends the functionality of
17+
/// <see cref="ProductDefinition"/> to include details specific to weed products.
1618
/// </summary>
19+
/// <remarks>
20+
/// This class provides methods and properties to work with weed-related product definitions,
21+
/// including creating product instances and accessing weed-specific properties.
22+
/// </remarks>
1723
public class WeedDefinition : ProductDefinition
1824
{
1925
/// <summary>
20-
/// INTERNAL: Strongly typed access to the WeedDefinition.
26+
/// Represents the definition of a weed product in the ScheduleOne API.
27+
/// Provides access to underlying data and functionalities specific to weed products.
2128
/// </summary>
2229
internal S1WeedDefinition S1WeedDefinition =>
2330
CrossType.As<S1WeedDefinition>(S1ItemDefinition);
2431

25-
2632
/// <summary>
27-
/// Creates a new weed product definition.
33+
/// Represents a specific type of product definition for weed products in the API.
2834
/// </summary>
29-
/// <param name="definition">The original in-game weed definition.</param>
35+
/// <remarks>
36+
/// This class acts as a wrapper for `Il2CppScheduleOne.Product.WeedDefinition`,
37+
/// providing additional functionality and a specific type for handling weed items.
38+
/// </remarks>
3039
internal WeedDefinition(S1WeedDefinition definition)
31-
: base(definition) { }
40+
: base(definition)
41+
{
42+
}
3243

3344
/// <summary>
34-
/// Creates an instance of this weed product.
45+
/// Creates an instance of the product with the specified quantity.
3546
/// </summary>
47+
/// <param name="quantity">The quantity of the product to create. Defaults to 1 if not specified.</param>
48+
/// <returns>An instance of <see cref="ItemInstance"/> representing the created product.</returns>
3649
public override ItemInstance CreateInstance(int quantity = 1) =>
3750
new ProductInstance(CrossType.As<ProductItemInstance>(
3851
S1WeedDefinition.GetDefaultInstance(quantity)));
52+
53+
/// <summary>
54+
/// Gets a list of properties associated with the current weed definition.
55+
/// </summary>
56+
/// <returns>
57+
/// A list of properties of type Il2CppScheduleOne.Properties.Property
58+
/// associated with the weed definition. If no properties are found,
59+
/// an empty list is returned.
60+
/// </returns>
61+
public List<Il2CppScheduleOne.Properties.Property> GetProperties()
62+
{
63+
var result = new List<Il2CppScheduleOne.Properties.Property>();
64+
var list = S1WeedDefinition?.Properties;
65+
if (list != null)
66+
{
67+
for (int i = 0; i < list.Count; i++)
68+
{
69+
result.Add(list[i]);
70+
}
71+
}
72+
73+
return result;
74+
}
3975
}
4076
}

0 commit comments

Comments
 (0)