GFCommandHistoryUtility¶
API Reference / Standard / 类索引
- 路径:
addons/gf/standard/utilities/history/gf_command_history_utility.gd - 模块:
Standard - 继承:
GFUtility - API:
public - 类别:运行时服务 (
runtime_service) - 首次版本:
3.17.0
可撤销命令历史管理器。 负责维护 GFUndoableCommand 的撤销栈与重做栈, 并提供同步/异步重放与历史序列化能力。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 属性 | max_history_size |
var max_history_size: int: |
| 属性 | undo_count |
var undo_count: int: |
| 属性 | redo_count |
var redo_count: int: |
| 属性 | async_timeout_seconds |
var async_timeout_seconds: float = 30.0 |
| 属性 | is_processing_async |
var is_processing_async: bool: |
| 方法 | init |
func init() -> void: |
| 方法 | dispose |
func dispose() -> void: |
| 方法 | record |
func record(cmd: GFUndoableCommand) -> void: |
| 方法 | execute_command |
func execute_command(cmd: GFUndoableCommand) -> Variant: |
| 方法 | undo_last |
func undo_last() -> bool: |
| 方法 | undo_last_async |
func undo_last_async() -> bool: |
| 方法 | redo |
func redo() -> bool: |
| 方法 | redo_async |
func redo_async() -> bool: |
| 方法 | clear |
func clear() -> void: |
| 方法 | can_undo |
func can_undo() -> bool: |
| 方法 | can_redo |
func can_redo() -> bool: |
| 方法 | get_undo_history |
func get_undo_history() -> Array[GFUndoableCommand]: |
| 方法 | get_redo_history |
func get_redo_history() -> Array[GFUndoableCommand]: |
| 方法 | serialize_history |
func serialize_history() -> Array[Dictionary]: |
| 方法 | serialize_full_history |
func serialize_full_history() -> Dictionary: |
| 方法 | deserialize_history |
func deserialize_history(data_array: Array, command_builder: Callable) -> void: |
| 方法 | deserialize_full_history |
func deserialize_full_history(data: Dictionary, command_builder: Callable) -> void: |
属性¶
max_history_size¶
- API:
public
撤销栈的最大容量;为 0 时表示不限制。
undo_count¶
- API:
public
当前撤销栈深度。
redo_count¶
- API:
public
当前重做栈深度。
async_timeout_seconds¶
- API:
public
异步命令等待超时时间(秒)。小于等于 0 时表示不启用超时。
is_processing_async¶
- API:
public
当前是否正在等待一条异步命令完成。
方法¶
init¶
- API:
public
初始化命令历史并清空撤销、重做栈。
dispose¶
- API:
public
释放命令历史并取消等待中的异步历史操作。
record¶
- API:
public
记录一条已经执行完成的命令。
参数:
| 名称 | 说明 |
|---|---|
cmd |
已执行的命令实例。 |
execute_command¶
- API:
public
执行命令并自动记录到撤销栈。
参数:
| 名称 | 说明 |
|---|---|
cmd |
要执行的命令实例。 |
返回:execute() 的原始返回值;异步命令可由调用方自行 await。
结构:
return: Variant returned by GFUndoableCommand.execute(), including null or Signal.
undo_last¶
- API:
public
撤销最后一条命令。
返回:成功撤销时返回 true。
undo_last_async¶
- API:
public
异步撤销最后一条命令。
返回:成功撤销时返回 true。
redo¶
- API:
public
重做最近被撤销的命令。
返回:成功重做时返回 true。
redo_async¶
- API:
public
异步重做最近被撤销的命令。
返回:成功重做时返回 true。
clear¶
- API:
public
清空所有历史记录。
can_undo¶
- API:
public
检查当前是否允许撤销。
返回:有可撤销命令时返回 true。
can_redo¶
- API:
public
检查当前是否允许重做。
返回:有可重做命令时返回 true。
get_undo_history¶
- API:
public
获取撤销栈副本。
返回:撤销历史的浅拷贝。
get_redo_history¶
- API:
public
获取重做栈副本。
返回:重做历史的浅拷贝。
serialize_history¶
- API:
public
将撤销栈序列化为纯数据数组。
返回:适合持久化的历史数据。
结构:
return: Array[Dictionary] serialized command snapshots produced by command serialize() or get_snapshot().
serialize_full_history¶
- API:
public
将完整命令历史序列化为纯数据字典。 包含 undo 与 redo 两个栈,可用于全量运行时快照恢复。
返回:适合持久化的完整历史数据。
结构:
return: Dictionary with undo and redo Array[Dictionary] stacks.
deserialize_history¶
- API:
public
通过构造器从纯数据恢复撤销栈。
参数:
| 名称 | 说明 |
|---|---|
data_array |
历史数据数组。 |
command_builder |
负责反序列化命令实例的构造器。 |
结构:
data_array: Array[Dictionary] serialized command snapshots produced by serialize_history().
deserialize_full_history¶
- API:
public
通过构造器从完整历史数据恢复撤销栈与重做栈。
参数:
| 名称 | 说明 |
|---|---|
data |
由 serialize_full_history() 生成的字典数据。 |
command_builder |
负责反序列化命令实例的构造器。 |
结构:
data: Dictionary with undo and redo Array[Dictionary] stacks.