Implement own main loop

master
LEdoian 3 years ago
parent d16758a5b9
commit b8e6bfcd78

@ -68,3 +68,15 @@ class Visualisation:
def reload(self):
self.mapfile.load()
self.draw()
def run(self, *, refresh=2):
pygame.time.set_timer(pygame.USEREVENT, refresh * 1000)
self.draw()
while True:
ev = pygame.event.wait()
if ev.type == pygame.QUIT or ev.type == pygame.KEYDOWN and ev.key == pygame.K_q:
return
if ev.type in [pygame.VIDEOEXPOSE, pygame.VIDEORESIZE, pygame.USEREVENT]:
self.draw()

@ -31,17 +31,16 @@ def read_mapfile(fn):
class MapFile:
def __init__(self, filename, start=None, end=None):
self.mapfilename = filename
self.start = start
self.start = start if start is not None else 0
self.end = end
def load(self):
self.status, self.blocks, self.comments = read_mapfile(self.mapfilename)
if self.start is not None or self.end is not None:
if self.end is not None: # FIXME: what about only start being set?
self.filter_data()
self.size = max(map(lambda blk: blk[0]+blk[1], self.blocks))
def filter_data(self):
assert self.start is not None and self.end is not None
self.blocks = self.filter_blocks(self.blocks, self.start, self.end)
self.blocks = self.trim_blocks(self.blocks, self.start, self.end)

Loading…
Cancel
Save