-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_tilesets.py
47 lines (38 loc) · 1.35 KB
/
convert_tilesets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python3
from sys import argv
import os, subprocess, struct
NUM_TILES_IN_PRIMARY = 640
NUM_TILES_TOTAL = 1024
NUM_METATILES_IN_PRIMARY = 640
NUM_METATILES_TOTAL = 1024
def create_new_behavior(path):
file = path + '/metatile_attributes.bin'
num = int(os.path.getsize(file) / 4)
with open(file, 'rb') as f:
new_data = bytearray(num * 2)
data = f.read(num * 4)
for i in range(0, num):
behavior = data[i * 4]
new_data[i * 2] = behavior
bg = data[i * 4 + 3]
if bg & 0x20 == 0x20:
bg = 0x10
new_data[i * 2 + 1] = bg
with open(os.sep.join([path, 'metatile_attributes_new.bin']), 'wb+') as f:
f.write(new_data)
# copy fire red tilesets over
if not os.path.isdir('data/tilesets/secondary/berry_forest/'):
path = '../../firered/pokefirered/data/tilesets/secondary'
dirs = os.listdir(path)
for dir in dirs:
if os.path.isfile(path + '/' + dir + '/tiles.png'):
str = 'cp -a ' + path + '/' + dir + ' ../../emerald/pokeemerald/data/tilesets/secondary/.';
print(str)
os.system(str)
# convert metatile attributes
path = './data/tilesets/secondary/'
dirs = os.listdir(path)
for i in dirs:
if os.path.isfile(path + i + '/tiles.png'):
print('create_new_behavior(' + path + i + '/)')
create_new_behavior(path + i)