Skip to content

Add QualityItemDefinition wrappers, StorableItemDefinition clone#79

Open
k073l wants to merge 3 commits into
ifBars:stablefrom
k073l:feat/quality-item-wrappers
Open

Add QualityItemDefinition wrappers, StorableItemDefinition clone#79
k073l wants to merge 3 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e324e4f-8f93-48b1-954b-c91a17633ce8

📥 Commits

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

📒 Files selected for processing (1)
  • S1API/Items/QualityItemDefinitionBuilder.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • S1API/Items/QualityItemDefinitionBuilder.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 on lines +42 to +43
public new QualityItemDefinition Definition =>
new QualityItemDefinition((S1ItemFramework.QualityItemDefinition)S1QualityInstance.Definition);
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot May 29, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 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*\)' -C2

Repository: 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Correct, same pattern as in ClothingItemInstance - that's why I used that.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@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.

@coderabbitai coderabbitai Bot added the game update Fixes the API for a Schedule 1 game update label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request game update Fixes the API for a Schedule 1 game update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant