Mediator for Sprite Enchantment
Centralize complex communication between disparate enchanted sprites to prevent chaotic magical crossfire.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Mediator
ARCANUM SCHOOL: Illusion // Sprite Enchantment
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
function SpriteNexus() constructor {
sprites = [];
static register = function(_sprite) { array_push(sprites, _sprite); };
static notify = function(_sender, _event) {
if (_event == "explode") {
for (var i = 0; i < array_length(sprites); i++) {
if (sprites[i] != _sender) {
sprites[i].apply_recoil();
}
}
}
};
}
function BoundSprite(_nexus) constructor {
nexus = _nexus;
nexus.register(self);
static explode = function() { nexus.notify(self, "explode"); };
static apply_recoil = function() { /* get pushed back */ };
}
The Mediator avoids the tangled web of dependencies wherein every sprite monitors every other sprite. Instead, they all speak to the Nexus. When one erupts in fiery magic, the Nexus orchestrates the recoil of all surrounding entities seamlessly.
Runic Tags:
#gml
#behavioral
#mediator