Skip to content

Commit

Permalink
Change pyboy.cartridge_title() to property
Browse files Browse the repository at this point in the history
  • Loading branch information
Baekalfen committed Jan 4, 2024
1 parent 42a7ab6 commit 7dcf388
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyboy/plugins/base_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __init__(self, *args, game_area_section=(0, 0, 32, 32), game_area_wrap_aroun
self._cached_game_area_tiles = memoryview(self._cached_game_area_tiles_raw).cast("I", shape=(width, height))

def enabled(self):
return self.cartridge_title is None or self.pyboy.cartridge_title() == self.cartridge_title
return self.cartridge_title is None or self.pyboy.cartridge_title == self.cartridge_title

def post_tick(self):
raise NotImplementedError("post_tick not implemented in game wrapper")
Expand Down
2 changes: 1 addition & 1 deletion pyboy/plugins/game_wrapper_pokemon_gen1.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs):
self.sprite_offset = 0x1000

def enabled(self):
return (self.pyboy.cartridge_title() == "POKEMON RED") or (self.pyboy.cartridge_title() == "POKEMON BLUE")
return (self.pyboy.cartridge_title == "POKEMON RED") or (self.pyboy.cartridge_title == "POKEMON BLUE")

def post_tick(self):
self._tile_cache_invalid = True
Expand Down
2 changes: 1 addition & 1 deletion pyboy/plugins/screen_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def save(self, path=None, fps=60):
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.pyboy.cartridge_title()}-%Y.%m.%d-%H.%M.%S.gif"))
path = os.path.join(directory, time.strftime(f"{self.pyboy.cartridge_title}-%Y.%m.%d-%H.%M.%S.gif"))

if len(self.frames) > 0:
self.frames[0].save(
Expand Down
2 changes: 1 addition & 1 deletion pyboy/plugins/screenshot_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def save(self, path=None):
directory = os.path.join(os.path.curdir, "screenshots")
if not os.path.exists(directory):
os.makedirs(directory, mode=0o755)
path = os.path.join(directory, time.strftime(f"{self.pyboy.cartridge_title()}-%Y.%m.%d-%H.%M.%S.png"))
path = os.path.join(directory, time.strftime(f"{self.pyboy.cartridge_title}-%Y.%m.%d-%H.%M.%S.png"))

self.pyboy.screen.image.save(path)

Expand Down
1 change: 1 addition & 0 deletions pyboy/pyboy.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cdef class PyBoy:
cdef readonly TileMap tilemap_window
cdef readonly object game_wrapper
cdef readonly MemoryScanner memory_scanner
cdef readonly str cartridge_title

cdef bint limit_emulationspeed
cdef int emulationspeed, target_emulationspeed, save_target_emulationspeed
Expand Down
23 changes: 11 additions & 12 deletions pyboy/pyboy.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ def __init__(
Object for handling plugins in PyBoy
"""

self.cartridge_title = self.mb.cartridge.gamename
"""
The title stored on the currently loaded cartridge ROM. The title is all upper-case ASCII and may
have been truncated to 11 characters.
Returns
-------
str :
Game title
"""

self.game_wrapper = self._plugin_manager.gamewrapper()
"""
Provides an instance of a game-specific or generic wrapper. The game is detected by the cartridge's hard-coded
Expand Down Expand Up @@ -627,18 +638,6 @@ def set_emulation_speed(self, target_speed):
logger.warning("The emulation speed might not be accurate when speed-target is higher than 5")
self.target_emulationspeed = target_speed

def cartridge_title(self):
"""
Get the title stored on the currently loaded cartridge ROM. The title is all upper-case ASCII and may
have been truncated to 11 characters.
Returns
-------
str :
Game title
"""
return self.mb.cartridge.gamename

def __rendering(self, value):
"""
Disable or enable rendering
Expand Down
4 changes: 2 additions & 2 deletions tests/test_game_wrapper_mario.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def test_mario_basics(supermarioland_rom):
pyboy = PyBoy(supermarioland_rom, window_type="null")
pyboy.set_emulation_speed(0)
assert pyboy.cartridge_title() == "SUPER MARIOLAN"
assert pyboy.cartridge_title == "SUPER MARIOLAN"

mario = pyboy.game_wrapper
mario.start_game(world_level=(1, 1))
Expand All @@ -35,7 +35,7 @@ def test_mario_basics(supermarioland_rom):
def test_mario_advanced(supermarioland_rom):
pyboy = PyBoy(supermarioland_rom, window_type="null")
pyboy.set_emulation_speed(0)
assert pyboy.cartridge_title() == "SUPER MARIOLAN"
assert pyboy.cartridge_title == "SUPER MARIOLAN"

mario = pyboy.game_wrapper
mario.start_game(world_level=(3, 2))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def replay(
recording ^= True

if gif_destination:
move_gif(pyboy.cartridge_title(), gif_destination)
move_gif(pyboy.cartridge_title, gif_destination)
if gif_hash is not None and not overwrite and sys.platform == "darwin":
verify_file_hash(gif_destination, gif_hash)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def test_load_save_consistency(tetris_rom):
pyboy = PyBoy(tetris_rom, window_type="null")
assert pyboy.cartridge_title() == "TETRIS"
assert pyboy.cartridge_title == "TETRIS"
pyboy.set_emulation_speed(0)
pyboy.memory[NEXT_TETROMINO_ADDR]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tetris_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def eval_network(epoch, child_index, child_model, record_to):
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"{pyboy.cartridge_title()}-%Y.%m.%d-%H.%M.%S.gif"))
path = os.path.join(directory, time.strftime(f"{pyboy.cartridge_title}-%Y.%m.%d-%H.%M.%S.gif"))
frames[0].save(
path,
Expand Down

0 comments on commit 7dcf388

Please sign in to comment.