@@ -31,6 +31,7 @@ class Bot:
3131 index : int = - 1
3232 name : str = ""
3333 player_id : int = 0
34+ can_render : bool = False
3435
3536 @property
3637 def spawn_id (self ) -> int :
@@ -90,6 +91,9 @@ def __init__(self, default_agent_id: Optional[str] = None):
9091 self ._handle_controllable_team_info
9192 )
9293 self ._game_interface .packet_handlers .append (self ._handle_packet )
94+ self ._game_interface .rendering_status_handlers .append (
95+ self .rendering_status_update
96+ )
9397
9498 self .renderer = Renderer (self ._game_interface )
9599
@@ -103,15 +107,6 @@ def _try_initialize(self):
103107 # Not ready to initialize
104108 return
105109
106- # Search match settings for our name
107- for player in self .match_config .player_configurations :
108- match player .variety .item :
109- case flat .CustomBot (name ):
110- if player .player_id == self .player_id :
111- self .name = name
112- self .logger = get_logger (self .name )
113- break
114-
115110 try :
116111 self .initialize ()
117112 except Exception as e :
@@ -127,6 +122,24 @@ def _try_initialize(self):
127122 def _handle_match_config (self , match_config : flat .MatchConfiguration ):
128123 self .match_config = match_config
129124 self ._has_match_settings = True
125+ self .can_render = (
126+ match_config .enable_rendering == flat .DebugRendering .OnByDefault
127+ )
128+
129+ # Search match settings for our name
130+ for player in self .match_config .player_configurations :
131+ match player .variety .item :
132+ case flat .CustomBot (name ):
133+ if player .player_id == self .player_id :
134+ self .name = name
135+ self .logger = get_logger (self .name )
136+ break
137+ else : # else block runs if break was not hit
138+ self .logger .warning (
139+ "Bot with agent id '%s' did not find itself in the match settings" ,
140+ self ._game_interface .agent_id ,
141+ )
142+
130143 self ._try_initialize ()
131144
132145 def _handle_field_info (self , field_info : flat .FieldInfo ):
@@ -228,6 +241,34 @@ def _handle_match_communication(self, match_comm: flat.MatchComm):
228241 match_comm .team_only ,
229242 )
230243
244+ def rendering_status_update (self , update : flat .RenderingStatus ):
245+ """
246+ Called when the server sends a rendering status update for ANY bot or script.
247+
248+ By default, this will update `self.can_render` if appropriate.
249+ """
250+ if update .is_bot and update .index == self .index :
251+ self .can_render = update .status
252+
253+ def update_rendering_status (
254+ self ,
255+ status : bool ,
256+ index : Optional [int ] = None ,
257+ is_bot : bool = True ,
258+ ):
259+ """
260+ Requests the server to update the status of the ability for this bot to render.
261+ Will be ignored if rendering has been set to AlwaysOff in the match settings.
262+ If the status is successfully updated, the `self.rendering_status_update` method will be called which will update `self.can_render`.
263+
264+ - `status`: `True` to enable rendering, `False` to disable.
265+ - `index`: The index of the bot to update. If `None`, uses the bot's own index.
266+ - `is_bot`: `True` if `index` is a bot index, `False` if it is a script index.
267+ """
268+ self ._game_interface .send_msg (
269+ flat .RenderingStatus (self .index if index is None else index , is_bot , status )
270+ )
271+
231272 def handle_match_comm (
232273 self ,
233274 index : int ,
0 commit comments