summaryrefslogtreecommitdiff
path: root/asciifarm/client
diff options
context:
space:
mode:
Diffstat (limited to 'asciifarm/client')
-rw-r--r--asciifarm/client/loaders.py44
-rw-r--r--asciifarm/client/main.py7
-rw-r--r--asciifarm/client/paths.py6
3 files changed, 52 insertions, 5 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"])
diff --git a/asciifarm/client/main.py b/asciifarm/client/main.py
index da556ef..459bb21 100644
--- a/asciifarm/client/main.py
+++ b/asciifarm/client/main.py
@@ -8,11 +8,8 @@ import os
import os.path
from .start import main as clientmain
+from .paths import keybindingsPath, charmapPath
-thisPath = os.path.dirname(__file__)
-farmsPath = os.path.join(thisPath, "..")
-charMapPath = os.path.join(farmsPath, "charmaps")
-keybindingsPath = os.path.join(farmsPath, "keybindings")
standardCharFiles = [name[:-5] for name in os.listdir(charMapPath) if name[-5:] == ".json"]
standardKeyFiles = [name[:-5] for name in os.listdir(keybindingsPath) if name[-5:] == ".json"]
@@ -35,7 +32,7 @@ def main(argv=None):
parser.add_argument('-n', '--name', help='Your player name (must be unique!). Defaults to username on inet sockets and tildename on (unix socket (including abstract)', default=None)
parser.add_argument("-a", "--address", help="The address of the socket. When the socket type is 'abstract' this is just a name. When it is 'unix' this is a filename. When it is 'inet' is should be in the format 'address:port', eg 'localhost:8080'. Defaults depends on the socket type")
parser.add_argument("-s", "--socket", help="the socket type. 'unix' is unix domain sockets, 'abstract' is abstract unix domain sockets and 'inet' is inet sockets. ", choices=["abstract", "unix", "inet"], default="abstract")
- parser.add_argument('-k', '--keybindings', help='The file with the keybinding configuration. This file is a JSON file.', default="keybindings")
+ parser.add_argument('-k', '--keybindings', help='The file with the keybinding configuration. This file is a JSON file.', default="default")
parser.add_argument('-c', '--characters', help='The file with the character mappings for the graphics. If it is either of these names: {} it will be loaded from the charmaps directory.'.format(standardCharFiles), default="default")
parser.add_argument('-o', '--logfile', help='All game messages will be written to this file.'.format(standardCharFiles), default=None)
diff --git a/asciifarm/client/paths.py b/asciifarm/client/paths.py
new file mode 100644
index 0000000..46a1a62
--- /dev/null
+++ b/asciifarm/client/paths.py
@@ -0,0 +1,6 @@
+
+
+clientPath = os.path.dirname(__file__)
+farmsPath = os.path.join(clientPath, "..")
+charMapPath = os.path.join(farmsPath, "charmaps")
+keybindingsPath = os.path.join(farmsPath, "keybindings")