diff options
| author | troido <troido@protonmail.com> | 2019-01-18 13:08:05 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2019-01-18 13:08:05 +0100 |
| commit | acadcfa5e7c22b5767e2ae4541829984b37b416a (patch) | |
| tree | d98bf70d2415d539f58acc7370d716717e54d0bf /asciifarm/client/loaders.py | |
| parent | 77105adc468c8f58f94173e7402ac822817beb6f (diff) | |
use loaders for keybindings and charmaps which allow them to import templates
Diffstat (limited to 'asciifarm/client/loaders.py')
| -rw-r--r-- | asciifarm/client/loaders.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/asciifarm/client/loaders.py b/asciifarm/client/loaders.py new file mode 100644 index 0000000..e7dac38 --- /dev/null +++ b/asciifarm/client/loaders.py @@ -0,0 +1,44 @@ + +import os + +from .paths import keybindingsPath +import json + + +standardKeyFiles = { + "default": os.path.join(keybindingsPath, "keybindings.json"), + "azerty": os.path.join(keybindingsPath, "azerty.json") +} + +def loadKeybindings(name): + fname = None + if name in standardKeyFiles: + fname = standardKeyFiles[name]) + else: + fname = name + with open(fname) as f: + data = json.load(f) + bindings = {} + for template in data.get(templates, []): + if template.partition(os.sep)[0] in {".", ".."}: + template = os.path.relpath(template, fname) + bindings.update(loadKeybindings(template)) + bindings.update(data["actions"]) + return (bindings, data["help"]) + + +def loadCharmap(name): + fname = None + if name in standardKeyFiles: + fname = standardKeyFiles[name]) + else: + fname = name + with open(fname) as f: + data = json.load(f) + bindings = {} + for template in data.get(templates, []): + if template.partition(os.sep)[0] in {".", ".."}: + template = os.path.relpath(template, fname) + bindings.update(loadKeybindings(template)) + bindings.update(data["actions"]) + return (bindings, data["help"]) |
