Index of every page on this site: llms.txt
All skills
jame581 avatar

/inventory-system

@426e8ab
by Jan Mesarčjame581/godotprompter979 stars
63
Run it yourself

Use when building or replacing an inventory system — Resource-based items, slots, stacking, and UI binding. Not for extending an existing one

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/inventory-system

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesequipment.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Equipment Extension

Reference for skills/inventory-system/SKILL.md — equipment slot system (paperdoll), SlotType enum, GDScript + C# implementations.

← Back to SKILL.md


5. Equipment Extension

Extend Inventory with a dedicated equipment layer. Equipment slots are keyed by a SlotType enum, and stat bonuses are aggregated on demand.

GDScript

# equipment.gd
class_name Equipment
extends Node

signal equipment_changed(slot: SlotType, item: ItemData)

enum SlotType {
    HEAD,
    CHEST,
    LEGS,
    HANDS,
    FEET,
    WEAPON,
    OFF_HAND,
    ACCESSORY,
}

# Maps SlotType → the ItemData currently equipped in that slot (null = empty)
var equipment_slots: Dictionary = {}


func _ready() -> void:
    for slot_type in SlotType.values():
        equipment_slots[slot_type] = null


func equip(item: ItemData, slot: SlotType) -> ItemData:
    assert(item.item_type == ItemData.ItemType.EQUIPMENT,
        "equip: '%s' is not an EQUIPMENT item" % item.name)
    var previous: ItemData = equipment_slots[slot]
    equipment_slots[slot] = item
    equipment_changed.emit(slot, item)
    return previous  # caller can return this to the inventory


func unequip(slot: SlotType) -> ItemData:
    var item: ItemData = equipment_slots[slot]
    equipment_slots[slot] = null
    if item != null:
        equipment_changed.emit(slot, null)
    return item


func get_equipped(slot: SlotType) -> ItemData:
    return equipment_slots.get(slot, null)


# Aggregate a named numeric stat from all equipped items.
# Each ItemData can expose stat bonuses via a Dictionary property named "stats".
# e.g. item.stats = { "attack": 10, "defense": 5 }
func get_total_stat(stat_name: String) -> float:
    var total := 0.0
    for item: ItemData in equipment_slots.values():
        if item == null:
            continue
        if item.get("stats") is Dictionary:
            total += float(item.stats.get(stat_name, 0))
    return total

C#

// Equipment.cs
using Godot;
using Godot.Collections;

public partial class Equipment : Node
{
    [Signal] public delegate void EquipmentChangedEventHandler(int slot, ItemData item);

    public enum SlotType
    {
        Head,
        Chest,
        Legs,
        Hands,
        Feet,
        Weapon,
        OffHand,
        Accessory,
    }

    // Maps SlotType → ItemData (null = empty)
    private readonly Dictionary<SlotType, ItemData> _equipmentSlots = new();

    public override void _Ready()
    {
        foreach (SlotType slot in System.Enum.GetValues<SlotType>())
            _equipmentSlots[slot] = null;
    }

    /// <summary>Equips item into slot. Returns the previously equipped item (may be null).</summary>
    public ItemData Equip(ItemData item, SlotType slot)
    {
        if (item.Type != ItemData.ItemType.Equipment)
        {
            GD.PushWarning($"Equip: '{item.Name}' is not an Equipment item");
            return null;
        }

        var previous          = _equipmentSlots[slot];
        _equipmentSlots[slot] = item;
        EmitSignal(SignalName.EquipmentChanged, (int)slot, item);
        return previous;
    }

    /// <summary>Unequips the item in slot. Returns the removed item (may be null).</summary>
    public ItemData Unequip(SlotType slot)
    {
        var item              = _equipmentSlots[slot];
        _equipmentSlots[slot] = null;
        if (item != null)
            EmitSignal(SignalName.EquipmentChanged, (int)slot, default(Variant));
        return item;
    }

    public ItemData GetEquipped(SlotType slot) => _equipmentSlots[slot];

    /// <summary>Aggregate a numeric stat from all currently equipped items.</summary>
    public float GetTotalStat(string statName)
    {
        float total = 0f;
        foreach (var item in _equipmentSlots.Values)
        {
            if (item == null) continue;
            // Expects ItemData to expose a Stats Dictionary property. Get() takes the
            // C# member name ("Stats"); C# members are not renamed to snake_case.
            if (item.Get("Stats").Obj is Godot.Collections.Dictionary stats
                && stats.ContainsKey(statName))
                total += stats[statName].As<float>();
        }
        return total;
    }
}

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts6d3 checks · Risk SAFE
  • Gen Agent Trust Hub6d

    This skill provides a standard architecture and implementation templates for an inventory system in Godot 4.3+. It utilizes native Godot Resource patterns for data management and signal-based UI updates. No malicious patterns, exfiltration attempts, or unsafe code execution were detected.

  • Socket7d

    No alerts

  • Snyk6d

    Risk: LOW · No issues

Signed by skilld at 426e8ab. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last week

README badge

README badge for jame581/godotprompter/inventory-system