generate helpful labels for maps

This commit is contained in:
Bryan Bishop 2012-05-17 00:40:40 -05:00
parent a049ef74f8
commit 979b376741
1 changed files with 34 additions and 19 deletions

View File

@ -4026,11 +4026,14 @@ class MapHeader:
self.dependencies = None self.dependencies = None
if not label: if not label:
label = self.base_label + hex(address) label = self.base_label + hex(address)
self.label = Label(name=label, address=address, object=self) self.label = Label(address=address, object=self)
self.last_address = address + 9 self.last_address = address + 9
script_parse_table[address : self.last_address] = self script_parse_table[address : self.last_address] = self
self.parse() self.parse()
def make_label(self):
return map_names[self.map_group][self.map_id]["label"] + "_MapHeader"
def parse(self): def parse(self):
address = self.address address = self.address
print "parsing a MapHeader at " + hex(address) print "parsing a MapHeader at " + hex(address)
@ -4121,12 +4124,15 @@ class SecondMapHeader:
self.dependencies = None self.dependencies = None
if not label: if not label:
label = self.base_label + hex(address) label = self.base_label + hex(address)
self.label = Label(name=label, address=address, object=self) self.label = Label(address=address, object=self)
self.last_address = address+12 self.last_address = address+12
#i think it's always a static size? #i think it's always a static size?
script_parse_table[address : self.last_address] = self script_parse_table[address : self.last_address] = self
self.parse() self.parse()
def make_label(self):
return map_names[self.map_group][self.map_id]["label"] + "_SecondMapHeader"
def parse(self): def parse(self):
address = self.address address = self.address
bytes = rom_interval(address, second_map_header_byte_size, strings=False) bytes = rom_interval(address, second_map_header_byte_size, strings=False)
@ -4272,11 +4278,14 @@ class MapBlockData:
raise Exception, "MapBlockData needs to know the width/height of its map" raise Exception, "MapBlockData needs to know the width/height of its map"
if not label: if not label:
label = self.base_label + hex(address) label = self.base_label + hex(address)
self.label = Label(name=label, address=address, object=self) self.label = Label(address=address, object=self)
self.last_address = self.address + (self.width.byte * self.height.byte) self.last_address = self.address + (self.width.byte * self.height.byte)
script_parse_table[address : self.last_address] = self script_parse_table[address : self.last_address] = self
self.parse() self.parse()
def make_label(self):
return map_names[self.map_group][self.map_id]["label"] + "_BlockData"
def save_to_file(self): def save_to_file(self):
#check if the file exists already #check if the file exists already
map_path = self.map_path map_path = self.map_path
@ -4310,10 +4319,13 @@ class MapEventHeader:
self.dependencies = None self.dependencies = None
if not label: if not label:
label = self.base_label + hex(address) label = self.base_label + hex(address)
self.label = Label(name=label, address=address, object=self) self.label = Label(address=address, object=self)
self.parse() self.parse()
script_parse_table[address : self.last_address] = self script_parse_table[address : self.last_address] = self
def make_label(self):
return map_names[self.map_group][self.map_id]["label"] + "_MapEventHeader"
def parse(self): def parse(self):
map_group, map_id, debug = self.map_group, self.map_id, self.debug map_group, map_id, debug = self.map_group, self.map_id, self.debug
address = self.address address = self.address
@ -4533,10 +4545,13 @@ class MapScriptHeader:
self.dependencies = None self.dependencies = None
if not label: if not label:
label = self.base_label + hex(address) label = self.base_label + hex(address)
self.label = Label(name=label, address=address, object=self) self.label = Label(address=address, object=self)
self.parse() self.parse()
script_parse_table[address : self.last_address] = self script_parse_table[address : self.last_address] = self
def make_label(self):
return map_names[self.map_group][self.map_id]["label"] + "_MapScriptHeader"
def parse(self): def parse(self):
address = self.address address = self.address
map_group = self.map_group map_group = self.map_group
@ -6177,11 +6192,10 @@ class Label:
been previously written to file. been previously written to file.
""" """
def __init__(self, name=None, address=None, line_number=None, object=None, is_in_file=None, address_is_in_file=None, add_to_globals=True): def __init__(self, name=None, address=None, line_number=None, object=None, is_in_file=None, address_is_in_file=None, add_to_globals=True):
assert name!=None, "need a name" assert address != None, "need an address"
assert address!=None, "need an address"
assert is_valid_address(address), "address must be valid" assert is_valid_address(address), "address must be valid"
assert object != None, "need an object to relate with"
self.name = name
self.address = address self.address = address
self.object = object self.object = object
@ -6193,22 +6207,16 @@ class Label:
# -- better. # -- better.
# #
# check if the label is in the file already # check if the label is in the file already
#self.is_in_file = is_in_file
#if is_in_file == None:
# self.old_check_is_in_file()
#
# check if the address of this label is already in use # check if the address of this label is already in use
#self.address_is_in_file = address_is_in_file
#if address_is_in_file == None:
# self.old_check_address_is_in_file()
self.is_in_file = is_in_file self.is_in_file = is_in_file
#if is_in_file == None and add_to_globals:
# self.check_is_in_file()
self.address_is_in_file = address_is_in_file self.address_is_in_file = address_is_in_file
#if address_is_in_file == None and add_to_globals:
# self.check_address_is_in_file() if name == None:
name = object.base_label + "_" + hex(object.address)
self.name = name
if add_to_globals: if add_to_globals:
all_new_labels.append(self) all_new_labels.append(self)
@ -6279,6 +6287,13 @@ class Label:
else: else:
return False return False
def make_label(self):
""" Generates a label name based on parents and self.object.
"""
object = self.object
name = object.make_label()
return name
def line_has_comment_address(line, returnable={}, bank=None): def line_has_comment_address(line, returnable={}, bank=None):
"""checks that a given line has a comment """checks that a given line has a comment
with a valid address, and returns the address in the object. with a valid address, and returns the address in the object.