Bevy Pins
A flexible pin/charm system for Bevy games, inspired by Hollow Knight's charm system. This crate provides a complete framework for equippable items that modify entity components and behavior.
Features
- Easy Pin Definition: Create pins with a single macro that handles registration automatically
- Flexible Component System: Pins can add any Bevy component to entities
- Inventory Management: Track discovered and owned pins
- Equipment System: Equip/unequip pins with notch cost limitations
- Overpin Mode: Allow equipping pins beyond normal capacity (like Hollow Knight's overcharm)
- Interactive UI: Navigate and manage pins with keyboard controls
- Auto-Discovery: Pins can be enabled/disabled and discovered dynamically
Quick Start
Add to your Cargo.toml:
[]
= "0.1.0"
= "0.17"
Basic Usage
1. Define Your Components
First, create the components that your pins will add to entities:
use *;
2. Create Pins
Use the create_pins! macro to define multiple pins at once:
use *;
create_pins!;
3. Set Up Your App
4. Add Pins to Inventory and Equip
Pin Definition Options
The create_pins! macro supports these fields:
name: Display name of the pindescription: Description text shown in UIenabled: Whether the pin appears in the game (allows hiding pins)cost: Notch cost to equip the pinimage_path: Path to the pin's image asset (optional - defaults totextures/{PinName}.png)component: The Bevy component type this pin adds to entities
Events
The system provides several events for managing pins:
AddPinToInventoryEvent/RemovePinFromInventoryEvent: Manage inventoryEquipPinEvent/UnequipPinEvent: Equip/unequip pinsOverpinToggleEvent: Toggle overpin mode
UI Controls
When the pin UI is open (press Tab):
- Arrow Keys: Navigate between pins
- Enter: Equip/unequip selected pin
- Tab: Close UI
- C: Clear all equipped pins
- Up/Down: Switch between equipped pins and pin grid sections
Resources
PinInventory: Tracks owned pinsPinEquipmentState: Tracks equipped pins per entityPinRegistry: Registry of all available pinsPinUIState: UI navigation state
Components
PinsHolder: Add to entities that can equip pinsEquippedPin: Information about equipped pins- Pin-specific components (defined by you)
Advanced Features
Overpin Mode
Like Hollow Knight's overcharm system, entities can equip pins beyond their normal capacity:
- Automatically enabled after 6 failed equip attempts
- Allows equipping high-cost pins with limited slots
- Visual indicators show overpinned status
- Auto-disables when pins are unequipped and capacity is restored
Pin Discovery
Pins can be enabled/disabled and discovered dynamically:
// Pins with enabled: false won't appear in the registry
create_pins!;
Example
Check out examples/demo.rs for a complete working example that demonstrates:
- Pin definition and registration
- Inventory management
- UI interaction
- Component effects
- Overpin functionality
Run with:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2024 Piotr Świercz tajo48@proton.me