GFInventoryItemRegistry¶
API Reference / Domain / 类索引
- 路径:
addons/gf/extensions/domain/inventory/gf_inventory_item_registry.gd - 模块:
Domain - 继承:
Resource - API:
public - 类别:资源定义 (
resource_definition) - 首次版本:
3.17.0
通用库存物品定义注册表。 统一提供物品堆叠上限、堆叠数量上限和实例数据兼容性规则。 未注册物品可按默认规则处理,便于项目渐进接入资源化定义。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 属性 | definitions |
var definitions: Dictionary = {} |
| 属性 | default_max_stack_amount |
var default_max_stack_amount: int: |
| 属性 | default_max_stack_count |
var default_max_stack_count: int: |
| 属性 | allow_unregistered_items |
var allow_unregistered_items: bool = true |
| 方法 | set_definition |
func set_definition(definition: GFInventoryItemDefinition) -> void: |
| 方法 | remove_definition |
func remove_definition(item_id: StringName) -> void: |
| 方法 | clear |
func clear() -> void: |
| 方法 | has_definition |
func has_definition(item_id: StringName) -> bool: |
| 方法 | get_definition |
func get_definition(item_id: StringName) -> GFInventoryItemDefinition: |
| 方法 | accepts_item |
func accepts_item(item_id: StringName) -> bool: |
| 方法 | get_max_stack_amount |
func get_max_stack_amount(item_id: StringName) -> int: |
| 方法 | get_max_stack_count |
func get_max_stack_count(item_id: StringName) -> int: |
| 方法 | normalize_instance_data |
func normalize_instance_data(item_id: StringName, instance_data: Dictionary = {}) -> Dictionary: |
| 方法 | are_instance_data_compatible |
func are_instance_data_compatible( item_id: StringName, left: Dictionary = {}, right: Dictionary = {} ) -> bool: |
| 方法 | to_dict |
func to_dict() -> Dictionary: |
| 方法 | apply_dict |
func apply_dict(data: Dictionary) -> void: |
| 方法 | from_dict |
static func from_dict(data: Dictionary) -> GFInventoryItemRegistry: |
属性¶
definitions¶
- API:
public
物品定义表。Key 推荐为 StringName,Value 应为 GFInventoryItemDefinition。
结构:
definitions: Dictionary,键为 StringName 或 String 物品 ID,值为 GFInventoryItemDefinition 物品定义资源。
default_max_stack_amount¶
- API:
public
未注册物品的默认单堆叠容量。
default_max_stack_count¶
- API:
public
未注册物品的默认堆叠数量上限。小于等于 0 表示不限制。
allow_unregistered_items¶
- API:
public
是否允许未注册物品进入库存。
方法¶
set_definition¶
- API:
public
添加或替换物品定义。
参数:
| 名称 | 说明 |
|---|---|
definition |
物品定义。 |
remove_definition¶
- API:
public
移除物品定义。
参数:
| 名称 | 说明 |
|---|---|
item_id |
物品标识。 |
clear¶
- API:
public
清空所有物品定义。
has_definition¶
- API:
public
检查物品定义是否存在。
参数:
| 名称 | 说明 |
|---|---|
item_id |
物品标识。 |
返回:存在返回 true。
get_definition¶
- API:
public
获取物品定义。
参数:
| 名称 | 说明 |
|---|---|
item_id |
物品标识。 |
返回:物品定义;不存在时返回 null。
accepts_item¶
- API:
public
检查物品是否可被库存接受。
参数:
| 名称 | 说明 |
|---|---|
item_id |
物品标识。 |
返回:可接受返回 true。
get_max_stack_amount¶
- API:
public
获取单堆叠容量。
参数:
| 名称 | 说明 |
|---|---|
item_id |
物品标识。 |
返回:单堆叠容量。
get_max_stack_count¶
- API:
public
获取堆叠数量上限。
参数:
| 名称 | 说明 |
|---|---|
item_id |
物品标识。 |
返回:堆叠数量上限;小于等于 0 表示不限制。
normalize_instance_data¶
- API:
public
规范化物品实例数据。
参数:
| 名称 | 说明 |
|---|---|
item_id |
物品标识。 |
instance_data |
实例数据。 |
返回:规范化后的实例数据副本。
结构:
instance_data: Dictionary,项目自定义物品实例数据。return: Dictionary,规范化后的物品实例数据副本。
are_instance_data_compatible¶
- API:
public
func are_instance_data_compatible( item_id: StringName, left: Dictionary = {}, right: Dictionary = {} ) -> bool:
判断两份实例数据是否可合并堆叠。
参数:
| 名称 | 说明 |
|---|---|
item_id |
物品标识。 |
left |
左侧实例数据。 |
right |
右侧实例数据。 |
返回:可合并返回 true。
结构:
left: Dictionary,左侧物品实例数据。right: Dictionary,右侧物品实例数据。
to_dict¶
- API:
public
转换为字典。
返回:可序列化字典。
结构:
return: Dictionary,包含 definitions、default_max_stack_amount、default_max_stack_count 与 allow_unregistered_items。
apply_dict¶
- API:
public
应用字典数据。
参数:
| 名称 | 说明 |
|---|---|
data |
字典数据。 |
结构:
data: Dictionary,可包含 definitions、default_max_stack_amount、default_max_stack_count 与 allow_unregistered_items。
from_dict¶
- API:
public
从字典创建注册表。
参数:
| 名称 | 说明 |
|---|---|
data |
字典数据。 |
返回:物品定义注册表。
结构:
data: Dictionary,可包含 definitions、default_max_stack_amount、default_max_stack_count 与 allow_unregistered_items。