Add QualityItemDefinition wrappers, StorableItemDefinition clone#79
Add QualityItemDefinition wrappers, StorableItemDefinition clone#79k073l wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 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
| public new QualityItemDefinition Definition => | ||
| new QualityItemDefinition((S1ItemFramework.QualityItemDefinition)S1QualityInstance.Definition); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm CrossType is the established native-cast helper and find any other raw native downcasts
ast-grep --pattern 'class CrossType { $$$ }'
echo "----- CrossType usage -----"
rg -nP --type=cs 'CrossType\.(Is|Cast|TryCast|As)\b' -A1
echo "----- other raw native definition casts -----"
rg -nP --type=cs '\(\s*S1\w+\.\w*Definition\s*\)' -C2Repository: ifBars/S1API
Length of output: 10848
Use CrossType for Il2Cpp definition casting in QualityItemInstance.Definition.
In S1API/Items/QualityItemInstance.cs (lines 42-43) Definition forwards via a raw managed cast: new QualityItemDefinition((S1ItemFramework.QualityItemDefinition)S1QualityInstance.Definition);. Most other native type forwards in this repo use CrossType.Is/As for Il2Cpp proxy typing; this raw cast is an outlier (the same pattern also exists in S1API/Items/ClothingItemInstance.cs). Update this forwarding to use the CrossType pattern consistent with the rest of the codebase.
🤖 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/QualityItemInstance.cs` around lines 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.
There was a problem hiding this comment.
Correct, same pattern as in ClothingItemInstance - that's why I used that.
There was a problem hiding this comment.
@k073l, understood — the raw cast in the Definition property getter is a deliberate pattern consistent with ClothingItemInstance (and other item instance wrappers). I'll note this for future reviews.
✏️ Learnings added
Learnt from: k073l
Repo: ifBars/S1API PR: 79
File: S1API/Items/QualityItemInstance.cs:42-43
Timestamp: 2026-05-29T19:18:49.648Z
Learning: In S1API (ifBars/S1API), the `Definition` property getter on `ItemInstance` subclasses (e.g., `QualityItemInstance`, `ClothingItemInstance`) intentionally uses a raw managed cast `(S1ItemFramework.SomeDefinition)instance.Definition` rather than the `CrossType.Is/As` helper. This is a deliberate, consistent pattern across item instance wrappers and should not be flagged as an inconsistency.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
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