From 0c2489af2c0a38daf9c53c8bc314b075ef7485a5 Mon Sep 17 00:00:00 2001 From: Tom Casavant Date: Wed, 15 May 2024 21:03:33 -0400 Subject: [PATCH] Updated to use v2 methods, simplified inputs to use .button --- gb.py | 53 ++++++++++-------------------------------------- requirements.txt | 9 +++++++- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/gb.py b/gb.py index 4cbf4e0..5eecb94 100644 --- a/gb.py +++ b/gb.py @@ -10,7 +10,7 @@ import numpy as np from moviepy.editor import ImageSequenceClip from PIL import Image -from pyboy import PyBoy, WindowEvent +from pyboy import PyBoy class Gameboy: @@ -144,72 +144,41 @@ def load_rom(self, rom): """Loads the rom into a pyboy object""" return PyBoy( rom, - window_type="SDL2" if self.debug else "headless", - window_scale=3, + window="SDL2" if self.debug else "null", debug=False, - game_wrapper=True, ) def dpad_up(self) -> None: """Presses up on the gameboy""" - self.pyboy.send_input(WindowEvent.PRESS_ARROW_UP) - self.tick(4) - self.pyboy.send_input(WindowEvent.RELEASE_ARROW_UP) + self.pyboy.button('up', 3) def dpad_down(self) -> None: """Presses down on the gameboy""" - self.pyboy.send_input(WindowEvent.PRESS_ARROW_DOWN) - print("down") - self.tick(3) - self.pyboy.send_input(WindowEvent.RELEASE_ARROW_DOWN) - # self.tick() + self.pyboy.button('down', 3) def dpad_right(self) -> None: """Presses right on the gameboy""" - self.pyboy.send_input(WindowEvent.PRESS_ARROW_RIGHT) - print("right") - self.tick(3) - self.pyboy.send_input(WindowEvent.RELEASE_ARROW_RIGHT) - # self.tick() + self.pyboy.button('right', 3) def dpad_left(self) -> None: """Presses left on the gameboy""" - self.pyboy.send_input(WindowEvent.PRESS_ARROW_LEFT) - print("left") - self.tick(3) - self.pyboy.send_input(WindowEvent.RELEASE_ARROW_LEFT) - # self.tick() + self.pyboy.button('left', 3) def a(self) -> None: """Presses a on the gameboy""" - self.pyboy.send_input(WindowEvent.PRESS_BUTTON_A) - print("a") - self.tick(3) - self.pyboy.send_input(WindowEvent.RELEASE_BUTTON_A) - # self.tick() + self.pyboy.button('a', 3) def b(self) -> None: """Presses b on the gameboy""" - self.pyboy.send_input(WindowEvent.PRESS_BUTTON_B) - print("b") - self.tick(3) - self.pyboy.send_input(WindowEvent.RELEASE_BUTTON_B) - # self.tick() + self.pyboy.button('b', 3) def start(self) -> None: """Presses start on the gameboy""" - self.pyboy.send_input(WindowEvent.PRESS_BUTTON_START) - print("start") - self.tick(3) - self.pyboy.send_input(WindowEvent.RELEASE_BUTTON_START) - # self.tick() + self.pyboy.button('start', 3) def select(self) -> None: """Presses select on the gameboy""" - self.pyboy.send_input(WindowEvent.PRESS_BUTTON_SELECT) - print("select") - self.tick(3) - self.pyboy.send_input(WindowEvent.RELEASE_BUTTON_SELECT) + self.pyboy.button('select', 3) def screenshot(self, path="screenshots"): """Takes a screenshot of gameboy screen and saves it to the path""" @@ -230,7 +199,7 @@ def screenshot(self, path="screenshots"): # Save the screenshot with the next available number screenshot_path = os.path.join(screenshot_dir, f"screenshot_{next_number}.png") screenshot_path_full = os.path.join(script_dir, "screenshot.png") - self.pyboy.screen_image().save(screenshot_path_full) + self.pyboy.screen.image.save(screenshot_path_full) # Copy the screenshot to the screenshots directory shutil.copyfile(screenshot_path_full, screenshot_path) return screenshot_path_full diff --git a/requirements.txt b/requirements.txt index 58547df..9305204 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,22 @@ +astroid==3.1.0 blurhash==1.1.4 certifi==2024.2.2 charset-normalizer==3.3.2 decorator==4.4.2 +dill==0.3.8 idna==3.6 imageio==2.34.0 imageio-ffmpeg==0.4.9 +isort==5.13.2 Mastodon.py==1.8.1 +mccabe==0.7.0 moviepy==1.0.3 numpy==1.26.4 pillow==10.2.0 +platformdirs==4.2.1 proglog==0.1.10 -pyboy==1.6.14 +pyboy==2.0.3 +pylint==3.1.0 PySDL2==0.9.16 pysdl2-dll==2.30.0 python-dateutil==2.8.2 @@ -19,5 +25,6 @@ requests==2.31.0 setuptools==69.1.0 six==1.16.0 toml==0.10.2 +tomlkit==0.12.4 tqdm==4.66.2 urllib3==2.2.0