Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.sprite = SpriteWindow(
pyboy,
mb,
pyboy_argv,
scale=3,
title="Sprite Data",
width=8 * 10,
height=16 * 4,
pos_x=window_pos,
pos_y=self.spriteview.height * 2 + 68
)
window_pos += (constants.COLS * self.spriteview.scale)
tile_data_width = 16 * 8 # Change the 16 to however wide you want the tile window
tile_data_height = ((constants.TILES * 8) // tile_data_width) * 8
self.tiledata = TileDataWindow(
pyboy,
mb,
pyboy_argv,
scale=3,
title="Tile Data",
width=tile_data_width,
height=tile_data_height,
pos_x=window_pos,
pos_y=0
)
def post_tick(self):
tile_cache0 = self.renderer._tilecache
for t in range(constants.TILES):
xx = (t*8) % self.width
yy = ((t*8) // self.width) * 8
self.copy_tile(tile_cache0, t, xx, yy, self.buf0)
self.draw_overlay()
BaseDebugWindow.post_tick(self)
def post_tick(self):
tile_cache0 = self.renderer._tilecache
# Updating screen buffer by copying tiles from cache
mem_offset = self.tilemap.map_offset - constants.VRAM_OFFSET
for n in range(mem_offset, mem_offset + 0x400):
tile_index = self.mb.lcd.VRAM[n]
# Check the tile source and add offset
# http://problemkaputt.de/pandocs.htm#lcdcontrolregister
# BG & Window Tile Data Select (0=8800-97FF, 1=8000-8FFF)
if self.mb.lcd.LCDC.tiledata_select == 0:
# (x ^ 0x80 - 128) to convert to signed, then add 256 for offset (reduces to + 128)
tile_index = (tile_index ^ 0x80) + 128
tile_column = (n-mem_offset) % 32
tile_row = (n-mem_offset) // 32
self.copy_tile(tile_cache0, tile_index, tile_column * 8, tile_row * 8, self.buf0)
self.draw_overlay()
def handle_events(self, events):
global mark_counter, marked_tiles
# Feed events into the loop
events = BaseDebugWindow.handle_events(self, events)
sprite_height = 16 if self.mb.lcd.LCDC.sprite_height else 8
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 // sprite_height
sprite_identifier = tile_y * (self.width // 8) + tile_x
if sprite_identifier > constants.SPRITES:
# Out of bounds
continue
sprite = Sprite(self.mb, sprite_identifier)
marked_tiles.add(
MarkedTile(
tile_identifier=sprite.tile_identifier,
mark_id="SPRITE",
mark_color=MARK[mark_counter],
sprite_height=sprite_height,
sprite=True,
)
)
mark_counter += 1
mark_counter %= len(MARK)
elif event.mouse_button == 1:
marked_tiles.clear()
def draw_overlay(self):
global marked_tiles
scanlineparameters = self.pyboy.botsupport_manager().screen().tilemap_position_list()
# TODO: Refactor this
# Mark screen area
for y in range(constants.ROWS):
xx = int(scanlineparameters[y][self.scanline_x])
yy = int(scanlineparameters[y][self.scanline_y])
if self.scanline_x == 0: # Background
# Wraps around edges of the screen
if y == 0 or y == constants.ROWS - 1: # Draw top/bottom bar
for x in range(constants.COLS):
self.buf0[(yy+y) % 0xFF][(xx+x) % 0xFF] = COLOR
else: # Draw body
self.buf0[(yy+y) % 0xFF][xx % 0xFF] = COLOR
for x in range(constants.COLS):
self.buf0[(yy+y) % 0xFF][(xx+x) % 0xFF] &= self.color
self.buf0[(yy+y) % 0xFF][(xx + constants.COLS) % 0xFF] = COLOR
else: # Window
# Takes a cut of the screen
xx = -xx
yy = -yy
if yy + y == 0 or y == constants.ROWS - 1: # Draw top/bottom bar
for x in range(constants.COLS):
if 0 <= xx + x < constants.COLS:
self.buf0[yy + y][xx + x] = COLOR
else: # Draw body
height=256,
pos_x=window_pos,
pos_y=0,
window_map=True,
scanline_x=2,
scanline_y=3
)
window_pos += (256 * self.tile2.scale)
self.spriteview = SpriteViewWindow(
pyboy,
mb,
pyboy_argv,
scale=2,
title="Sprite View",
width=constants.COLS,
height=constants.ROWS,
pos_x=window_pos,
pos_y=0
)
self.sprite = SpriteWindow(
pyboy,
mb,
pyboy_argv,
scale=3,
title="Sprite Data",
width=8 * 10,
height=16 * 4,
pos_x=window_pos,
pos_y=self.spriteview.height * 2 + 68
)
for x in range(constants.COLS):
self.buf0[(yy+y) % 0xFF][(xx+x) % 0xFF] &= self.color
self.buf0[(yy+y) % 0xFF][(xx + constants.COLS) % 0xFF] = COLOR
else: # Window
# Takes a cut of the screen
xx = -xx
yy = -yy
if yy + y == 0 or y == constants.ROWS - 1: # Draw top/bottom bar
for x in range(constants.COLS):
if 0 <= xx + x < constants.COLS:
self.buf0[yy + y][xx + x] = COLOR
else: # Draw body
if 0 <= yy + y:
self.buf0[yy + y][max(xx, 0)] = COLOR
for x in range(constants.COLS):
if 0 <= xx + x < constants.COLS:
self.buf0[yy + y][xx + x] &= self.color
self.buf0[yy + y][xx + constants.COLS] = COLOR
# Mark selected tiles
for t, match in zip(
marked_tiles, self.tilemap.search_for_identifiers([m.tile_identifier for m in marked_tiles])
):
for row, column in match:
self.mark_tile(column * 8, row * 8, t.mark_color, 8, 8, True)
if self.hover_x != -1:
self.mark_tile(self.hover_x, self.hover_y, HOVER, 8, 8, True)
def update_title(self):
title = self.base_title
title += " [HIGH MAP 0x9C00-0x9FFF]" if self.tilemap.map_offset == constants.HIGH_TILEMAP else \
" [LOW MAP 0x9800-0x9BFF]"
title += " [HIGH DATA (SIGNED) 0x8800-0x97FF]" if self.tilemap.signed_tile_data else \
" [LOW DATA (UNSIGNED) 0x8000-0x8FFF]"
if self.tilemap._select == "WINDOW":
title += " [Window]"
if self.tilemap._select == "BACKGROUND":
title += " [Background]"
sdl2.SDL_SetWindowTitle(self._window, title.encode("utf8"))