inventory

@motioneffector/inventory

A flexible, type-safe inventory system supporting multiple storage paradigms for games and interactive applications.

npm version license TypeScript

Features

Read the full manual →

Quick Start

import { createInventoryManager } from '@motioneffector/inventory'

// Create manager with item metadata
const inventory = createInventoryManager({
  getItemWeight: (id) => ({ sword: 5, potion: 1 }[id] ?? 1),
  getItemSize: (id) => ({ sword: { width: 1, height: 3 } }[id] ?? { width: 1, height: 1 }),
  defaultStackSize: 99
})

// Create a grid-based backpack (4x4 Tetris-style)
inventory.createContainer('backpack', {
  mode: 'grid',
  width: 4,
  height: 4,
  allowRotation: true
})

// Add items
inventory.addItem('backpack', 'sword', 1)
inventory.addItem('backpack', 'potion', 5)

// Query inventory
const contents = inventory.getContents('backpack')
const canFit = inventory.canAdd('backpack', 'shield', 1)

Testing & Validation

License

MIT © motioneffector