Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add "Export Tilemap" Function #81

Open
dannye opened this issue Nov 12, 2023 · 0 comments
Open

[Feature Request] Add "Export Tilemap" Function #81

dannye opened this issue Nov 12, 2023 · 0 comments

Comments

@dannye
Copy link

dannye commented Nov 12, 2023

It would be handy to quickly be able to export a blk file as a tilemap.

Obviously it's not algorithmically challenging, but here's a python script to demonstrate what I mean:

blktotilemap.py
#!/usr/bin/env python

import argparse

if __name__ == "__main__":
	ap = argparse.ArgumentParser(description="Convert blk files to tilemaps")
	ap.add_argument("-b", "--bst", default="gfx/blocksets/overworld.bst", help="blockset to use")
	ap.add_argument("-w", "--width", required=True, help="width of blk file")
	ap.add_argument("blk", help="blk file to convert")
	args = ap.parse_args()

	bst_file = bytearray(open(args.bst, "rb").read())
	num_bst_blocks = len(bst_file) // 16

	blk_file = bytearray(open(args.blk, "rb").read())
	num_blk_blocks = len(blk_file)

	tilemap = bytearray([0 for x in range(num_blk_blocks * 16)])

	width = int(args.width)
	height = num_blk_blocks // width
	for block_y in range(height):
		for block_x in range(width):
			block_index = block_y * width + block_x
			block_id = blk_file[block_index]
			assert block_id < num_bst_blocks
			block_tiles = bst_file[block_id * 16:(block_id + 1) * 16]
			base_y = block_y * 4
			base_x = block_x * 4
			for tile_y in range(4):
				for tile_x in range(4):
					tile_index = (base_y + tile_y) * (width * 4) + (base_x + tile_x)
					tilemap[tile_index] = block_tiles[tile_y * 4 + tile_x]
	out_file = open(args.blk + ".tilemap", "wb")
	out_file.write(tilemap)
	out_file.close()

For example, it turns this blk file:
image

Into this tilemap:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant