factoriax.analysis.inventory

factoriax.analysis.inventory#

Draw a player inventory as a standalone RGB panel.

The panel holds one row for each item type except EMPTY. A row shows a sprite, a label, and a count. A row with a count of zero is dimmed and shows a -. The reader can therefore see what the player holds and what the player lacks.

The sprites come from factoriax.playground.ui.icons.render_item_icon(), which is the same source the map renderer, the hotbar, and the editor use. One item therefore looks the same everywhere.

The module uses NumPy and factoriax.playground.ui only. It does not import the debugger. The live debugger HUD, the replay viewer, and the PPO eval video all call it.

factoriax.analysis.inventory.render_inventory_panel(inventory: ndarray, width: int, height: int, *, title: str = 'Inventory') → ndarray#

Render the player inventory as an RGB panel.

Every item in INVENTORY_ITEMS gets its own row, at any panel size. One condition applies: the panel must be tall enough for one row under the title bar. With the default title, that means a height of 22 or more. Below that, the rows do not fit and the function draws none of them, which leaves an almost empty panel.

A count of zero still gets a row. That row is dimmed and shows a - in place of the number, so the reader can see which items the player does not hold.

Parameters:
  • inventory – Per-item counts in a 1-D array, indexed by ItemType value. An array shorter than the item count is allowed. Items past its end read as 0 instead of raising.

  • width – Output width in pixels.

  • height – Output height in pixels.

  • title – The heading drawn at the top left.

Returns:

RGB uint8 of shape (height, width, 3). The panel has a dark background, so a caller can composite it without a mask.

Return type:

numpy.ndarray

Notes

A label too wide for its column is retried at two smaller fonts, and dropped if it still does not fit. The icon and the count are drawn whether or not the label fits.