Skip to content

Add QualityItemDefinition wrappers, StorableItemDefinition clone#79

Merged
ifBars merged 4 commits into
ifBars:stablefrom
k073l:feat/quality-item-wrappers
Jun 4, 2026
Merged

Add QualityItemDefinition wrappers, StorableItemDefinition clone#79
ifBars merged 4 commits into
ifBars:stablefrom
k073l:feat/quality-item-wrappers

Conversation

@k073l
Copy link
Copy Markdown
Collaborator

@k073l k073l commented May 29, 2026

Adds QualityItemDefinition wrappers, allowing for creation of custom items of that type.

I also added methods for cloning an existing StorableItemDefinition to the builder and a missing RequiredRank method.

Since QualityItemDefinition is a subclass of StorableItemDefinition, much of the builder code is duplicated. That's not ideal, but other item creator builders also seem to follow this pattern.
I'm working on a solution to this, but that should be its own PR.

Release Notes

  • Added QualityItemDefinition wrapper class and builder for creating custom quality items at runtime
  • Introduced QualityItemCreator utility with factory methods (CreateBuilder(), CloneFrom()) for quality item creation
  • Added QualityItemInstance wrapper to expose quality property on item instances
  • Implemented QualityItemDefinitionBuilder with fluent API for configuring quality items (ID, name, description, pricing, stacking, icons, default quality, station prefab handling, and more)
  • Extended StorableItemDefinition with RequiresLevelToPurchase and RequiredRank properties for purchase-level gating
  • Enhanced StorableItemDefinitionBuilder with WithRequiredRank() and CopyPropertiesFrom() to support rank-based purchase restrictions and cloning initialization
  • Added CloneFrom() overloads to StorableItemDefinitionBuilder for cloning existing storable items by ID or reference
  • Extended ItemCreator.CreateItem() signature with requiresLevelToPurchase and requiredRank parameters and added CloneFrom overloads
  • Registered QualityItemDefinition type dispatch in ItemManager.GetItemDefinition()
  • Note: Builder code contains duplicated logic between StorableItemDefinitionBuilder and QualityItemDefinitionBuilder; a refactor is planned in a separate branch

Lines Added/Removed by Author

Author Added Removed Total
k073l 80425 0 +80425

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Warning

Review limit reached

@ifBars, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 817a6513-a0f2-464c-8776-881099f1127d

📥 Commits

Reviewing files that changed from the base of the PR and between e5f165b and 19b5a73.

📒 Files selected for processing (5)
  • .gitignore
  • S1API/Items/ClothingItemInstance.cs
  • S1API/Items/QualityItemInstance.cs
  • S1API/Products/ProductInstance.cs
  • S1API/Products/ShroomInstance.cs
📝 Walkthrough

Walkthrough

Adds a quality-item model and instance wrappers, a comprehensive QualityItemDefinitionBuilder and QualityItemCreator factory, rank-based purchase gating on storable items, and integrates quality-type dispatch into item lookup and creation APIs.

Changes

Quality Item System Addition

Layer / File(s) Summary
Quality item model and instance wrappers
S1API/Items/QualityItemDefinition.cs, S1API/Items/QualityItemInstance.cs
QualityItemDefinition extends StorableItemDefinition, wraps the native quality definition, and adds CreateInstance overloads and DefaultQuality. QualityItemInstance wraps runtime instances exposing a Quality property and a typed Definition getter.
Level and rank requirement support for storable items
S1API/Items/StorableItemDefinition.cs, S1API/Items/StorableItemDefinitionBuilder.cs
Adds RequiresLevelToPurchase and RequiredRank properties; builder ensures a hidden StoredItem placeholder, adds WithRequiredRank(Leveling.FullRank? rank), and CopyPropertiesFrom to clone properties while preserving stored-item fallback.
Quality item builder with fluent API
S1API/Items/QualityItemDefinitionBuilder.cs
New QualityItemDefinitionBuilder with fluent setters (basic info, stack, icon, pricing, legal/equippable, stored/station items, demo availability, required rank, default quality), station-item prefab caching under a hidden DontDestroyOnLoad root, best-effort module validation, Build()/BuildInternal(), and CopyPropertiesFrom.
Quality item factory entry points
S1API/Items/QualityItemCreator.cs
QualityItemCreator exposes CreateBuilder() and CloneFrom overloads that validate registry lookups and reject invalid/null sources.
Item system integration for quality items and rank gating
S1API/Items/ItemCreator.cs, S1API/Items/ItemManager.cs
ItemCreator adds CloneFrom overloads for storable items and extends CreateItem with requiresLevelToPurchase and requiredRank parameters applied via .WithRequiredRank(...). ItemManager.GetItemDefinition now dispatches native QualityItemDefinition to a QualityItemDefinition wrapper.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • ifBars/S1API#58: Edits to StorableItemDefinitionBuilder/storable item behavior related to builder changes and cloning logic.

Suggested labels

game update

Suggested reviewers

  • ifBars

Poem

🐰 I hopped through code, nibbling on ranks and quality,
Builders stitched with care beneath the hidden tree,
Station prefabs cached where no light gleams,
Items born with default hues and gated dreams,
Hooray — the warren's stocked, now go and see!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding QualityItemDefinition wrappers and StorableItemDefinition cloning methods, and is within the 50-character guideline.
Docstring Coverage ✅ Passed Docstring coverage is 87.80% which is sufficient. The required threshold is 70.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added the game update Fixes the API for a Schedule 1 game update label May 29, 2026
@k073l k073l added enhancement New feature or request and removed game update Fixes the API for a Schedule 1 game update labels May 29, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
S1API/Items/StorableItemDefinitionBuilder.cs (1)

