GFTileMapCache¶
API Reference / Standard / 类索引
- 路径:
addons/gf/standard/foundation/math/gf_tile_map_cache.gd - 模块:
Standard - 继承:
Resource - API:
public - 类别:资源定义 (
resource_definition) - 首次版本:
3.17.0
通用格子数据快照与差分缓存。 用 Vector2i 管理格子字典数据,既可手动写入,也可从 TileMapLayer 采集基础 source/atlas/alternative/terrain 信息。它不规定字段语义,项目可扩展记录内容。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 属性 | cells |
var cells: Dictionary = {} |
| 方法 | update_from_tile_map |
func update_from_tile_map(layer: TileMapLayer, target_cells: Array[Vector2i] = []) -> void: |
| 方法 | set_cell_data |
func set_cell_data(cell: Vector2i, data: Dictionary) -> void: |
| 方法 | erase_cell |
func erase_cell(cell: Vector2i) -> void: |
| 方法 | has_cell |
func has_cell(cell: Vector2i) -> bool: |
| 方法 | get_cell_data |
func get_cell_data(cell: Vector2i) -> Dictionary: |
| 方法 | get_value |
func get_value(cell: Vector2i, key: StringName, default_value: Variant = null) -> Variant: |
| 方法 | clear |
func clear() -> void: |
| 方法 | diff_cells |
func diff_cells(other: GFTileMapCache, compare_key: StringName = &"") -> Array[Vector2i]: |
| 方法 | to_dict |
func to_dict() -> Dictionary: |
| 方法 | from_dict |
func from_dict(data: Dictionary) -> void: |
属性¶
cells¶
- API:
public
格子数据,结构为 Vector2i -> Dictionary。
结构:
cells: Dictionary mapping Vector2i cells to Dictionary cell records.
方法¶
update_from_tile_map¶
- API:
public
从 TileMapLayer 更新缓存。
参数:
| 名称 | 说明 |
|---|---|
layer |
目标 TileMapLayer。 |
target_cells |
要更新的格子;为空时采集 layer.get_used_cells()。 |
set_cell_data¶
- API:
public
设置一个格子的字典数据。
参数:
| 名称 | 说明 |
|---|---|
cell |
格坐标。 |
data |
格子数据。 |
结构:
data: Dictionary cell record copied into the cache.
erase_cell¶
- API:
public
移除一个格子。
参数:
| 名称 | 说明 |
|---|---|
cell |
格坐标。 |
has_cell¶
- API:
public
检查格子是否存在。
参数:
| 名称 | 说明 |
|---|---|
cell |
格坐标。 |
返回:存在时返回 true。
get_cell_data¶
- API:
public
获取格子数据副本。
参数:
| 名称 | 说明 |
|---|---|
cell |
格坐标。 |
返回:格子数据。
结构:
return: Dictionary cell record copy.
get_value¶
- API:
public
获取格子字段值。
参数:
| 名称 | 说明 |
|---|---|
cell |
格坐标。 |
key |
字段名。 |
default_value |
默认值。 |
返回:字段值。
结构:
default_value: Variant fallback value returned when the field is missing.return: Variant field value or default_value.
clear¶
- API:
public
清空缓存。
diff_cells¶
- API:
public
和另一个缓存做差分。
参数:
| 名称 | 说明 |
|---|---|
other |
另一个缓存。 |
compare_key |
为空时比较完整字典;否则只比较指定字段。 |
返回:发生变化的格子列表。
to_dict¶
- API:
public
序列化为字典。
返回:可保存的字典。
结构:
return: Dictionary mapping string cell keys to Dictionary cell records.
from_dict¶
- API:
public
从字典恢复。
参数:
| 名称 | 说明 |
|---|---|
data |
to_dict() 生成的数据。 |
结构:
data: Dictionary mapping string cell keys to Dictionary cell records.