Skip to content

Commit 0de38fe

Browse files
authored
Merge pull request #70 from KaBooMa/products
Products
2 parents fcee074 + 641f48f commit 0de38fe

8 files changed

Lines changed: 248 additions & 61 deletions

File tree

S1API/Internal/Patches/QuestPatches.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,6 @@ private static void QuestsLoaderLoad(S1Loaders.QuestsLoader __instance, string m
9393
}
9494
}
9595

96-
/// <summary>
97-
/// Patching performed for when stale files are deleted.
98-
/// </summary>
99-
/// <param name="__instance">Instance of the quest manager.</param>
100-
/// <param name="parentFolderPath">Path to the base Quest folder.</param>
101-
[HarmonyPatch(typeof(S1Quests.QuestManager), "DeleteUnapprovedFiles")]
102-
[HarmonyPostfix]
103-
private static void QuestManagerDeleteUnapprovedFiles(S1Quests.QuestManager __instance, string parentFolderPath)
104-
{
105-
string questFolder = Path.Combine(parentFolderPath, "Quests");
106-
string?[] existingQuests = QuestManager.Quests.Select(quest => quest.SaveFolder).ToArray();
107-
108-
string[] unapprovedQuestDirectories = Directory.GetDirectories(questFolder)
109-
.Where(directory => directory.StartsWith("Quest_") && !existingQuests.Contains(directory))
110-
.ToArray();
111-
112-
foreach (string unapprovedQuestDirectory in unapprovedQuestDirectories)
113-
Directory.Delete(unapprovedQuestDirectory, true);
114-
}
115-
11696
[HarmonyPatch(typeof(S1Quests.Quest), "Start")]
11797
[HarmonyPrefix]
11898
private static void QuestStart(S1Quests.Quest __instance) =>
Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,61 @@
11
#if (IL2CPPMELON)
22
using Il2CppScheduleOne.Product;
33
using S1CocaineDefinition = Il2CppScheduleOne.Product.CocaineDefinition;
4+
using S1Properties = Il2CppScheduleOne.Properties;
45
#elif (MONOMELON || MONOBEPINEX || IL2CPPBEPINEX)
56
using ScheduleOne.Product;
67
using S1CocaineDefinition = ScheduleOne.Product.CocaineDefinition;
8+
using S1Properties = ScheduleOne.Properties;
79
#endif
810

11+
using System.Collections.Generic;
912
using S1API.Internal.Utils;
1013
using S1API.Items;
1114

1215
namespace S1API.Products
1316
{
1417
/// <summary>
15-
/// Represents the definition of a Cocaine product.
18+
/// Defines the characteristics and behaviors of a cocaine product within the system.
1619
/// </summary>
1720
public class CocaineDefinition : ProductDefinition
1821
{
1922
/// <summary>
20-
/// INTERNAL: Strongly typed access to the CocaineDefinition.
23+
/// Provides internal access to the CocaineDefinition type within the Schedule One system.
2124
/// </summary>
2225
internal S1CocaineDefinition S1CocaineDefinition =>
2326
CrossType.As<S1CocaineDefinition>(S1ItemDefinition);
2427

2528
/// <summary>
26-
/// Creates a new cocaine product definition.
29+
/// Represents the definition of a cocaine product within the system.
2730
/// </summary>
28-
/// <param name="definition">The original in-game cocaine definition.</param>
2931
internal CocaineDefinition(S1CocaineDefinition definition)
30-
: base(definition) { }
32+
: base(definition)
33+
{
34+
}
3135

3236
/// <summary>
33-
/// Creates an instance of this cocaine product.
37+
/// Creates an instance of this product definition with the specified quantity.
3438
/// </summary>
39+
/// <param name="quantity">The quantity of the product to instantiate. Defaults to 1 if not specified.</param>
40+
/// <returns>An <see cref="ItemInstance"/> representing the instantiated product with the specified quantity.</returns>
3541
public override ItemInstance CreateInstance(int quantity = 1) =>
3642
new ProductInstance(CrossType.As<ProductItemInstance>(
3743
S1CocaineDefinition.GetDefaultInstance(quantity)));
44+
45+
/// <summary>
46+
/// Retrieves a list of properties associated with this product definition.
47+
/// </summary>
48+
/// <returns>A list of properties for the product.</returns>
49+
public List<S1Properties.Property> GetProperties()
50+
{
51+
var result = new List<S1Properties.Property>();
52+
var list = S1CocaineDefinition?.Properties;
53+
if (list != null)
54+
{
55+
for (int i = 0; i < list.Count; i++)
56+
result.Add(list[i]);
57+
}
58+
return result;
59+
}
3860
}
3961
}

S1API/Products/MethDefinition.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,60 @@
11
#if (IL2CPPMELON)
22
using Il2CppScheduleOne.Product;
33
using S1MethDefinition = Il2CppScheduleOne.Product.MethDefinition;
4+
using S1Properties = Il2CppScheduleOne.Properties;
45
#elif (MONOMELON || MONOBEPINEX || IL2CPPBEPINEX)
56
using ScheduleOne.Product;
67
using S1MethDefinition = ScheduleOne.Product.MethDefinition;
8+
using S1Properties = ScheduleOne.Properties;
79
#endif
810

