The Command: Sealed Directives
Encapsulate a request as an object, allowing parameterization, queuing, and undoing of actions.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Evocation // Directives
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class_name GameCommand extends RefCounted
func execute() -> void: pass
func undo() -> void: pass
class_name MoveCommand extends GameCommand
var target: Node2D
var direction: Vector2
var previous_pos: Vector2
func _init(t: Node2D, dir: Vector2) -> void:
target = t
direction = dir
func execute() -> void:
previous_pos = target.position
target.position += direction
func undo() -> void:
target.position = previous_pos
The Command pattern captures an intent like a sealed scroll. By transforming logic into instantiated data objects, you can delay execution, sequence a queue of arcane instructions, or reverse time itself through undo operations. It is essential for tactical grids and complex input handling.
Runic Tags:
#godot
#gdscript
#command
#undo
#inputs