EntityComponentMediator ​
Inherits: RefCounted
Internal signal bus for Entity component coordination
Description ​
PURPOSE: The mediator acts as a private communication layer between Entity's internal components (Stats, Effects, Abilities, Equipment, Pets, etc.). Components use the mediator to coordinate with each other without tight coupling.
ARCHITECTURE:
- INTERNAL API: Components access each other via mediator.get_component()
- INTERNAL SIGNALS: Components emit through mediator for inter-component coordination
- PUBLIC API: Entity forwards mediator signals as Entity signals for external systems
DESIGN PATTERN: External Systems (UI/Quests/Audio) → Connect to Entity.signals (public API) → Entity forwards from Mediator.signals → Mediator coordinates Component.signals (internal API)
This separation provides:
- Clean encapsulation of Entity's internal architecture
- Flexibility to refactor components without breaking external code
- Clear boundary between internal coordination and external communication
Variables ​
Entity | entity | |
CombatManager | combat_manager | |
Dictionary | components | {} |
Dictionary | subscriptions | {} |
bool | is_initialized | false |
Methods ​
void | register_component( component_type: String, component: Variant ) |
Variant | get_component( component_type: String ) |
bool | has_component( component_type: String ) |
void | finalize_connections() |
void | subscribe( event_name: String, callback: Callable ) |
void | unsubscribe( event_name: String, callback: Callable ) |
void | emit_event( event_name: String, event_data: Dictionary = {} ) |
void | route_combat_state_changed( in_combat: bool ) |
void | route_damage_dealt( effect: EffectInstance, target: Variant ) |
void | route_kill( target: Entity ) |
void | cleanup() |
Signals ​
damage_taken( amount: float, source: Entity, effect: EffectInstance, damage_type: int ) ​
Combat signals
damage_incoming( amount: float, damage_type: int, source: Entity, effect: EffectInstance ) ​
Emitted before damage lands: the amount, the damage type, the source and the effect.
healing_received( pool_id: int, amount: float, source: Entity, effect: EffectInstance ) ​
Emitted when a pool is healed: the pool, the amount, the source and the effect.
entity_died( entity: Entity ) ​
Emitted when the entity dies.
damage_absorbed_by_pool( pool_id: int, amount: float, damage_type: int, source: Entity, effect: EffectInstance ) ​
Mitigation signals
ability_used( ability_instance: AbilityInstance, target: Variant ) ​
Ability signals
ability_cooldown_started( ability_name: String, duration: float ) ​
Emitted when the cooldown of an ability starts: the ability and how long it lasts.
effect_gained( effect_instance: EffectInstance ) ​
Effect signals
effect_lost( effect_instance: EffectInstance ) ​
Emitted when an effect ends or is removed.
effect_updated( effect_instance: EffectInstance ) ​
Emitted when an effect changes (a new stack, a refreshed duration).
stat_changed( stat_id: int, old_value: float, new_value: float ) ​
State signals
pool_value_changed( pool_id: int, current: float, max_value: float ) ​
Emitted when the value of a pool changes: the pool, the current and the maximum value.
equipment_changed( item: ItemInstance, slot_def: EquipmentSlotDefinition, equipped: bool ) ​
Emitted when an item is equipped or taken off: the item, the slot and whether it was equipped.
combat_state_changed( entity: Entity, in_combat: bool ) ​
Emitted when the entity enters or leaves combat.
immunity_activated( immunity_id: int, duration: float, immunity_type: ImmunityDefinition.ImmunityType, protected_targets: Array[int] ) ​
Immunity signals
immunity_deactivated( immunity_id: int, immunity_type: ImmunityDefinition.ImmunityType, protected_targets: Array[int] ) ​
Emitted when a temporary immunity ends: the immunity, its type and what it protected against.
pet_gained( pet: Pet ) ​
Pet signals
pet_lost( pet: Pet ) ​
Emitted when a pet of the entity is lost.
item_received( item_instance: ItemInstance, slot_index: int ) ​
Inventory component signals - relayed to Entity
item_removed( item_instance: ItemInstance, quantity: int ) ​
Emitted when items leave the bag: the item and how many.
Variable descriptions ​
Entity entity ​
The entity the mediator belongs to.
CombatManager combat_manager ​
The manager of combat of the game.
Dictionary components = ​
The components registered with the mediator, by type.
Dictionary subscriptions = ​
The callbacks subscribed to each event name.
bool is_initialized = false ​
True once the mediator is set up.
Method descriptions ​
void register_component( component_type: String, component: Variant ) ​
Registers a component under its type name.
Variant get_component( component_type: String ) ​
The component of a type, or null.
bool has_component( component_type: String ) ​
Is a component of this type registered?
void finalize_connections() ​
Connects the signals of the components to each other. Called once after every component is registered.
void subscribe( event_name: String, callback: Callable ) ​
Subscribes a callback to an event by name (once: a callback already there is not added again).
void unsubscribe( event_name: String, callback: Callable ) ​
Takes a callback off an event.
void emit_event( event_name: String, event_data: Dictionary = {} ) ​
Calls every callback subscribed to the event with the data.
void route_combat_state_changed( in_combat: bool ) ​
Tells everyone the combat state of the entity changed.
void route_damage_dealt( effect: EffectInstance, target: Variant ) ​
Tells everyone the entity dealt damage to a target.
void route_kill( target: Entity ) ​
Called by the entity when it kills another one.
void cleanup() ​
Forgets every component and subscription (the entity is going away).