11+
using System.Collections.Generic;
912
using S1API.Internal.Utils;
1013
using S1API.Items;
11-
1214
namespace S1API.Products
1315
{
1416
/// <summary>
15-
/// Represents the definition of a Meth product.
17+
/// Represents the definition of a meth product within the ScheduleOne product framework.
1618
/// </summary>
1719
public class MethDefinition : ProductDefinition
1820
{
1921
/// <summary>
20-
/// INTERNAL: Strongly typed access to the MethDefinition.
22+
/// INTERNAL: Strongly typed access to S1MethDefinition.
2123
/// </summary>
2224
internal S1MethDefinition S1MethDefinition =>
2325
CrossType.As<S1MethDefinition>(S1ItemDefinition);
2426

2527
/// <summary>
26-
/// Creates a new meth product definition.
28+
/// Represents the definition of a Meth product in the product framework.
2729
/// </summary>
28-
/// <param name="definition">The original in-game meth definition.</param>
2930
internal MethDefinition(S1MethDefinition definition)
30-
: base(definition) { }
31+
: base(definition)
32+
{
33+
}
3134

3235
/// <summary>
33-
/// Creates an instance of this meth product.
36+
/// Creates an instance of this meth product with the specified quantity.
3437
/// </summary>
38+
/// <param name="quantity">The quantity of the product instance to create. Defaults to 1 if not specified.</param>
39+
/// <returns>An instance of <see cref="ItemInstance"/> representing the created meth product.</returns>
3540
public override ItemInstance CreateInstance(int quantity = 1) =>
3641
new ProductInstance(CrossType.As<ProductItemInstance>(
3742
S1MethDefinition.GetDefaultInstance(quantity)));
43+
44+
/// <summary>
45+
/// Retrieves the list of properties associated with the meth product definition.
46+
/// </summary>
47+
/// <returns>A list of properties defined for the meth product.</returns>
48+
public List<S1Properties.Property> GetProperties()
49+
{
50+
var result = new List<S1Properties.Property>();
51+
var list = S1MethDefinition?.Properties;
52+
if (list != null)
53+
{
54+
for (int i = 0; i < list.Count; i++)
55+
result.Add(list[i]);
56+
}
57+
return result;
58+
}
3859
}
3960
}

S1API/Products/ProductDefinition.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#if (IL2CPPMELON)
22
using Il2CppInterop.Runtime.InteropTypes;
33
using S1Product = Il2CppScheduleOne.Product;
4+
using ItemFramework = Il2CppScheduleOne.ItemFramework;
5+
using Properties = Il2CppScheduleOne.Properties;
46
#elif (MONOMELON || MONOBEPINEX || IL2CPPBEPINEX)
57
using S1Product = ScheduleOne.Product;
8+
using ItemFramework = ScheduleOne.ItemFramework;
9+
using Properties = ScheduleOne.Properties;
610
#endif
711

12+
using System.Collections.Generic;
813
using S1API.Internal.Utils;
914
using S1API.Items;
1015
using UnityEngine;
@@ -26,8 +31,11 @@ public class ProductDefinition : ItemDefinition
2631
/// INTERNAL: Creates a product definition from the in-game product definition.
2732
/// </summary>
2833
/// <param name="productDefinition"></param>
29-
internal ProductDefinition(S1Product.ProductDefinition productDefinition) : base(productDefinition) { }
30-
34+
#if IL2CPPMELON
35+
internal ProductDefinition(ItemFramework.ItemDefinition productDefinition) : base(productDefinition) { }
36+
#else
37+
internal ProductDefinition(ItemFramework.ItemDefinition productDefinition) : base(productDefinition) { }
38+
#endif
3139
/// <summary>
3240
/// The price associated with this product.
3341
/// </summary>
@@ -49,6 +57,14 @@ public Sprite Icon
4957
{
5058
get { return S1ProductDefinition.Icon; }
5159
}
60+
#if IL2CPPMELON
61+
private List<Properties.Property> properties; // or however properties are stored
62+
public List<Properties.Property> Properties; // or however properties are stored
63+
#else
64+
private List<Properties.Property> properties; // or however properties are stored
65+
public IReadOnlyList<Properties.Property> Properties => properties.AsReadOnly();
66+
#endif
5267

53-
}
68+
69+
}
5470
}

S1API/Products/ProductDefinitionWrapper.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
using S1API.Internal.Utils;
2-
32
#if (IL2CPPMELON)
43
using S1Product = Il2CppScheduleOne.Product;
5-
#else
4+
#elif (MONOMELON || MONOBEPINEX || IL2CPPBEPINEX)
65
using S1Product = ScheduleOne.Product;
76
#endif
87

