VariantXYZ
(Variant Xyz)
February 6, 2025, 10:16pm
8
Lucas Malor:
Can you post the code?
import struct
from ast import literal_eval
from collections import OrderedDict
def merge_dicts(dict_list):
result = OrderedDict()
for dictionary in dict_list:
result.update(dictionary)
return result
def reverse_dict(d):
return dict((v,k) for k,v in d.items())
def bin2txt(bin, tbl):
tilemap = []
for b in bin:
if b in tbl:
tilemap += tbl[b]
else:
tilemap += '\\x{:02x}'.format(b)
This file has been truncated. show original
(no imports here anyway)
MODE_LIT = 0
MODE_REP = 1
MODE_INC = 2
MODE_DEC = 3
def decompress_tilemap(original):
tmap = []
rom = iter(original)
for b in rom:
if b in [0xfc, 0xfd, 0xfe, 0xff]:
tmap.append(b)
else:
command = (b >> 6) & 0b11
count = b & 0b00111111
if command == MODE_LIT:
for i in range(count+1):
tmap.append(next(rom))
elif command == MODE_REP:
byte = next(rom)
for i in range(count+2):
This file has been truncated. show original
Lucas Malor:
You can try to move from shutil import copyfile inside the if os.path.isfile(prebuilt):, and to remove tilesets import, that seems unused. I don’t really know however if there’s a noticeable improvement.
Thanks for noticing this! I forgot I removed the need for the tilesets import and I’ll try moving the shutil bit as well. These are indeed helpful for reducing import times.
Actually, your post reminds me that I can also import the specific definitions from the common functions as well.