summaryrefslogtreecommitdiff
path: root/asciifarm/client/loaders.py
blob: e7dac3899d178911cacb3048e108d9f9cd3f4eea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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"])