89 lines
2.1 KiB
GDScript
89 lines
2.1 KiB
GDScript
class_name ActionResult
|
|
extends RefCounted
|
|
|
|
const STATUS_ACCEPTED := &"accepted"
|
|
const STATUS_REJECTED := &"rejected"
|
|
const STATUS_COMPLETED := &"completed"
|
|
const STATUS_FAILED := &"failed"
|
|
const VALID_STATUSES := [STATUS_ACCEPTED, STATUS_REJECTED, STATUS_COMPLETED, STATUS_FAILED]
|
|
|
|
var _command_id: StringName
|
|
var _status: StringName
|
|
var _reason_code: StringName
|
|
var _message: String
|
|
var _payload: Dictionary
|
|
|
|
|
|
func _init(
|
|
command_id: StringName = &"",
|
|
status: StringName = &"",
|
|
reason_code: StringName = &"",
|
|
message: String = "",
|
|
payload: Dictionary = {}
|
|
) -> void:
|
|
_command_id = command_id
|
|
_status = status
|
|
_reason_code = reason_code
|
|
_message = message
|
|
_payload = payload.duplicate(true)
|
|
|
|
|
|
func is_valid() -> bool:
|
|
return (
|
|
not _command_id.is_empty()
|
|
and _status in VALID_STATUSES
|
|
and not WorldTargetCapability._contains_object(_payload)
|
|
)
|
|
|
|
|
|
func is_accepted() -> bool:
|
|
return _status in [STATUS_ACCEPTED, STATUS_COMPLETED]
|
|
|
|
|
|
func is_terminal() -> bool:
|
|
return _status in [STATUS_REJECTED, STATUS_COMPLETED, STATUS_FAILED]
|
|
|
|
|
|
func did_succeed() -> bool:
|
|
return _status == STATUS_COMPLETED
|
|
|
|
|
|
func get_command_id() -> StringName:
|
|
return _command_id
|
|
|
|
|
|
func get_status() -> StringName:
|
|
return _status
|
|
|
|
|
|
func get_reason_code() -> StringName:
|
|
return _reason_code
|
|
|
|
|
|
func get_message() -> String:
|
|
return _message
|
|
|
|
|
|
func get_payload() -> Dictionary:
|
|
return _payload.duplicate(true)
|
|
|
|
|
|
static func accepted(command_id: StringName, payload: Dictionary = {}) -> ActionResult:
|
|
return ActionResult.new(command_id, STATUS_ACCEPTED, &"", "", payload)
|
|
|
|
|
|
static func rejected(
|
|
command_id: StringName, reason_code: StringName, message: String = ""
|
|
) -> ActionResult:
|
|
return ActionResult.new(command_id, STATUS_REJECTED, reason_code, message)
|
|
|
|
|
|
static func completed(command_id: StringName, payload: Dictionary = {}) -> ActionResult:
|
|
return ActionResult.new(command_id, STATUS_COMPLETED, &"", "", payload)
|
|
|
|
|
|
static func failed(
|
|
command_id: StringName, reason_code: StringName, message: String = ""
|
|
) -> ActionResult:
|
|
return ActionResult.new(command_id, STATUS_FAILED, reason_code, message)
|