diff options
author | Bryan Bishop <kanzure@gmail.com> | 2012-05-20 00:02:43 -0500 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2012-05-20 00:02:43 -0500 |
commit | e80e1c420c29b0cd9994319d7bedb50f8dcd7fa3 (patch) | |
tree | aa390c2fb6b337be64b719a8638b96aefb093a27 /crystal.py | |
parent | f367588b42c700fa00655cdc730a84593d6b2b25 (diff) |
make better trainer names
original-commit-id: 6f49b01c4b8ec37f5321dd11835780eaa3211542
Diffstat (limited to 'crystal.py')
-rw-r--r-- | crystal.py | 57 |
1 files changed, 56 insertions, 1 deletions
@@ -16,6 +16,9 @@ try: except ImportError: import unittest +# for capwords +import string + # Check for things we need in unittest. if not hasattr(unittest.TestCase, 'setUpClass'): print "The unittest2 module or Python 2.7 is required to run this script." @@ -1684,7 +1687,8 @@ class PointerParamToItemAndLetter(MultiByteParam): class TrainerIdParam(SingleByteParam): #raise NotImplementedError, bryan_message pass - + #def to_asm(self): + # pass class TrainerGroupParam(SingleByteParam): #raise NotImplementedError, bryan_message @@ -3615,6 +3619,18 @@ class TrainerHeader: else: return self.parent.group_name + "_" + str(self.trainer_id) + def make_constant_name(self): + if hasattr(self, "seed_constant_name"): + seed = self.seed_constant_name + else: + seed = self.name + return string.capwords(seed).\ + replace("@", "").\ + replace(" & ", "AND").\ + replace(" ", "").\ + replace(".", "_").\ + upper() + def get_dependencies(self, recompute=False, global_dependencies=set()): if recompute or self.dependencies == None: self.dependencies = [] @@ -3874,6 +3890,42 @@ def trainer_group_report(): output += "total trainers: " + str(total) return output +def make_trainer_group_name_trainer_ids(debug=True): + """ Edits trainer_group_names and sets the trainer names. + For instance, "AMY & MAY" becomes "AMY_AND_MAY1" and "AMY_AND_MAY2" + + This should only be used after TrainerGroupTable.parse has been called. + """ + assert trainer_group_table != None, "TrainerGroupTable must be called before setting the trainer names" + + if debug: + print "starting to make trainer names and give ids to repeated trainer names" + + i = 1 + for header in trainer_group_table.headers: + trainer_names = [] # (name, trainer_header) + dupes = set() + group_id = i + group_name = header.group_name + for trainer_header in header.individual_trainer_headers: + if trainer_header.name in [x[0] for x in trainer_names]: + dupes.add(trainer_header.name) + trainer_names.append([trainer_header.name, trainer_header]) + + # now fix trainers with duplicate names by appending an id + if len(dupes) > 0: + for dupe in dupes: + culprits = [trainer_header for trainer_header in header.individual_trainer_headers if trainer_header.name == dupe] + for (id, culprit) in enumerate(culprits): + culprit.seed_constant_name = culprit.name.replace("@", "") + str(id+1) + culprit.constant_name = culprit.make_constant_name() + + # now add the trainer names to trainer_group_names + trainer_group_names[i]["trainer_names"] = [theader.make_constant_name() for theader in header.individual_trainer_headers] + + if debug: + print "done improving trainer names" + class PeopleEvent(Command): size = people_event_byte_size macro_name = "person_event" @@ -7959,6 +8011,9 @@ def run_main(): global trainer_group_table trainer_group_table = TrainerGroupTable() + # improve duplicate trainer names + make_trainer_group_name_trainer_ids() + #just a helpful alias main=run_main #when you run the file.. do unit tests |