Animation Manager
src.controller.animation_manager
¶
Animation coordination layer.
The animation manager keeps the association between model units, their rendered animations, their visual effects, and their current facing direction. Controllers and game-loop code use this registry to update or draw units without directly managing individual sprite objects.
The documentation follows Google-style docstrings so tools such as pdoc, Sphinx Napoleon, or MkDocs-based pipelines can expose parameters, return values, and side effects in a consistent HTML API reference.
AnimationManager
¶
Registry that synchronizes units, animations, effects, and orientation.
The manager is used as the bridge between gameplay state and rendered state. It stores one animation and, optionally, one effect per unit name. It also records which direction each unit is facing so sprite flipping remains consistent across movement, attacks, and defenses.
Attributes:
| Name | Type | Description |
|---|---|---|
animations |
dict[str, Animation]
|
Registered unit animations. |
effects |
dict[str, Effect]
|
Registered visual effects. |
heros |
dict[str, Unit]
|
Registered hero models by name. |
orientations |
dict[str, str]
|
Last known rendering orientation by unit name. |
Notes
This class is documented as part of the public project API and is intended to be readable in generated HTML documentation.
Source code in src\controller\animation_manager.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
set_orientation(name, orientation)
¶
Store a unit orientation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Name identifying the asset, unit, competence, or registered resource. |
required | |
orientation
|
Rendering orientation, typically right or left for mirrored sprites. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This method is executed for its side effects. |
Side Effects
Updates the stored orientation for a registered unit.
Source code in src\controller\animation_manager.py
add_animation(name, animation)
¶
Register an animation for a unit name when none exists yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Name identifying the asset, unit, competence, or registered resource. |
required | |
animation
|
Animation
|
Animation instance associated with a unit. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This method is executed for its side effects. |
Side Effects
Adds an animation to the registry when the key is not already present.
Source code in src\controller\animation_manager.py
add_hero(hero)
¶
Register a hero model instance by unit name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hero
|
Unit
|
Unit model instance to register or update. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This method is executed for its side effects. |
Side Effects
Adds or replaces a unit in the hero registry.
Source code in src\controller\animation_manager.py
add_effect(name, effect)
¶
Register a visual effect object for a unit name when none exists yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Name identifying the asset, unit, competence, or registered resource. |
required | |
effect
|
Effect
|
Effect instance associated with a unit or action. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This method is executed for its side effects. |
Side Effects
Adds an effect to the registry when the key is not already present.
Source code in src\controller\animation_manager.py
add_sprite_conf(name, sprite_conf)
¶
Register sprite configuration data for a unit name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Name identifying the asset, unit, competence, or registered resource. |
required | |
sprite_conf
|
SpriteConfig
|
SpriteConfig instance describing frame indexes and effect metadata. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This method is executed for its side effects. |
Side Effects
Adds sprite metadata to the registry.
Source code in src\controller\animation_manager.py
get_animation(name)
¶
Return the animation registered for a unit name, if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Name identifying the asset, unit, competence, or registered resource. |
required |
Returns:
| Type | Description |
|---|---|
Animation
|
Animation | None: Registered animation for the unit name, if available. |
Source code in src\controller\animation_manager.py
get_effect(name)
¶
Return the effect registered for a unit name, if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Name identifying the asset, unit, competence, or registered resource. |
required |
Returns:
| Type | Description |
|---|---|
|
Effect | None: Registered effect matching the requested key, if available. |
Source code in src\controller\animation_manager.py
draw(screen)
¶
Draw all registered unit animations and active effects on the target surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
screen
|
Pygame surface or screen wrapper used as the drawing target. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This method is executed for its side effects. |
Side Effects
Blits animation and effect frames to the target surface.
Source code in src\controller\animation_manager.py
update_animation(hero, state, type)
¶
Synchronize a unit animation with the latest model state and action type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hero
|
Unit model instance to register or update. |
required | |
state
|
Gameplay or animation state to apply. |
required | |
type
|
Action subtype, competence name, or category key used by the caller. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
This method is executed for its side effects. |
Side Effects
Updates animation state and frame selection for one unit.
Source code in src\controller\animation_manager.py
update(hero, state, type, dt, screen)
¶
Update the selected unit animation and its active effect for one frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hero
|
Unit model instance to register or update. |
required | |
state
|
Gameplay or animation state to apply. |
required | |
type
|
Action subtype, competence name, or category key used by the caller. |
required | |
dt
|
Elapsed time since the previous frame, used to advance animations. |
required | |
screen
|
Pygame surface or screen wrapper used as the drawing target. |
required |
Returns:
| Type | Description |
|---|---|
|
bool | None: For animations and effects, indicates completion or active playback; for rendering/update controllers, no explicit value is returned. |
Side Effects
Mutates animation, effect, terrain, and rendering state depending on the object.
Notes
The method is part of the frame loop and is expected to be called repeatedly.