summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2013-12-06 19:44:02 -0500
committeryenatch <yenatch@gmail.com>2013-12-06 19:44:02 -0500
commit05b622e7c019a97bb69007a43de733f64076e59a (patch)
tree0e774364a84a69e481318f72c9b0a0d34fde002a
parent460171a2c52d6fcd591559ab1c5fff09e9bc49cb (diff)
labels: grab labels from a mapfile instead of an old json dump
labels.json had to be deleted manually to be updated, and rgbasm is better at scanning labels anyway
-rw-r--r--pokemontools/labels.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/pokemontools/labels.py b/pokemontools/labels.py
index 96e34b9..87e9990 100644
--- a/pokemontools/labels.py
+++ b/pokemontools/labels.py
@@ -8,33 +8,39 @@ import json
import logging
import pointers
+import sym
class Labels(object):
"""
Store all labels.
"""
- filename = "labels.json"
- def __init__(self, config):
+ def __init__(self, config, filename="pokecrystal.map"):
"""
Setup the instance.
"""
self.config = config
- self.path = os.path.join(self.config.path, Labels.filename)
+ self.filename = filename
+ self.path = os.path.join(self.config.path, self.filename)
def initialize(self):
"""
Handle anything requiring file-loading and such.
"""
+ # Look for a mapfile if it's not given
if not os.path.exists(self.path):
- logging.info(
- "Running crystal.scan_for_predefined_labels to create \"{0}\". Trying.."
- .format(Labels.filename)
- )
- import crystal
- crystal.scan_for_predefined_labels()
+ self.filename = find_mapfile_in_dir(self.config.path)
+ if self.filename == None:
+ raise Exception, "Couldn't find any mapfiles. Run rgblink -m to create a mapfile."
+ self.path = os.path.join(self.config.path, self.filename)
- self.labels = json.read(open(self.path, "r").read())
+ self.labels = sym.read_mapfile(self.path)
+
+def find_mapfile_in_dir(path):
+ for filename in os.listdir(path):
+ if os.path.splitext(filename)[1] == '.map':
+ return filename
+ return None
def remove_quoted_text(line):
"""get rid of content inside quotes