75 lines
1.7 KiB
GDScript
75 lines
1.7 KiB
GDScript
class_name ActionCommand
|
|
extends RefCounted
|
|
|
|
var _command_id: StringName
|
|
var _actor: WorldEntityRef
|
|
var _action_id: StringName
|
|
var _target: WorldTargetHandle
|
|
var _parameters: Dictionary
|
|
var _expected_state_revision: int
|
|
|
|
|
|
func _init(
|
|
command_id: StringName = &"",
|
|
actor: Variant = null,
|
|
action_id: StringName = &"",
|
|
target: WorldTargetHandle = null,
|
|
parameters: Dictionary = {},
|
|
expected_state_revision: int = -1
|
|
) -> void:
|
|
_command_id = command_id
|
|
_actor = _normalize_actor(actor)
|
|
_action_id = action_id
|
|
_target = target
|
|
_parameters = parameters.duplicate(true)
|
|
_expected_state_revision = expected_state_revision
|
|
|
|
|
|
func is_valid() -> bool:
|
|
return (
|
|
not _command_id.is_empty()
|
|
and _actor != null
|
|
and _actor.is_valid()
|
|
and not _action_id.is_empty()
|
|
and _target != null
|
|
and _target.is_well_formed()
|
|
and _expected_state_revision >= -1
|
|
and not WorldTargetCapability._contains_object(_parameters)
|
|
)
|
|
|
|
|
|
func get_command_id() -> StringName:
|
|
return _command_id
|
|
|
|
|
|
func get_actor_id() -> StringName:
|
|
return _actor.get_entity_id() if _actor != null else &""
|
|
|
|
|
|
func get_actor() -> WorldEntityRef:
|
|
return _actor.duplicate_ref() if _actor != null else null
|
|
|
|
|
|
func get_action_id() -> StringName:
|
|
return _action_id
|
|
|
|
|
|
func get_target() -> WorldTargetHandle:
|
|
return _target
|
|
|
|
|
|
func get_parameters() -> Dictionary:
|
|
return _parameters.duplicate(true)
|
|
|
|
|
|
func get_expected_state_revision() -> int:
|
|
return _expected_state_revision
|
|
|
|
|
|
static func _normalize_actor(actor: Variant) -> WorldEntityRef:
|
|
if actor is WorldEntityRef:
|
|
return (actor as WorldEntityRef).duplicate_ref()
|
|
if actor is StringName or actor is String:
|
|
return WorldEntityRef.create(SimulationIds.ENTITY_PERSON, StringName(actor))
|
|
return null
|