gb-tarot/misc.py

45 lines
1.6 KiB
Python

def splitfour(the_string):
""" takes a block of sprites output by gb-export.lua from aseprite.
divides it into four line-by-line and returns them as separate sprite maps.
if you arranged your sprites horizontally, this divides them up."""
out = ["", "", "", ""]
for l in the_string.split("\n"):
sub = list(l.strip()[3:].split(","))
length = len(sub)
out[0] += "db " + ", ".join(sub[0:length//4]) + "\n"
out[1] += "db " + ", ".join(sub[length//4 : length//2]) + "\n"
out[2] += "db " + ", ".join(sub[length//2 : 3*length//4]) + "\n"
out[3] += "db " + ", ".join(sub[3*length//4 : length]) + "\n"
for d in out:
print(d)
return out
def splitn(n, the_string):
""" takes a block of sprites output by gb-export.lua from aseprite.
divides it into n line-by-line and returns them as separate sprite maps.
if you arranged your sprites horizontally, this divides them up."""
out = ["" for _ in range(n)]
for l in the_string.split("\n"):
sub = list(l.strip()[3:].split(", "))
length = len(sub)
for i in range(n):
out[i] += "db " + ", ".join(sub[(i*length)//n:((i+1)*length)//n]) + "\n"
for d in out:
print(d)
return out
def transpose_gb_tiles(the_string):
out = [[] for _ in range(max(map(lambda l: len(l.split(", ")), the_string.split("\n"))))]
for l in the_string.split("\n"):
sub = list(l.strip()[3:].split(", "))
for i, byte in enumerate(sub):
out[i].append(byte)
for d in out:
print("db " + ", ".join(d))
return out