diff options
author | xCrystal <rgr.crystal@gmail.com> | 2018-06-12 14:12:32 +0200 |
---|---|---|
committer | xCrystal <rgr.crystal@gmail.com> | 2018-06-12 14:12:32 +0200 |
commit | 9ec77a8f48c6e986e803030ada06da31fae85370 (patch) | |
tree | 3b6e7cb96625d262c6a21509b2cac4e530bfcf6f /tools/configuration.py | |
parent | eb954b0364e04df40c571817cb6092390a7e716f (diff) |
Don't use the extras submodule
Most tools from pokemon-reverse-engineering-tools are meant for pokecrystal or pokered. Having only the subset of required tools without depending on a submodule makes it easier to submit custom changes exclusive poketcg and its structure. For example, the disasm tool can be made to use poketcg rom/sym files by default, read vram and hram as symbols, and can be modified in the future to for example guess text labels in applicable load instructions or to dump poketcg-specific scripts. gfx.py was also added, but without the not required pokecrystal lz (de)compression support
Diffstat (limited to 'tools/configuration.py')
-rw-r--r-- | tools/configuration.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/configuration.py b/tools/configuration.py new file mode 100644 index 0000000..6bdb7e8 --- /dev/null +++ b/tools/configuration.py @@ -0,0 +1,57 @@ +"""
+Configuration
+"""
+
+import os
+
+class ConfigException(Exception):
+ """
+ Configuration error. Maybe a missing config variable.
+ """
+
+class Config(object):
+ """
+ The Config class handles all configuration for pokemontools. Other classes
+ and functions use a Config object to determine where expected files can be
+ located.
+ """
+
+ def __init__(self, **kwargs):
+ """
+ Store all parameters.
+ """
+ self._config = {}
+
+ for (key, value) in kwargs.items():
+ if key not in self.__dict__:
+ self._config[key] = value
+ else:
+ raise ConfigException(
+ "Can't store \"{0}\" in configuration because the key conflicts with an existing property."
+ .format(key)
+ )
+
+ if "path" not in self._config:
+ self._config["path"] = os.getcwd()
+
+ # vba save states go into ./save-states/
+ if "save_state_path" not in self._config:
+ self._config["save_state_path"] = os.path.join(self._config["path"], "save-states/")
+
+ # assume rom is at ./baserom.gbc
+ if "rom" not in self._config:
+ self._config["rom_path"] = os.path.join(self._config["path"], "baserom.gbc")
+
+ def __getattr__(self, key):
+ """
+ Grab the value from the class properties, then check the configuration,
+ and raise an exception if nothing works.
+ """
+ if key in self.__dict__:
+ return self.__dict__[key]
+ elif key in self._config:
+ return self._config[key]
+ else:
+ raise ConfigException(
+ "no config found for \"{0}\"".format(key)
+ )
|