class_name ActionEffectCommitResult extends RefCounted var _committed := false var _rolled_back := false var _event_ids: Array[int] = [] var _reason_code: StringName var _message := "" var _reason_trace: Array[StringName] = [] var _valid := false func _init( committed: bool = false, rolled_back: bool = false, event_ids: Array = [], reason_code: StringName = &"", message: String = "", reason_trace: Array = [] ) -> void: _committed = committed _rolled_back = rolled_back _reason_code = reason_code _message = message _valid = true var seen_event_ids := {} for event_id_value in event_ids: if event_id_value is not int or int(event_id_value) < 0: _valid = false continue var event_id := int(event_id_value) if seen_event_ids.has(event_id): _valid = false seen_event_ids[event_id] = true _event_ids.append(event_id) for trace_value in reason_trace: if trace_value is not String and trace_value is not StringName: _valid = false continue var trace_id := StringName(trace_value) if trace_id.is_empty(): _valid = false continue _reason_trace.append(trace_id) if _reason_trace.is_empty(): _valid = false if _committed: _valid = ( _valid and not _rolled_back and not _event_ids.is_empty() and _reason_code.is_empty() and _message.is_empty() ) else: _valid = ( _valid and _rolled_back and _event_ids.is_empty() and not _reason_code.is_empty() and not _message.is_empty() ) static func committed( event_ids: Array, reason_trace: Array = [&"whole_plan_committed"] ) -> ActionEffectCommitResult: return ActionEffectCommitResult.new(true, false, event_ids, &"", "", reason_trace) static func rollback_safe_failure( reason_code: StringName, message: String, reason_trace: Array ) -> ActionEffectCommitResult: return ActionEffectCommitResult.new(false, true, [], reason_code, message, reason_trace) func is_valid() -> bool: return _valid func did_commit() -> bool: return _committed func was_rolled_back() -> bool: return _rolled_back func get_event_ids() -> Array[int]: return _event_ids.duplicate() func get_reason_code() -> StringName: return _reason_code func get_message() -> String: return _message func get_reason_trace() -> Array[StringName]: return _reason_trace.duplicate()