✨ ARCANUM RUNE DIFFICULTY: Adept Behavioral

The Memento: Temporal Phylactery

Capture and externalize an object's internal state so it can be restored later, without violating encapsulation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Chronomancy // Phylacteries
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class_name PlayerStateMemento extends RefCounted
var health: int
var position: Vector2
func _init(h: int, p: Vector2) -> void:
    health = h
    position = p

class_name PlayerCharacter extends Node2D
var health: int = 100

func create_memento() -> PlayerStateMemento:
    return PlayerStateMemento.new(health, position)

func restore(memento: PlayerStateMemento) -> void:
    health = memento.health
    position = memento.position

The Memento is a Chronomancer’s finest tool. By locking the fragile state of an entity into a sealed Phylactery, one can rewind the flow of battle or manage save-game states effortlessly. The internal mysteries of the object remain private, yet its history is fully preserved.

Runic Tags: #godot #gdscript #memento #save-state #state