feat: add emergent world foundations
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
class_name ActionCommand
|
||||
extends RefCounted
|
||||
|
||||
var _command_id: StringName
|
||||
var _actor_id: StringName
|
||||
var _action_id: StringName
|
||||
var _target: WorldTargetHandle
|
||||
var _parameters: Dictionary
|
||||
|
||||
|
||||
func _init(
|
||||
command_id: StringName = &"",
|
||||
actor_id: StringName = &"",
|
||||
action_id: StringName = &"",
|
||||
target: WorldTargetHandle = null,
|
||||
parameters: Dictionary = {}
|
||||
) -> void:
|
||||
_command_id = command_id
|
||||
_actor_id = actor_id
|
||||
_action_id = action_id
|
||||
_target = target
|
||||
_parameters = parameters.duplicate(true)
|
||||
|
||||
|
||||
func is_valid() -> bool:
|
||||
return (
|
||||
not _command_id.is_empty()
|
||||
and not _actor_id.is_empty()
|
||||
and not _action_id.is_empty()
|
||||
and _target != null
|
||||
and _target.is_well_formed()
|
||||
and not WorldTargetCapability._contains_object(_parameters)
|
||||
)
|
||||
|
||||
|
||||
func get_command_id() -> StringName:
|
||||
return _command_id
|
||||
|
||||
|
||||
func get_actor_id() -> StringName:
|
||||
return _actor_id
|
||||
|
||||
|
||||
func get_action_id() -> StringName:
|
||||
return _action_id
|
||||
|
||||
|
||||
func get_target() -> WorldTargetHandle:
|
||||
return _target
|
||||
|
||||
|
||||
func get_parameters() -> Dictionary:
|
||||
return _parameters.duplicate(true)
|
||||
@@ -0,0 +1 @@
|
||||
uid://doxwel0w8eqx5
|
||||
@@ -0,0 +1,10 @@
|
||||
class_name ActionCommandService
|
||||
extends RefCounted
|
||||
|
||||
signal command_resolved(result: ActionResult)
|
||||
|
||||
|
||||
# Implementations must resolve the transient target handle and revalidate every
|
||||
# precondition. An earlier ActionOffer never grants authority by itself.
|
||||
func submit_command(_command: ActionCommand) -> ActionResult:
|
||||
return null
|
||||
@@ -0,0 +1 @@
|
||||
uid://dfbj1brsbira5
|
||||
@@ -0,0 +1,74 @@
|
||||
class_name ActionOffer
|
||||
extends RefCounted
|
||||
|
||||
var _offer_id: StringName
|
||||
var _action_id: StringName
|
||||
var _target: WorldTargetHandle
|
||||
var _display_name: String
|
||||
var _enabled: bool
|
||||
var _rejection_reason: String
|
||||
var _parameters: Dictionary
|
||||
var _priority: float
|
||||
|
||||
|
||||
func _init(
|
||||
offer_id: StringName = &"",
|
||||
action_id: StringName = &"",
|
||||
target: WorldTargetHandle = null,
|
||||
display_name: String = "",
|
||||
enabled: bool = true,
|
||||
rejection_reason: String = "",
|
||||
parameters: Dictionary = {},
|
||||
priority: float = 0.0
|
||||
) -> void:
|
||||
_offer_id = offer_id
|
||||
_action_id = action_id
|
||||
_target = target
|
||||
_display_name = display_name
|
||||
_enabled = enabled
|
||||
_rejection_reason = rejection_reason
|
||||
_parameters = parameters.duplicate(true)
|
||||
_priority = priority
|
||||
|
||||
|
||||
func is_valid() -> bool:
|
||||
return (
|
||||
not _offer_id.is_empty()
|
||||
and not _action_id.is_empty()
|
||||
and _target != null
|
||||
and _target.is_well_formed()
|
||||
and is_finite(_priority)
|
||||
and not WorldTargetCapability._contains_object(_parameters)
|
||||
)
|
||||
|
||||
|
||||
func get_offer_id() -> StringName:
|
||||
return _offer_id
|
||||
|
||||
|
||||
func get_action_id() -> StringName:
|
||||
return _action_id
|
||||
|
||||
|
||||
func get_target() -> WorldTargetHandle:
|
||||
return _target
|
||||
|
||||
|
||||
func get_display_name() -> String:
|
||||
return _display_name
|
||||
|
||||
|
||||
func is_enabled() -> bool:
|
||||
return _enabled
|
||||
|
||||
|
||||
func get_rejection_reason() -> String:
|
||||
return _rejection_reason
|
||||
|
||||
|
||||
func get_parameters() -> Dictionary:
|
||||
return _parameters.duplicate(true)
|
||||
|
||||
|
||||
func get_priority() -> float:
|
||||
return _priority
|
||||
@@ -0,0 +1 @@
|
||||
uid://c34gchiomlnpy
|
||||
@@ -0,0 +1,88 @@
|
||||
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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bs85tiv8cs3gi
|
||||
@@ -0,0 +1,8 @@
|
||||
class_name InteractionService
|
||||
extends RefCounted
|
||||
|
||||
|
||||
# Offers are advisory presentation values. Implementations must not mutate
|
||||
# authoritative state while answering this query.
|
||||
func get_action_offers(_actor_id: StringName, _target: WorldTargetHandle) -> Array[ActionOffer]:
|
||||
return []
|
||||
@@ -0,0 +1 @@
|
||||
uid://bgd28t7y4x3mf
|
||||
Reference in New Issue
Block a user