summaryrefslogtreecommitdiff
path: root/pokemontools/map_editor.py
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2013-09-26 02:26:09 -0400
committeryenatch <yenatch@gmail.com>2013-09-26 02:27:01 -0400
commit96574a08ee25c6118d4e1e5cb8ff334b118817f2 (patch)
tree5aa25d9e0ba16af20d270a7b5ae153512a4833f8 /pokemontools/map_editor.py
parent5f0bd7a2fefbb9354301a3926b011d055e650c56 (diff)
map_editor: more flexible macro handling
makes less assumptions about the structure of a header
Diffstat (limited to 'pokemontools/map_editor.py')
-rw-r--r--pokemontools/map_editor.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/pokemontools/map_editor.py b/pokemontools/map_editor.py
index 9cd29ea..0a02cb0 100644
--- a/pokemontools/map_editor.py
+++ b/pokemontools/map_editor.py
@@ -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: