Stop attempting to download link sprite
Create link sprite from local rom if missing Fixing output_path bugs in the adjuster and sprite display
This commit is contained in:
@@ -27,6 +27,7 @@ def adjust(args):
|
||||
apply_rom_settings(rom, args.heartbeep, args.heartcolor, args.quickswap, args.fastmenu, args.disablemusic,
|
||||
args.sprite, args.ow_palettes, args.uw_palettes, args.reduce_flashing)
|
||||
|
||||
output_path.cached_path = args.outputpath
|
||||
rom.write_to_file(output_path('%s.sfc' % outfilebase))
|
||||
|
||||
logger.info('Done. Enjoy.')
|
||||
|
||||
@@ -18,6 +18,9 @@ Thanks to qadan, cheuer, & compiling
|
||||
* Reduce flashing option added
|
||||
* Sprite author credit added
|
||||
* Ranged Crystal switch rules tweaked
|
||||
* Baserom update: includes Credits Speedup, reduced flashing option, msu resume (but turned off by default)
|
||||
* Create link sprite's zspr from local ROM and no longer attempts to download it from website
|
||||
* Some minor bug fixes
|
||||
* 0.4.0.6
|
||||
* Hints now default to off
|
||||
* The maiden gives you a hint to the attic if you bring her to the unlit boss room
|
||||
|
||||
63
Rom.py
63
Rom.py
@@ -1638,6 +1638,14 @@ def hud_format_text(text):
|
||||
|
||||
def apply_rom_settings(rom, beep, color, quickswap, fastmenu, disable_music, sprite,
|
||||
ow_palettes, uw_palettes, reduce_flashing):
|
||||
|
||||
if not os.path.exists("data/sprites/official/001.link.1.zspr"):
|
||||
dump_zspr(rom.orig_buffer[0x80000:0x87000], rom.orig_buffer[0xdd308:0xdd380],
|
||||
rom.orig_buffer[0xdedf5:0xdedf9], "data/sprites/official/001.link.1.zspr", "Nintendo", "Link")
|
||||
|
||||
# todo: implement a flag for msu resume delay
|
||||
rom.write_bytes(0x18021D, [0, 0]) # default to off for now
|
||||
|
||||
if sprite and not isinstance(sprite, Sprite):
|
||||
sprite = Sprite(sprite) if os.path.isfile(sprite) else get_sprite_from_name(sprite)
|
||||
|
||||
@@ -1736,6 +1744,61 @@ def apply_rom_settings(rom, beep, color, quickswap, fastmenu, disable_music, spr
|
||||
rom.write_crc()
|
||||
|
||||
|
||||
# .zspr file dumping logic copied with permission from SpriteSomething:
|
||||
# https://github.com/Artheau/SpriteSomething/blob/master/source/meta/classes/spritelib.py#L443 (thanks miketrethewey!)
|
||||
def dump_zspr(basesprite, basepalette, baseglove, outfilename, author_name, sprite_name):
|
||||
palettes = basepalette
|
||||
# Add glove data
|
||||
palettes.extend(baseglove)
|
||||
HEADER_STRING = b"ZSPR"
|
||||
VERSION = 0x01
|
||||
SPRITE_TYPE = 0x01 # this format has "1" for the player sprite
|
||||
RESERVED_BYTES = b'\x00\x00\x00\x00\x00\x00'
|
||||
QUAD_BYTE_NULL_CHAR = b'\x00\x00\x00\x00'
|
||||
DOUBLE_BYTE_NULL_CHAR = b'\x00\x00'
|
||||
SINGLE_BYTE_NULL_CHAR = b'\x00'
|
||||
|
||||
write_buffer = bytearray()
|
||||
|
||||
write_buffer.extend(HEADER_STRING)
|
||||
write_buffer.extend(struct.pack('B', VERSION)) # as_u8
|
||||
checksum_start = len(write_buffer)
|
||||
write_buffer.extend(QUAD_BYTE_NULL_CHAR) # checksum
|
||||
sprite_sheet_pointer = len(write_buffer)
|
||||
write_buffer.extend(QUAD_BYTE_NULL_CHAR)
|
||||
write_buffer.extend(struct.pack('<H', len(basesprite))) # as_u16
|
||||
palettes_pointer = len(write_buffer)
|
||||
write_buffer.extend(QUAD_BYTE_NULL_CHAR)
|
||||
write_buffer.extend(struct.pack('<H', len(palettes))) # as_u16
|
||||
write_buffer.extend(struct.pack('<H', SPRITE_TYPE)) # as_u16
|
||||
write_buffer.extend(RESERVED_BYTES)
|
||||
# sprite.name
|
||||
write_buffer.extend(sprite_name.encode('utf-16-le'))
|
||||
write_buffer.extend(DOUBLE_BYTE_NULL_CHAR)
|
||||
# author.name
|
||||
write_buffer.extend(author_name.encode('utf-16-le'))
|
||||
write_buffer.extend(DOUBLE_BYTE_NULL_CHAR)
|
||||
# author.name-short
|
||||
write_buffer.extend(author_name.encode('ascii'))
|
||||
write_buffer.extend(SINGLE_BYTE_NULL_CHAR)
|
||||
write_buffer[sprite_sheet_pointer:sprite_sheet_pointer +
|
||||
4] = struct.pack('<L', len(write_buffer)) # as_u32
|
||||
write_buffer.extend(basesprite)
|
||||
write_buffer[palettes_pointer:palettes_pointer +
|
||||
4] = struct.pack('<L', len(write_buffer)) # as_u32
|
||||
write_buffer.extend(palettes)
|
||||
|
||||
checksum = (sum(write_buffer) + 0xFF + 0xFF) % 0x10000
|
||||
checksum_complement = 0xFFFF - checksum
|
||||
|
||||
write_buffer[checksum_start:checksum_start +
|
||||
2] = struct.pack('<H', checksum) # as_u16
|
||||
write_buffer[checksum_start + 2:checksum_start +
|
||||
4] = struct.pack('<H', checksum_complement) # as_u16
|
||||
|
||||
with open('%s' % outfilename, "wb") as zspr_file:
|
||||
zspr_file.write(write_buffer)
|
||||
|
||||
def write_sprite(rom, sprite):
|
||||
if not sprite.valid:
|
||||
return
|
||||
|
||||
@@ -110,7 +110,7 @@ class SpriteSelector(object):
|
||||
|
||||
sprites = []
|
||||
|
||||
for file in glob(output_path(path)):
|
||||
for file in glob(path):
|
||||
sprites.append(Sprite(file))
|
||||
|
||||
sprites.sort(key=lambda s: str.lower(s.name or "").strip())
|
||||
@@ -161,7 +161,8 @@ class SpriteSelector(object):
|
||||
task.update_status("Determining needed sprites")
|
||||
current_sprites = [os.path.basename(file) for file in glob(os.path.join(self.official_sprite_dir,"*"))]
|
||||
official_sprites = [(sprite['file'], os.path.basename(urlparse(sprite['file']).path)) for sprite in sprites_arr]
|
||||
needed_sprites = [(sprite_url, filename) for (sprite_url, filename) in official_sprites if filename not in current_sprites]
|
||||
needed_sprites = [(sprite_url, filename) for (sprite_url, filename) in official_sprites
|
||||
if filename not in current_sprites and filename != "001.link.1.zspr"]
|
||||
bundled_sprites = [os.path.basename(file) for file in glob(os.path.join(self.unofficial_sprite_dir,"*"))]
|
||||
# todo: eventually use the above list to avoid downloading any sprites that we already have cached in the bundle.
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ def adjust_page(top, parent, settings):
|
||||
guiargs.rom = self.romVar2.get()
|
||||
guiargs.baserom = top.pages["randomizer"].pages["generation"].widgets["rom"].storageVar.get()
|
||||
guiargs.sprite = self.sprite
|
||||
guiargs.outputpath = os.path.dirname(guiargs.rom)
|
||||
try:
|
||||
adjust(args=guiargs)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user