Skip to content

hkb_editor.hkb.tagfile

Tagfile

can_redo

can_redo() -> bool

Check if there are actions to redo.

Returns:

Type Description
bool

True if there is at least one action to redo, False otherwise.

can_undo

can_undo() -> bool

Check if there are actions to undo.

Returns:

Type Description
bool

True if there is at least one action to undo, False otherwise.

delete_object

delete_object(object_id: HkbRecord | str) -> HkbRecord

Delete the specified object from the behavior.

Note that this will not update any pointers referring to the object.

Parameters:

Name Type Description Default
object_id str

The HkbRecord object or object ID to remove.

required

Returns:

Type Description
HkbRecord

The removed object.

get_unique_object_paths

get_unique_object_paths(target_id: str | HkbRecord) -> Generator[list[str], None, None]

Find paths through the behavior graph that lead to the start object.

To resolve a unique path to an object, use resolve_unique_object_path.

Each element of a path is an attribute path, e.g. "transitions:2/transition". To resolve a path, start with the behavior's root object and get the field denoted by the first attribute path. This should return a pointer, which will lead you to the next object on which you resolve the second attribute path, and so on.

As object IDs are not stable and may change between HkLib conversions, this is the only reliable way of locating an object. Due to the nature of the graph structure it is possible for an object to be referenced by more than one parent, thus yielding multiple unique paths. This method will find all shortest simple paths, as per the networkx definition.

Parameters:

Name Type Description Default
target_id str | HkbRecord

The object you want to locate.

required

Yields:

Type Description
Generator[list[str], None, None]

Unique paths to reach the target object from the behavior root.

is_undo_enabled

is_undo_enabled() -> bool

Check whether undo is supported for the underlying xml tree.

Returns:

Type Description
bool

True if undo is supported, false otherwise.

query

query(query_str: str, *, object_filter: Callable[[HkbRecord], bool] = None, search_root: HkbRecord | str = None) -> Generator[HkbRecord, None, None]

Find behavior nodes matching the specified criteria.

Supports Lucene-style search queries like <field>=<value>.

  • Fields are used verbatim, with the only excception that array indices may be replaced by a * wildcard.
  • Values may be specified using fields, wildcards, fuzzy searches, ranges.
  • Terms may be combined using grouping, OR, NOT.
  • Terms separated by a space are assumed to be AND.

You may run queries over the following fields:

  • id
  • object_id (same as id)
  • type_id
  • type_name
  • name
  • parent
  • any attribute path

Examples: - id=*588 OR type_name:hkbStateMachine - bindings:0/memberPath=selectedGeneratorIndex - NOT animId=[100000..200000] - name=~AddDamageFire

Yields:

Type Description
HkbRecord

Iterator over matching records.

Raises:

Type Description
ValueError

If the query has invalid syntax.

redo

redo() -> MutationType

Redo the last mutation of the underlying xml structure.

Returns:

Type Description
ActionType

The type of the mutation that was redone, or None if there was nothing to redo.

top_undo_id

top_undo_id() -> int

Get the ID of the topmost undo item. Useful for checking if the undo stack has been changed.

Returns:

Type Description
int

The ID of the topmost undo item, or -1 if there is nothing to undo. Calling undo, then redo will place the same undo item on the top again, and so the same ID will be returned.

top_undo_type

top_undo_type() -> MutationType

Get the mutation type of the topmost undo item.

Returns:

Type Description
ActionType

Type of the topmost undo item, or None if there is nothing to undo.

transaction

transaction()

Combine all subsequent mutations of the underlying xml structure into a single undo/redo action.

Usage
with tagfile.transaction():
    element.set("a", "1")
    element.set("b", "2")
    element.append(child)
# All three operations undo/redo together

undo

undo() -> MutationType

Undo the last mutation of the underlying xml structure.

Returns:

Type Description
ActionType

The type of the mutation that was undone, or None if there was nothing to undo.