Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: Inventory

[17:7] extends: FxObj

Wraps FXGL's Inventory, a generic container of items keyed by an arbitrary type T (often a string, enum, or entity-type tag). Each item carries a display name, description, view Node, and quantity. The wrapper exposes the simple-add path (name + description + view + quantity) plus the quantity queries and remove operations needed by typical inventory UIs.

Methods

  • Inventory (int Capacity = 100)

    Creates a new Inventory with the given capacity (max number of distinct items, not total stack size).

    • @p Capacity is the maximum distinct-item count.
  • adopt (object Ajo)

    Wraps an existing Inventory AussomJavaObject.

    • @p Ajo is an AussomJavaObject around an Inventory.
    • @r A new wrapper.
  • add (Item, string Name, string Description, int Quantity = 1)

    Adds an item with name + description + quantity. View defaults to FXGL's empty Group and maxStackQuantity to Integer.MAX_VALUE. Returns true on success, false if the inventory is full or Quantity is non-positive.

    • @p Item is the item key (string, enum, or arbitrary value).
    • @p Name is the display name.
    • @p Description is the item description.
    • @p Quantity is the initial quantity.
    • @r A bool.
  • addConfig (Item, object ConfigObj, int Quantity = 1)

    Adds an item using a full ItemConfig (so callers can set a view Node and a per-stack quantity cap). Use this when the simple name + description form is not enough -- e.g. when a UI inventory needs each item to render with its own sprite, or when an item should split across stacks at a known cap. Returns true on success, false if the inventory is full.

    • @p Item is the item key.
    • @p ConfigObj is an ItemConfig wrapper.
    • @p Quantity is the initial quantity.
    • @r A bool.
  • remove (Item)

    Removes an item by key.

    • @p Item is the item key.
    • @r this object
  • hasItem (Item)

    Returns whether the inventory currently holds the item.

    • @p Item is the item key.
    • @r A bool.
  • getItemQuantity (Item)

    Returns the current quantity of the item (0 if not held).

    • @p Item is the item key.
    • @r An int.
  • incrementQuantity (Item, int Amount)

    Increments the item's quantity by the given amount. Returns true on success, false if capacity exceeded.

    • @p Item is the item key.
    • @p Amount is the delta to apply.
    • @r A bool.
  • size ()

    Returns the inventory item count (number of stacks).

    • @r An int.
  • getCapacity ()

    Returns the inventory's capacity (the maximum number of stacks it can hold).

    • @r An int.
  • setCapacity (int Capacity)

    Resizes the inventory's capacity at runtime. Reducing below the current size does not drop existing stacks; it only blocks future adds.

    • @p Capacity is the new stack count.
    • @r this object
  • isFull ()

    Returns true when the inventory has reached its capacity.

    • @r A bool.
  • getNumFreeStacks ()

    Returns how many stack slots are still free.

    • @r An int.
  • itemsProperty ()

    Returns the underlying unmodifiable ObservableList of ItemStacks. Bind a JavaFX ListView to this to render an inventory grid that updates as items change.

    • @r An AussomJavaObject around an ObservableList.
  • getItemQuantityProperty (Item)

    Returns the IntegerProperty backing the item's total quantity (across all stacks). Useful for binding a label to a stack count. Throws if the item is not in the inventory.

    • @p Item is the item key.
    • @r An AussomJavaObject around an IntegerProperty.
  • getData (Item)

    Returns the ItemData wrapper for the given item, or null if not held. ItemData carries the name, description, view Node, total quantity, per-stack cap, and the list of stacks.

    • @p Item is the item key.
    • @r An ItemData wrapper or null.
  • getAllData ()

    Returns the inventory's full metadata as a list of ItemData wrappers, one per held item.

    • @r A list of ItemData wrappers.
  • transferFrom (object OtherObj, Item, int Quantity = 1)

    Moves an item with the given quantity from Other to this inventory. Returns true when both halves of the transfer succeed; returns false (with no changes) on capacity or stock failure.

    • @p OtherObj is an Inventory wrapper.
    • @p Item is the item key.
    • @p Quantity is the amount to move.
    • @r A bool.
  • transferAllFrom (object OtherObj)

    Moves every stack from Other into this inventory. Returns true when at least one item transferred successfully.

    • @p OtherObj is an Inventory wrapper.
    • @r A bool.
  • getSize ()

    Returns the count of distinct item stacks currently in the inventory.

  • itemQuantityProperty (object ItemObj)

    Returns the live IntegerProperty tracking the quantity of the supplied item. Use for binding into a HUD count label.