async def _send_debug(self): """ Sends the debug draw execution. This is run by main.py now automatically, if there is any items in the list. You do not need to run this manually any longer. Check examples/terran/ramp_wall.py for example drawing. Each draw request needs to be sent again in every single on_step iteration. """ debug_hash = ( sum(hash(item) for item in self._debug_texts), sum(hash(item) for item in self._debug_lines), sum(hash(item) for item in self._debug_boxes), sum(hash(item) for item in self._debug_spheres), ) if debug_hash != (0, 0, 0, 0): if debug_hash != self._debug_hash_tuple_last_iteration: # Something has changed, either more or less is to be drawn, or a position of a drawing changed (e.g. when drawing on a moving unit) self._debug_hash_tuple_last_iteration = debug_hash await self._execute( debug=sc_pb.RequestDebug( debug=[ debug_pb.DebugCommand( draw=debug_pb.DebugDraw( text=[text.to_proto() for text in self._debug_texts] if self._debug_texts else None, lines=[line.to_proto() for line in self._debug_lines] if self._debug_lines else None, boxes=[box.to_proto() for box in self._debug_boxes] if self._debug_boxes else None, spheres=[sphere.to_proto() for sphere in self._debug_spheres] if self._debug_spheres else None, ) ) ] ) ) self._debug_draw_last_frame = True self._debug_texts.clear() self._debug_lines.clear() self._debug_boxes.clear() self._debug_spheres.clear() elif self._debug_draw_last_frame: # Clear drawing if we drew last frame but nothing to draw this frame self._debug_hash_tuple_last_iteration = (0, 0, 0, 0) await self._execute( debug=sc_pb.RequestDebug( debug=[ debug_pb.DebugCommand(draw=debug_pb.DebugDraw(text=None, lines=None, boxes=None, spheres=None)) ] ) ) self._debug_draw_last_frame = False
async def debug_text(self, texts: Union[str, list], positions: Union[list, set], color=(0, 255, 0), size_px=16): """ Deprecated, may be removed soon """ if isinstance(positions, (set, list)): if not positions: return if isinstance(texts, str): texts = [texts] * len(positions) assert len(texts) == len(positions) await self._execute(debug=sc_pb.RequestDebug(debug=[ debug_pb.DebugCommand(draw=debug_pb.DebugDraw(text=[ debug_pb.DebugText( text=t, color=debug_pb.Color( r=color[0], g=color[1], b=color[2]), world_pos=common_pb.Point( x=p.x, y=p.y, z=getattr(p, "z", 10)), size=size_px) for t, p in zip(texts, positions) ])) ])) else: await self.debug_text([texts], [positions], color)
async def send_debug(self): """ Sends the debug draw execution. Put this after your debug creation functions. """ await self._execute(debug=sc_pb.RequestDebug( debug=[debug_pb.DebugCommand(draw=debug_pb.DebugDraw( text=self._debug_texts if len(self._debug_texts) > 0 else None, lines=self._debug_lines if len(self._debug_lines) > 0 else None, boxes=self._debug_boxes if len(self._debug_boxes) > 0 else None, spheres=self._debug_spheres if len(self._debug_spheres) > 0 else None ))])) self._debug_texts.clear() self._debug_lines.clear() self._debug_boxes.clear() self._debug_spheres.clear()
async def _send_debug(self): """ Sends the debug draw execution. This is run by main.py now automatically, if there is any items in the list. You do not need to run this manually any longer. """ if self._debug_texts or self._debug_lines or self._debug_boxes or self._debug_spheres: await self._execute(debug=sc_pb.RequestDebug(debug=[ debug_pb.DebugCommand(draw=debug_pb.DebugDraw( text=self._debug_texts if self._debug_texts else None, lines=self._debug_lines if self._debug_lines else None, boxes=self._debug_boxes if self._debug_boxes else None, spheres=self._debug_spheres if self. _debug_spheres else None, )) ])) self._debug_draw_last_frame = True self._debug_texts.clear() self._debug_lines.clear() self._debug_boxes.clear() self._debug_spheres.clear() elif self._debug_draw_last_frame: # Clear drawing if we drew last frame but nothing to draw this frame await self._execute(debug=sc_pb.RequestDebug(debug=[ debug_pb.DebugCommand(draw=debug_pb.DebugDraw( text=None, lines=None, boxes=None, spheres=None)) ])) self._debug_draw_last_frame = False
async def debug_text(self, texts, positions, color=(0, 255, 0)): if isinstance(positions, list): if not positions: return if isinstance(texts, str): texts = [texts] * len(positions) assert len(texts) == len(positions) await self._execute(debug=sc_pb.RequestDebug( debug=[debug_pb.DebugCommand(draw=debug_pb.DebugDraw( text=[debug_pb.DebugText( text=t, color=debug_pb.Color(r=color[0], g=color[1], b=color[2]), world_pos=common_pb.Point(x=p.x, y=p.y, z=p.z) ) for t, p in zip(texts, positions)] ))] )) else: await self.debug_text([texts], [positions], color)