summaryrefslogtreecommitdiff
path: root/pokemontools/labels.py
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2013-12-18 20:20:09 -0600
committerBryan Bishop <kanzure@gmail.com>2013-12-18 20:20:09 -0600
commita07c92d3b38898568077da99ec05a82c69ffcc3c (patch)
tree44c5466fc998a132a358e319a01cd7c3dca954ed /pokemontools/labels.py
parenta077e470b2b24fc00db75aad220cc381f602bb3e (diff)
parentd8f4e687ebc49d4b135f0d8b7f10a643114a0d8a (diff)
Merge branch 'master' into path-finding
Diffstat (limited to 'pokemontools/labels.py')
-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