summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asciifarm/client/loaders.py72
-rw-r--r--asciifarm/client/main.py27
-rw-r--r--asciifarm/client/paths.py3
3 files changed, 66 insertions, 36 deletions
diff --git a/asciifarm/client/loaders.py b/asciifarm/client/loaders.py
index e7dac38..0b4c5b7 100644
--- a/asciifarm/client/loaders.py
+++ b/asciifarm/client/loaders.py
@@ -1,7 +1,7 @@
import os
-from .paths import keybindingsPath
+from .paths import keybindingsPath, charmapPath
import json
@@ -13,32 +13,70 @@ standardKeyFiles = {
def loadKeybindings(name):
fname = None
if name in standardKeyFiles:
- fname = standardKeyFiles[name])
+ 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"])
+ help = ""
+ for ftemplate in data.get("templates", []):
+ if ftemplate.partition(os.sep)[0] in {".", ".."}:
+ ftemplate = os.path.relpath(ftemplate, fname)
+ template = loadKeyBindings(ftemplate)
+ bindings.update(template.get("actions", {}))
+ help = template.get("help", help)
+ bindings.update(data.get("actions", {}))
+ help = data.get("help", help)
+ return {"actions": bindings, "help": help}
+standardCharFiles = {name, os.path.join(charmapPath, file) for name, file in {
+ "default": "default.json",
+ "fullwith": "fullwidth.json",
+ "fw": "fullwidth.json",
+ "emoji": "emoji.json"
+}.items()}
+
def loadCharmap(name):
fname = None
- if name in standardKeyFiles:
- fname = standardKeyFiles[name])
+ if name in standardCharFiles:
+ fname = standardCharFiles[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"])
+
+ templates = []
+ for ftemplate in data.get("templates", []):
+ if ftemplate.partition(os.sep)[0] in {".", ".."}:
+ ftemplate = os.path.relpath(ftemplate, fname)
+ templates.append(loadCharmap(ftemplate))
+
+ templates.append(data)
+
+ mapping = {}
+ writable = {}
+ default = None
+ charwidth = 1
+ healthfull = None
+ healthempty = None
+ alphabet = ""
+
+ for template in templates:
+ mapping.update(template.get("mapping", {}))
+ writable.update(template.get("writable", {}))
+ default = template.get("default", default)
+ charwidth = template.get("charwidth", charwidth)
+ healthfull = template.get("healthfull", healthfull)
+ healthempty = template.get("healthempty", healthempty)
+ alphabet = template.get("alphabet", alphabet)
+ return {
+ "mapping": mapping,
+ "writable": writable,
+ "default": default,
+ "charwidth": charwidth,
+ "healthfull": healthfull,
+ "healthempty": healthempty,
+ "alphabet": alphabet
+ }
diff --git a/asciifarm/client/main.py b/asciifarm/client/main.py
index 459bb21..45ccda8 100644
--- a/asciifarm/client/main.py
+++ b/asciifarm/client/main.py
@@ -8,11 +8,12 @@ import os
import os.path
from .start import main as clientmain
-from .paths import keybindingsPath, charmapPath
+#from .paths import keybindingsPath, charmapPath
+from . import loaders
-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"]
+#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"]
defaultAdresses = {
@@ -33,8 +34,8 @@ def main(argv=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="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)
+ 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(list(loaders.standardCharFiles.items())), default="default")
+ parser.add_argument('-o', '--logfile', help='All game messages will be written to this file.', default=None)
colourGroup = parser.add_mutually_exclusive_group()
colourGroup.add_argument('-l', '--colours', '--colors', help='enable colours! :)', action="store_true")
@@ -42,19 +43,9 @@ def main(argv=None):
args = parser.parse_args(argv)
+ charmap = loaders.loadCharmap(args.characters)
- charFile = args.characters
- if charFile in standardCharFiles:
- charFile = os.path.join(charMapPath, charFile + ".json")
- with open(charFile, 'r') as cf:
- charMap = json.load(cf)
-
- keyFile = args.keybindings
- if keyFile in standardKeyFiles:
- keyFile = os.path.join(keybindingsPath, keyFile + ".json")
- with open(keyFile, 'r') as kf:
- # todo: support yaml
- keybindings = json.load(kf)
+ keybindings = loaders.loadKeybindings(args.keybindings)
address = args.address
if address is None:
@@ -79,5 +70,5 @@ def main(argv=None):
else:
name = username
- clientmain(name, args.socket, address, keybindings, charMap, colours, args.logfile)
+ clientmain(name, args.socket, address, keybindings, charmap, colours, args.logfile)
diff --git a/asciifarm/client/paths.py b/asciifarm/client/paths.py
index 46a1a62..3042f92 100644
--- a/asciifarm/client/paths.py
+++ b/asciifarm/client/paths.py
@@ -1,6 +1,7 @@
+import os.path
clientPath = os.path.dirname(__file__)
farmsPath = os.path.join(clientPath, "..")
-charMapPath = os.path.join(farmsPath, "charmaps")
+charmapPath = os.path.join(farmsPath, "charmaps")
keybindingsPath = os.path.join(farmsPath, "keybindings")