Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle_events(self, events):
global mark_counter, marked_tiles
self.tilemap.refresh_lcdc()
# Feed events into the loop
events = BaseDebugWindow.handle_events(self, events)
for event in events:
if event == WindowEvent._INTERNAL_MOUSE and event.window_id == self.window_id:
if event.mouse_button == 0:
tile_x, tile_y = event.mouse_x // self.scale // 8, event.mouse_y // self.scale // 8
tile_identifier = self.tilemap.tile_identifier(tile_x, tile_y)
logger.info(f"Tile clicked on {tile_x}, {tile_y}")
marked_tiles.add(
MarkedTile(tile_identifier=tile_identifier, mark_id="TILE", mark_color=MARK[mark_counter])
)
mark_counter += 1
mark_counter %= len(MARK)
elif event.mouse_button == 1:
marked_tiles.clear()
elif event == WindowEvent._INTERNAL_MARK_TILE:
marked_tiles.add(event.tile_identifier)
return events
def save(self, path=None, fps=60):
if not Image:
logger.warning("ScreenRecorder: No recording to save. Missing dependency \"Pillow\".")
return
logger.info("ScreenRecorder saving...")
if path is None:
directory = os.path.join(os.path.curdir, "recordings")
if not os.path.exists(directory):
os.makedirs(directory, mode=0o755)
path = os.path.join(directory, time.strftime(f"{self.gamename}-%Y.%m.%d-%H.%M.%S.gif"))
if self.frames:
self.frames[0].save(path, save_all=True, interlace=False,
loop=0, optimize=True,
append_images=self.frames[1:],
duration=int(round(1000 / fps, -1)))
logger.info("Screen recording saved in {}".format(path))
else:
logger.error("Screen recording failed: no frames")
def stop(self, save=True):
"""
Gently stops the emulator and all sub-modules.
Args:
save (bool): Specify whether to save the game upon stopping. It will always be saved in a file next to the
provided game-ROM.
"""
logger.info("###########################")
logger.info("# Emulator is turning off #")
logger.info("###########################")
self.plugin_manager.stop()
self.mb.stop(save)
logger.info("ScreenRecorder saving...")
if path is None:
directory = os.path.join(os.path.curdir, "recordings")
if not os.path.exists(directory):
os.makedirs(directory, mode=0o755)
path = os.path.join(directory, time.strftime(f"{self.gamename}-%Y.%m.%d-%H.%M.%S.gif"))
if self.frames:
self.frames[0].save(path, save_all=True, interlace=False,
loop=0, optimize=True,
append_images=self.frames[1:],
duration=int(round(1000 / fps, -1)))
logger.info("Screen recording saved in {}".format(path))
else:
logger.error("Screen recording failed: no frames")
def handle_events(self, events):
for event in events:
if event == WindowEvent.SCREEN_RECORDING_TOGGLE:
self.recording ^= True
if not self.recording:
self.save()
else:
logger.info("ScreenRecorder started")
break
return events
def set_title(self, title):
if self.enable_title:
logger.info("DummyWindow set title: %s" % title)