npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@overworld-engine/inventory

v1.5.0

Published

Headless inventory/item engine

Downloads

773

Readme

@overworld-engine/inventory

无头(headless)物品/背包引擎。不含任何 UI、不含任何游戏内容:物品定义通过配置注入, 使用物品的副作用走 @overworld-engine/core 的效果注册表,所有变更通过事件总线广播 (item:added / item:removed / item:used),供任务、成就等系统消费。

定位

  • 堆叠、容量、增删查、使用物品等机制由框架实现;
  • 物品表、效果处理器、UI 渲染等内容由游戏提供;
  • 底层是 zustand vanilla store(inventory.store),React 端用 useStore 订阅即可。

Schema:ItemDefinition

| 字段 | 说明 | | --- | --- | | id | 唯一标识 | | name / description | 对框架不透明的字符串(纯文本或 i18n key) | | icon | UI 图标提示(emoji / 精灵 id / URL) | | category | 自由分组键,用于筛选与排序 | | stackable | 是否可堆叠,默认 true | | maxStack | 每格上限;可堆叠时默认无限,不可堆叠时恒为 1 | | useEffects | EffectRef[],use() 时经效果注册表执行 | | consumable | use() 后是否扣除 1 个,默认 false | | metadata | 任意游戏自定义数据 |

API

const inventory = createInventory({
  items,       // ItemDefinition[]
  capacity,    // 格子数上限,省略 = 无限
  effects,     // EffectRegistry,解析 useEffects
  context,     // 传给效果处理器的上下文
  events,      // 事件总线,默认全局 gameEvents
  persist,     // { name?, version?, prefix?, storage? },传入即开启持久化
})
  • add(itemId, qty?){ success, added, overflow, reason? }:先填满已有堆叠,再按容量开新格
  • remove(itemId, qty?)boolean(数量不足时整体失败,不做部分移除)
  • has(itemId, qty?) / count(itemId)
  • use(itemId){ success, consumed, reason? }:执行 useEffects,consumable 扣 1
  • slots() / entries() / entriesByCategory(category):格子视图 / 按物品聚合视图
  • sortSlots(comparator?):默认按 category、再按 itemId 排序
  • registerItems(items) / getDefinition(id) / definitions():运行期增量注册物品表
  • isFull() / clear()
  • store:zustand vanilla store,可直接 subscribe 或配合 React useStore

仅持久化 slots(物品定义始终来自代码注入)。

示例

import { createEffectRegistry, gameEvents } from '@overworld-engine/core'
import { createInventory } from '@overworld-engine/inventory'

const effects = createEffectRegistry<GameCtx>()
effects.register('player.heal', ({ amount }, ctx) => ctx.heal(Number(amount)))

const inventory = createInventory({
  items: [
    {
      id: 'potion',
      name: 'item.potion.name',
      category: 'consumable',
      maxStack: 99,
      consumable: true,
      useEffects: [{ type: 'player.heal', params: { amount: 25 } }],
    },
  ],
  capacity: 20,
  effects,
  context: gameCtx,
  persist: { name: 'inventory' },
})

inventory.add('potion', 3)   // { success: true, added: 3, overflow: 0 }
inventory.use('potion')      // 执行 player.heal 效果并扣除 1 个

gameEvents.on('item:added', ({ itemId, total }) => {
  // 任务系统在这里推进"收集 N 个 X"目标
})