Skip to content

Commit

Permalink
FRLG fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pkmnsnfrn committed Aug 30, 2024
1 parent c9cdebd commit fa003e1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions migration_scripts/1.10/frlg_triple_layer_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,25 @@
if not os.path.exists(metatile_attributes_path):
print(f"[SKIP] {tileset_name} skipped because metatile_attributes.bin was not found.")
continue
if os.path.getsize(metatiles_path) != 4 * os.path.getsize(metatile_attributes_path):
if os.path.getsize(metatiles_path) != 4*os.path.getsize(metatile_attributes_path):
print(f"[SKIP] {tileset_name} skipped because metatiles.bin is not four times the size of metatile_attributes.bin (already converted?)")
continue

layer_types = []
meta_attributes = []
with open(metatile_attributes_path, 'rb') as fileobj:
while (chunk := fileobj.read(2)):
metatile_attribute = struct.unpack('<H', chunk)[0]
meta_attributes.append(metatile_attribute & 0x9FFFFFFF)
layer_types.append((metatile_attribute & layer_type_mask) >> layer_type_shift)
for chunk in iter(lambda: fileobj.read(4), ''):
if chunk == b'':
break
metatile_attribute = struct.unpack('<I', chunk)[0]

i = 0
new_metatile_data = []

with open(metatiles_path, 'rb') as fileobj:
while (chunk := fileobj.read(16)):
for chunk in iter(lambda: fileobj.read(16), ''):
if chunk == b'':
break
metatile_data = struct.unpack('<HHHHHHHH', chunk)
if layer_types[i] == 0:
new_metatile_data += [0]*4
Expand All @@ -71,7 +73,7 @@
i += 1

metatile_buffer = struct.pack(f'<{len(new_metatile_data)}H', *new_metatile_data)
metatile_attribute_buffer = struct.pack(f'<{len(meta_attributes)}H', *meta_attributes)
metatile_attribute_buffer = struct.pack(f'<{len(meta_attributes)}I', *meta_attributes)
with open(metatiles_path, 'wb') as fileobj:
fileobj.write(metatile_buffer)
with open(metatile_attributes_path, 'wb') as fileobj:
Expand Down

0 comments on commit fa003e1

Please sign in to comment.