added some debugging tools
This commit is contained in:
51
tools.py
51
tools.py
@@ -0,0 +1,51 @@
|
||||
import pygame as pg
|
||||
from queue import Queue
|
||||
|
||||
|
||||
def _debug(fn):
|
||||
def wrapper(self: 'Debug', *args, **kwargs):
|
||||
if not self.enabled: return
|
||||
fn(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
class Debug:
|
||||
|
||||
def __init__(self, enabled=False):
|
||||
self.enabled = enabled
|
||||
self._screen = None
|
||||
self._debug_queue = Queue()
|
||||
|
||||
|
||||
def debug(self):
|
||||
while not self._debug_queue.empty():
|
||||
self._debug_queue.get()()
|
||||
|
||||
@_debug
|
||||
def draw_lines(self, points) -> None:
|
||||
def _draw_lines():
|
||||
if len(points) > 1:
|
||||
pg.draw.lines(
|
||||
self._screen,
|
||||
(255,0,255),
|
||||
False,
|
||||
points=points,
|
||||
width=3
|
||||
)
|
||||
for point in points:
|
||||
pg.draw.circle(
|
||||
self._screen,
|
||||
(255,0,255),
|
||||
point,
|
||||
2
|
||||
)
|
||||
if len(points) > 0:
|
||||
pg.draw.circle(
|
||||
self._screen,
|
||||
(255,0,255),
|
||||
points[0],
|
||||
2
|
||||
)
|
||||
self._debug_queue.put(_draw_lines)
|
||||
|
||||
|
||||
debug = Debug()
|
||||
|
||||
Reference in New Issue
Block a user