Add QualityItemDefinition wrappers, StorableItemDefinition clone#79
Conversation
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAdds 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. ChangesQuality Item System Addition
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 winDestroy the placeholder when replaced to avoid orphaned
DontDestroyOnLoadobjects.The constructor always creates
_storedItemPlaceholderunderDontDestroyOnLoad. When a custom stored item replaces it here (and similarly whenCopyPropertiesFromoverwritesStoredItemwith 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
📒 Files selected for processing (8)
S1API/Items/ItemCreator.csS1API/Items/ItemManager.csS1API/Items/QualityItemCreator.csS1API/Items/QualityItemDefinition.csS1API/Items/QualityItemDefinitionBuilder.csS1API/Items/QualityItemInstance.csS1API/Items/StorableItemDefinition.csS1API/Items/StorableItemDefinitionBuilder.cs
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.
Adds
QualityItemDefinitionwrappers, allowing for creation of custom items of that type.I also added methods for cloning an existing
StorableItemDefinitionto the builder and a missingRequiredRankmethod.Since
QualityItemDefinitionis a subclass ofStorableItemDefinition, 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
Lines Added/Removed by Author