186-195: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Destroy the placeholder when replaced to avoid orphaned DontDestroyOnLoad objects.

The constructor always creates _storedItemPlaceholder under DontDestroyOnLoad. When a custom stored item replaces it here (and similarly when CopyPropertiesFrom overwrites StoredItem with a non-null source), the placeholder is no longer referenced by the definition but is never destroyed, so it lingers for the whole session.

🧹 Proposed fix
             var storedItem = storedItemPrefab.GetComponent<S1Storage.StoredItem>() ?? storedItemPrefab.AddComponent<S1Storage.StoredItem>();
+            if (_storedItemPlaceholder != null && _definition.StoredItem == _storedItemPlaceholder.GetComponent<S1Storage.StoredItem>())
+                Object.Destroy(_storedItemPlaceholder);
             _definition.StoredItem = storedItem;
             _hasCustomStoredItem = true;
             return this;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@S1API/Items/StorableItemDefinitionBuilder.cs` around lines 186 - 195, When
replacing the auto-created placeholder, ensure it is destroyed so it doesn't
linger under DontDestroyOnLoad: in WithStoredItem (and likewise in
CopyPropertiesFrom where _definition.StoredItem may be overwritten) check if
_storedItemPlaceholder != null and _definition.StoredItem ==
_storedItemPlaceholder, then call UnityEngine.Object.Destroy on the
placeholder's GameObject and clear _storedItemPlaceholder before assigning the
new _definition.StoredItem; this removes the orphaned DontDestroyOnLoad object
when you set a custom StoredItem.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@S1API/Items/QualityItemDefinition.cs`:
- Around line 52-56: The CreateInstance method may be passing arguments to the
native constructor in the wrong order/arity: inspect the native
S1ItemFramework.QualityItemInstance constructor signature and confirm the
expected parameters and types, then update QualityItemDefinition.CreateInstance
to match that signature (reordering or converting arguments as needed) when
calling new S1ItemFramework.QualityItemInstance(S1QualityDefinition, quantity,
(S1ItemFramework.EQuality)quality); ensure S1QualityDefinition, quantity and the
cast to S1ItemFramework.EQuality are provided in the exact order and types the
native constructor requires.

In `@S1API/Items/QualityItemDefinitionBuilder.cs`:
- Line 29: The XML documentation comment in QualityItemDefinitionBuilder.cs has
a malformed closing tag "</summary" (missing '>') which causes CS1570; open the
doc block above the QualityItemDefinitionBuilder type/method and correct the
closing tag to "</summary>" so the XML doc is well-formed and
IntelliSense/CS1570 errors are resolved.

In `@S1API/Items/QualityItemInstance.cs`:
- Around line 42-43: The Definition property in QualityItemInstance currently
constructs QualityItemDefinition via a raw managed cast from
S1QualityInstance.Definition; replace that cast with the repo's Il2Cpp proxy
pattern by using CrossType.Is/CrossType.As to verify/convert the underlying
S1ItemFramework.QualityItemDefinition before wrapping it in the
QualityItemDefinition proxy — locate the Definition getter on
QualityItemInstance and change the new
QualityItemDefinition((S1ItemFramework.QualityItemDefinition)S1QualityInstance.Definition)
logic to call CrossType.Is/As on S1QualityInstance.Definition (matching other
forwards) and then pass the resulting proxied instance into the
QualityItemDefinition constructor.

---

Outside diff comments:
In `@S1API/Items/StorableItemDefinitionBuilder.cs`:
- Around line 186-195: When replacing the auto-created placeholder, ensure it is
destroyed so it doesn't linger under DontDestroyOnLoad: in WithStoredItem (and
likewise in CopyPropertiesFrom where _definition.StoredItem may be overwritten)
check if _storedItemPlaceholder != null and _definition.StoredItem ==
_storedItemPlaceholder, then call UnityEngine.Object.Destroy on the
placeholder's GameObject and clear _storedItemPlaceholder before assigning the
new _definition.StoredItem; this removes the orphaned DontDestroyOnLoad object
when you set a custom StoredItem.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c598d86-0c0e-40c2-92b8-8340902e97ff

📥 Commits

Reviewing files that changed from the base of the PR and between 248d8fe and e7415fd.

📒 Files selected for processing (8)
  • S1API/Items/ItemCreator.cs
  • S1API/Items/ItemManager.cs
  • S1API/Items/QualityItemCreator.cs
  • S1API/Items/QualityItemDefinition.cs
  • S1API/Items/QualityItemDefinitionBuilder.cs
  • S1API/Items/QualityItemInstance.cs
  • S1API/Items/StorableItemDefinition.cs
  • S1API/Items/StorableItemDefinitionBuilder.cs

Comment thread S1API/Items/QualityItemDefinition.cs
Comment thread S1API/Items/QualityItemDefinitionBuilder.cs Outdated
Comment thread S1API/Items/QualityItemInstance.cs Outdated
@coderabbitai coderabbitai Bot added the game update Fixes the API for a Schedule 1 game update label May 29, 2026
@ifBars ifBars removed the game update Fixes the API for a Schedule 1 game update label Jun 2, 2026
Route derived item definition access through CrossType.As so IL2CPP wrappers use the runtime-safe cast path consistently. This covers quality, clothing, product, and shroom item instances, including the pre-existing clothing pattern that the PR copied.
@ifBars ifBars merged commit 60d89f7 into ifBars:stable Jun 4, 2026
5 checks passed
@ifBars ifBars deleted the feat/quality-item-wrappers branch June 4, 2026 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants