build-game-inventory

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Build Game Inventory

构建游戏库存系统

Use one typed, serializable item source of truth and make every transfer atomic.
使用单一类型化、可序列化的物品可信源,确保每一次转移都是原子操作。

Define the item contract

定义物品契约

Model stable IDs, item definitions, ownership, stack limits, equipment compatibility, effects, rarity, presentation data, and migration version separately. Runtime UI must reference definitions by ID rather than duplicate stats or descriptions.
分别对稳定ID、物品定义、所有权、堆叠上限、装备兼容性、效果、稀有度、展示数据及迁移版本进行建模。运行时UI必须通过ID引用定义,而非重复存储属性或描述内容。

Implement transfers as transactions

将转移实现为事务操作

For pickup, equip, unequip, swap, drag/drop, consume, and sell:
  1. Validate source ownership and destination legality.
  2. Compute the entire next inventory/equipment state.
  3. Commit once or reject without changing either side.
  4. Persist only after the committed state is valid.
Never remove an item before confirming a legal destination. Preserve item identity across a swap and prevent duplicate effect registration.
针对拾取、装备、卸下、交换、拖放、消耗及出售操作:
  1. 验证来源所有权和目标合法性。
  2. 计算完整的下一版库存/装备状态。
  3. 一次性提交或拒绝,且任何一方都不会被修改。
  4. 仅在提交状态有效后进行持久化存储。
切勿在确认合法目标前移除物品。在交换过程中保留物品标识,并防止重复注册效果。

Build usable UI

构建易用的UI

Expose slot compatibility, equipped state, quantity, tooltip facts, and failure feedback. Support keyboard and touch alternatives to drag-only interactions. Keep focus behavior, dialogs, and tooltips accessible.
展示槽位兼容性、装备状态、数量、提示框信息及失败反馈。支持键盘和触摸操作作为纯拖放交互的替代方案。确保焦点行为、对话框和提示框的可访问性。

Test loss boundaries

测试丢失边界

Cover invalid destinations, full inventory, duplicate pickup, equip swap, mid-action swap, save/load, schema migration, reset/new game, tooltip updates, and repeated dispatch. Validate that total owned item identity is conserved except for explicit consumption or reward rules.
覆盖无效目标、库存已满、重复拾取、装备交换、操作中途交换、存档/加载、schema迁移、重置/新游戏、提示框更新及重复调度场景。验证除明确的消耗或奖励规则外,所有已拥有物品的标识均保持完整。