GFInventoryStack¶
API Reference / Domain / 类索引
- 路径:
addons/gf/extensions/domain/inventory/gf_inventory_stack.gd - 模块:
Domain - 继承:
Resource - API:
public - 类别:领域模型 (
domain_model) - 首次版本:
3.17.0
通用库存堆叠记录。 只保存物品标识、数量和实例数据,不解释实例数据的业务含义。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 属性 | item_id |
var item_id: StringName = &"" |
| 属性 | amount |
var amount: int: |
| 属性 | instance_data |
var instance_data: Dictionary = {} |
| 方法 | is_empty |
func is_empty() -> bool: |
| 方法 | get_stack_limit |
func get_stack_limit(registry: GFInventoryItemRegistry = null) -> int: |
| 方法 | get_available_space |
func get_available_space(registry: GFInventoryItemRegistry = null) -> int: |
| 方法 | can_merge |
func can_merge( target_item_id: StringName, target_instance_data: Dictionary = {}, registry: GFInventoryItemRegistry = null ) -> bool: |
| 方法 | add_amount |
func add_amount(quantity: int, registry: GFInventoryItemRegistry = null) -> int: |
| 方法 | remove_amount |
func remove_amount(quantity: int) -> int: |
| 方法 | clear |
func clear() -> void: |
| 方法 | duplicate_stack |
func duplicate_stack() -> GFInventoryStack: |
| 方法 | to_dict |
func to_dict() -> Dictionary: |
| 方法 | apply_dict |
func apply_dict(data: Dictionary) -> void: |
| 方法 | from_dict |
static func from_dict(data: Dictionary) -> GFInventoryStack: |
属性¶
item_id¶
- API:
public
物品稳定标识。
amount¶
- API:
public
当前堆叠数量。
instance_data¶
- API:
public
项目自定义实例数据。框架只用于兼容性比较和序列化。
结构:
instance_data: Dictionary,项目自定义物品实例数据;GF 只用于兼容性比较和序列化。
方法¶
is_empty¶
- API:
public
检查堆叠是否为空。
返回:为空返回 true。
get_stack_limit¶
- API:
public
获取当前堆叠容量上限。
参数:
| 名称 | 说明 |
|---|---|
registry |
可选物品注册表。 |
返回:堆叠容量上限。
get_available_space¶
- API:
public
获取当前堆叠剩余空间。
参数:
| 名称 | 说明 |
|---|---|
registry |
可选物品注册表。 |
返回:剩余空间。
can_merge¶
- API:
public
func can_merge( target_item_id: StringName, target_instance_data: Dictionary = {}, registry: GFInventoryItemRegistry = null ) -> bool:
检查是否可与指定物品实例合并。
参数:
| 名称 | 说明 |
|---|---|
target_item_id |
目标物品标识。 |
target_instance_data |
目标实例数据。 |
registry |
可选物品注册表。 |
返回:可合并返回 true。
结构:
target_instance_data: Dictionary,目标物品实例数据。
add_amount¶
- API:
public
增加数量并返回未加入的剩余数量。
参数:
| 名称 | 说明 |
|---|---|
quantity |
尝试增加的数量。 |
registry |
可选物品注册表。 |
返回:未加入的剩余数量。
remove_amount¶
- API:
public
移除数量并返回实际移除数量。
参数:
| 名称 | 说明 |
|---|---|
quantity |
尝试移除的数量。 |
返回:实际移除数量。
clear¶
- API:
public
清空堆叠。
duplicate_stack¶
- API:
public
复制堆叠。
返回:新堆叠资源。
to_dict¶
- API:
public
转换为字典。
返回:可序列化字典。
结构:
return: Dictionary,包含 item_id、amount 与 instance_data。
apply_dict¶
- API:
public
应用字典数据。
参数:
| 名称 | 说明 |
|---|---|
data |
字典数据。 |
结构:
data: Dictionary,可包含 item_id、amount 与 instance_data。
from_dict¶
- API:
public
从字典创建堆叠。
参数:
| 名称 | 说明 |
|---|---|
data |
字典数据。 |
返回:堆叠资源。
结构:
data: Dictionary,可包含 item_id、amount 与 instance_data。