mirror of
https://github.com/pret/pokemon-reverse-engineering-tools.git
synced 2026-08-22 10:14:06 -05:00
map_editor: more flexible macro handling
makes less assumptions about the structure of a header
This commit is contained in:
@@ -473,7 +473,7 @@ def map_header(name):
|
||||
headers = open(os.path.join(header_dir, 'map_headers.asm'), 'r').read()
|
||||
label = name + '_MapHeader'
|
||||
header = asm_at_label(headers, label)
|
||||
macros = [ 'db', 'dw', 'db' ]
|
||||
macros = [ 'db', 'db', 'db', 'dw', 'db', 'db', 'db', 'db' ]
|
||||
attributes = [
|
||||
'bank',
|
||||
'tileset_id',
|
||||
@@ -499,7 +499,7 @@ def map_header(name):
|
||||
label = headers[i:i+len(lower_label)]
|
||||
|
||||
header = asm_at_label(headers, label)
|
||||
macros = [ 'db', 'db', 'dw', 'db' ]
|
||||
macros = [ 'db', 'db', 'db', 'dw', 'dw', 'dw', 'db' ]
|
||||
attributes = [
|
||||
'tileset_id',
|
||||
'height',
|
||||
@@ -530,7 +530,7 @@ def second_map_header(name):
|
||||
headers = open(os.path.join(header_dir, 'second_map_headers.asm'), 'r').read()
|
||||
label = name + '_SecondMapHeader'
|
||||
header = asm_at_label(headers, label)
|
||||
macros = [ 'db', 'db', 'dbw', 'dbw', 'dw', 'db' ]
|
||||
macros = [ 'db', 'db', 'db', 'db', 'dw', 'db', 'dw', 'dw', 'db' ]
|
||||
attributes = [
|
||||
'border_block',
|
||||
'height',
|
||||
@@ -552,19 +552,21 @@ def second_map_header(name):
|
||||
|
||||
def connections(which_connections, header, l=0):
|
||||
directions = { 'north': {}, 'south': {}, 'west': {}, 'east': {} }
|
||||
macros = [ 'db', 'dw', 'dw', 'db', 'db', 'dw' ]
|
||||
|
||||
if version == 'crystal':
|
||||
macros = [ 'db', 'db' ]
|
||||
attributes = [
|
||||
'map_group',
|
||||
'map_no',
|
||||
]
|
||||
|
||||
elif version == 'red':
|
||||
macros = [ 'db' ]
|
||||
attributes = [
|
||||
'map_id',
|
||||
]
|
||||
|
||||
macros += [ 'dw', 'dw', 'db', 'db', 'db', 'db', 'dw' ]
|
||||
attributes += [
|
||||
'strip_pointer',
|
||||
'strip_destination',
|
||||
@@ -591,8 +593,9 @@ def read_header_macros(header, attributes, macros):
|
||||
l = 0
|
||||
for l, (asm, comment) in enumerate(header):
|
||||
if asm.strip() != '':
|
||||
values += macro_values(asm, macros[i])
|
||||
i += 1
|
||||
mvalues = macro_values(asm, macros[i])
|
||||
values += mvalues
|
||||
i += len(mvalues)
|
||||
if len(values) >= len(attributes):
|
||||
l += 1
|
||||
break
|
||||
@@ -608,7 +611,10 @@ def script_header(asm, name):
|
||||
|
||||
def macro_values(line, macro):
|
||||
values = line[line.find(macro) + len(macro):].split(',')
|
||||
return [v.replace('$','0x').strip() for v in values]
|
||||
values = [v.replace('$','0x').strip() for v in values]
|
||||
if values[0] == 'w': # dbw
|
||||
values = values[1:]
|
||||
return values
|
||||
|
||||
def db_value(line):
|
||||
macro = 'db'
|
||||
@@ -623,8 +629,12 @@ from preprocessor import separate_comment
|
||||
|
||||
def asm_at_label(asm, label):
|
||||
label_def = label + ':'
|
||||
start = asm.find(label_def) + len(label_def)
|
||||
lines = asm[start:].split('\n')
|
||||
lines = asm.split('\n')
|
||||
for line in lines:
|
||||
if line.startswith(label_def):
|
||||
lines = lines[lines.index(line):]
|
||||
lines[0] = lines[0][len(label_def):]
|
||||
break
|
||||
# go until the next label
|
||||
content = []
|
||||
for line in lines:
|
||||
|
||||
Reference in New Issue
Block a user