forked from KaBooMa/S1API
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Add QualityItemDefinition wrappers, StorableItemDefinition clone #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
k073l
wants to merge
3
commits into
ifBars:stable
Choose a base branch
from
k073l:feat/quality-item-wrappers
base: stable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #if (IL2CPPMELON) | ||
| using S1ItemFramework = Il2CppScheduleOne.ItemFramework; | ||
| using S1Registry = Il2CppScheduleOne.Registry; | ||
| #elif (MONOMELON || MONOBEPINEX || IL2CPPBEPINEX) | ||
| using S1ItemFramework = ScheduleOne.ItemFramework; | ||
| using S1Registry = ScheduleOne.Registry; | ||
| #endif | ||
| using System; | ||
| using S1API.Internal.Utils; | ||
|
|
||
| namespace S1API.Items | ||
| { | ||
| /// <summary> | ||
| /// Provides convenient static methods for creating custom quality items. | ||
| /// Use <see cref="CreateBuilder"/> for flexible configuration | ||
| /// or <see cref="CloneFrom"/> for quick variants based on existing items. | ||
| /// </summary> | ||
| public class QualityItemCreator | ||
| { | ||
| /// <summary> | ||
| /// Creates a new builder for composing a quality item definition with full flexibility. | ||
| /// Use fluent methods to configure the definition, then call Build() to register it. | ||
| /// </summary> | ||
| public static QualityItemDefinitionBuilder CreateBuilder() | ||
| { | ||
| return new QualityItemDefinitionBuilder(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new quality item builder by cloning an existing quality item by ID. | ||
| /// </summary> | ||
| /// <param name="sourceItemId">The ID of the item to clone.</param> | ||
| /// <returns>A builder pre-configured with the source item properties.</returns> | ||
| /// <exception cref="ArgumentException">Thrown if the source item ID is not found or is not a quality item.</exception> | ||
| public static QualityItemDefinitionBuilder CloneFrom(string sourceItemId) | ||
| { | ||
| var sourceDefinition = S1Registry.GetItem(sourceItemId); | ||
| if (sourceDefinition == null) | ||
| { | ||
| throw new ArgumentException($"Source item with ID '{sourceItemId}' not found in registry", nameof(sourceItemId)); | ||
| } | ||
|
|
||
| if (!CrossType.Is(sourceDefinition, out S1ItemFramework.QualityItemDefinition qualityDef)) | ||
| { | ||
| throw new ArgumentException($"Item '{sourceItemId}' is not an QualityItemDefinition", nameof(sourceItemId)); | ||
| } | ||
|
|
||
| return new QualityItemDefinitionBuilder(qualityDef); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new quality item builder by cloning an existing quality item wrapper. | ||
| /// </summary> | ||
| /// <param name="source">The quality item definition to clone.</param> | ||
| /// <returns>A builder pre-configured with the source item properties.</returns> | ||
| /// <exception cref="ArgumentNullException">Thrown if the source definition is null.</exception> | ||
| public static QualityItemDefinitionBuilder CloneFrom(QualityItemDefinition source) | ||
| { | ||
| if (source == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(source), "Source storable item definition cannot be null"); | ||
| } | ||
|
|
||
| return new QualityItemDefinitionBuilder(source.S1QualityDefinition); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #if (IL2CPPMELON) | ||
| using S1ItemFramework = Il2CppScheduleOne.ItemFramework; | ||
| #elif (MONOMELON || MONOBEPINEX || IL2CPPBEPINEX) | ||
| using S1ItemFramework = ScheduleOne.ItemFramework; | ||
| #endif | ||
| using S1API.Products; | ||
|
|
||
| namespace S1API.Items | ||
| { | ||
| /// <summary> | ||
| /// Represents a quality item definition that can be consumed or used in recipes | ||
| /// Extends <see cref="StorableItemDefinition"/> with quality-specific properties. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Use <see cref="QualityItemCreator"/> | ||
| /// </remarks> | ||
| public class QualityItemDefinition : StorableItemDefinition | ||
| { | ||
| /// <summary> | ||
| /// INTERNAL: Wraps an existing native quality item definition. | ||
| /// </summary> | ||
| internal QualityItemDefinition(S1ItemFramework.QualityItemDefinition definition) : base(definition) | ||
| { | ||
| S1QualityDefinition = definition; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// INTERNAL: The underlying S1 quality item definition instance. | ||
| /// </summary> | ||
| internal S1ItemFramework.QualityItemDefinition S1QualityDefinition { get; } | ||
|
|
||
| /// <summary> | ||
| /// Creates a quality item instance from this definition using the default quality. | ||
| /// </summary> | ||
| /// <param name="quantity">The quantity to apply to the created instance.</param> | ||
| /// <returns>A quality item instance using this definition's default quality.</returns> | ||
| public override ItemInstance CreateInstance(int quantity = 1) => CreateInstance(quantity, DefaultQuality); | ||
|
|
||
| /// <summary> | ||
| /// Creates a quality item instance from this definition with the specified quality. | ||
| /// </summary> | ||
| /// <param name="quality">The quality to apply to the created instance.</param> | ||
| /// <returns>A quality item instance using the specified quality.</returns> | ||
| public QualityItemInstance CreateInstance(Quality quality) => CreateInstance(1, quality); | ||
|
|
||
| /// <summary> | ||
| /// Creates a quality item instance from this definition with the specified quantity and quality. | ||
| /// </summary> | ||
| /// <param name="quantity">The quantity to apply to the created instance.</param> | ||
| /// <param name="quality">The quality to apply to the created instance.</param> | ||
| /// <returns>A quality item instance using the specified quantity and quality.</returns> | ||
| public QualityItemInstance CreateInstance(int quantity, Quality quality) => | ||
| new QualityItemInstance(new S1ItemFramework.QualityItemInstance( | ||
| S1QualityDefinition, | ||
| quantity, | ||
| (S1ItemFramework.EQuality)quality)); | ||
|
|
||
| /// <summary> | ||
| /// The default quality for this item. | ||
| /// </summary> | ||
| public Quality DefaultQuality | ||
| { | ||
| get => (Quality)S1QualityDefinition.DefaultQuality; | ||
| set => S1QualityDefinition.DefaultQuality = (S1ItemFramework.EQuality)value; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.