98
namespace S1API.Products
109
{
1110
/// <summary>
12-
/// INTERNAL: A wrapper class for converting a product definition to its proper dedicated class.
11+
/// Provides functionality to wrap and convert generic product definitions into their specific type-derived definitions.
1312
/// </summary>
14-
internal static class ProductDefinitionWrapper
13+
public static class ProductDefinitionWrapper
1514
{
16-
internal static ProductDefinition Wrap(ProductDefinition def)
15+
/// <summary>
16+
/// Converts a generic <see cref="ProductDefinition"/> into its corresponding typed wrapper.
17+
/// </summary>
18+
/// <param name="def">The raw product definition to be processed and converted.</param>
19+
/// <returns>A wrapped instance of <see cref="ProductDefinition"/> with type-specific methods and properties, or the input definition if no specific wrapper applies.</returns>
20+
public static ProductDefinition Wrap(ProductDefinition def)
1721
{
1822
var item = def.S1ItemDefinition;
1923
if (CrossType.Is<S1Product.WeedDefinition>(item, out var weed))
2024
return new WeedDefinition(weed);
25+
2126
if (CrossType.Is<S1Product.MethDefinition>(item, out var meth))
2227
return new MethDefinition(meth);
28+
2329
if (CrossType.Is<S1Product.CocaineDefinition>(item, out var coke))
2430
return new CocaineDefinition(coke);
31+
2532
return def;
2633
}
2734
}

S1API/Products/ProductInstance.cs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,72 @@
1-
#if (IL2CPPMELON)
1+
#if (IL2CPPMELON )
22
using S1Product = Il2CppScheduleOne.Product;
3+
using S1Properties = Il2CppScheduleOne.Properties;
34
#elif (MONOMELON || MONOBEPINEX || IL2CPPBEPINEX)
45
using S1Product = ScheduleOne.Product;
6+
using S1Properties = ScheduleOne.Properties;
57
#endif
6-
8+
using System.Collections.Generic;
79
using S1API.Internal.Utils;
8-
using S1API.Items;
9-
10+
using S1ItemInstance = S1API.Items.ItemInstance;
1011
namespace S1API.Products
1112
{
1213
/// <summary>
1314
/// Represents an instance of a product in the game.
1415
/// </summary>
15-
public class ProductInstance : ItemInstance
16+
/// <remarks>
17+
/// This class defines specific properties and behaviors for a product instance,
18+
/// such as quality, packaging, and definition, derived from the S1API's item instance structure.
19+
/// </remarks>
20+
public class ProductInstance : S1ItemInstance
1621
{
1722
/// <summary>
18-
/// INTERNAL: The stored reference to the in-game product instance.
23+
/// INTERNAL: Provides access to the underlying in-game product item instance.
1924
/// </summary>
2025
internal S1Product.ProductItemInstance S1ProductInstance =>
2126
CrossType.As<S1Product.ProductItemInstance>(S1ItemInstance);
2227

2328
/// <summary>
24-
/// INTERNAL: Creates a product instance from the in-game product instance.
29+
/// Represents an instance of a product, derived from a specific in-game product item instance,
30+
/// with additional properties for packaging, quality, and product definition.
2531
/// </summary>
26-
/// <param name="productInstance"></param>
27-
internal ProductInstance(S1Product.ProductItemInstance productInstance) : base(productInstance) { }
32+
internal ProductInstance(S1Product.ProductItemInstance productInstance)
33+
: base(productInstance)
34+
{
35+
}
2836

2937
/// <summary>
30-
/// Whether this product is currently packaged or not.
38+
/// Indicates whether the product instance has applied packaging.
3139
/// </summary>
32-
public bool IsPackaged =>
33-
S1ProductInstance.AppliedPackaging;
40+
public bool IsPackaged => S1ProductInstance.AppliedPackaging;
3441

3542
/// <summary>
36-
/// The type of packaging applied to this product.
43+
/// Provides access to the packaging information applied to the product,
44+
/// represented as a specific packaging definition instance.
3745
/// </summary>
3846
public PackagingDefinition AppliedPackaging =>
3947
new PackagingDefinition(S1ProductInstance.AppliedPackaging);
48+
49+
/// <summary>
50+
/// Represents the quality level of the product instance.
51+
/// </summary>
52+
/// <remarks>
53+
/// Quality levels provide a measure of the product's grading, ranging from "Trash" to "Heavenly".
54+
/// </remarks>
55+
public Quality Quality => S1ProductInstance.Quality.ToAPI();
56+
57+
/// <summary>
58+
/// Gets the definition of the product associated with this instance.
59+
/// </summary>
60+
public ProductDefinition Definition => new ProductDefinition(S1ProductInstance.Definition);
61+
62+
/// <summary>
63+
/// Gets the list of properties associated with the product definition.
64+
/// </summary>
65+
/// <remarks>
66+
/// This property provides an unmodifiable list of properties associated
67+
/// with the underlying product definition. Each property represents
68+
/// a specific characteristic or behavior of the corresponding product.
69+
/// </remarks>
70+
public IReadOnlyList<S1Properties.Property> Properties => Definition.Properties;
4071
}
4172
}

0 commit comments

Comments
 (0)