summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2019-01-20 01:19:24 +0100
committertroido <troido@protonmail.com>2019-01-20 01:19:24 +0100
commita12b29852e16854de5d248e5ba7f8a313cf8ff9b (patch)
treefccd8b0f6b2f2624a356b7290d00c4d25beb3286
parentda297170c3c1bbd01458b13a6b0a6212181650e0 (diff)
chat now has colours
-rw-r--r--asciifarm/charmaps/halfwidth.json6
-rw-r--r--asciifarm/client/display/display.py10
-rw-r--r--asciifarm/client/display/health.py11
-rw-r--r--asciifarm/client/display/messages.py17
-rw-r--r--asciifarm/client/gameclient.py6
-rw-r--r--asciifarm/client/loaders.py5
6 files changed, 31 insertions, 24 deletions
diff --git a/asciifarm/charmaps/halfwidth.json b/asciifarm/charmaps/halfwidth.json
index 1620bb5..2dae1c8 100644
--- a/asciifarm/charmaps/halfwidth.json
+++ b/asciifarm/charmaps/halfwidth.json
@@ -50,5 +50,11 @@
"charwidth": 1,
"healthfull": ["#", 7, 2],
"healthempty": ["_", 7, 1],
+ "msgcolours": {
+ "chat": [15,0],
+ "attack": [12,0],
+ "damage": [9,0],
+ "heal": [10,0]
+ },
"alphabet": "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
}
diff --git a/asciifarm/client/display/display.py b/asciifarm/client/display/display.py
index 0660bb9..92136b1 100644
--- a/asciifarm/client/display/display.py
+++ b/asciifarm/client/display/display.py
@@ -57,8 +57,8 @@ class Display:
self.addWidget(Info(), "info")
self.addWidget(Health(
charMap.get("healthfull", ("@",7, 2)),
- charMap.get("healthempty", ("-",7, 1)),
- self.colours),
+ charMap.get("healthempty", ("-",7, 1))
+ ),
"health")
self.addWidget(Inventory("Inventory"), "inventory")
self.addWidget(Inventory("Ground"), "ground")
@@ -67,7 +67,7 @@ class Display:
switcher = Switcher([self.widgets["ground"], self.widgets["inventory"], self.widgets["equipment"]], 1)
self.addWidget(switcher, "switch")
- self.addWidget(Messages(), "msg")
+ self.addWidget(Messages(charMap.get("msgcolours", {})), "msg")
self.addWidget(TextInput(), "textinput")
self.forced = False
@@ -125,8 +125,8 @@ class Display:
self.getWidget("ground").setInventory(items)
- def addMessage(self, message):
- self.getWidget("msg").addMessage(message)
+ def addMessage(self, message, type):
+ self.getWidget("msg").addMessage(message, type)
def scrollBack(self, amount, relative=True):
self.getWidget("msg").scroll(amount, relative)
diff --git a/asciifarm/client/display/health.py b/asciifarm/client/display/health.py
index a8d0823..d42edbf 100644
--- a/asciifarm/client/display/health.py
+++ b/asciifarm/client/display/health.py
@@ -4,11 +4,10 @@ from .widimp import WidImp
class Health(WidImp):
- def __init__(self, char=None, emptyChar=None, colours=False):
+ def __init__(self, char=None, emptyChar=None):
self.char = char or ('@',7,0)
self.emptyChar = emptyChar or ('-',7,0)
self.changed = False
- self.colours = colours
self.health = 0
self.maxHealth = 0
@@ -23,10 +22,6 @@ class Health(WidImp):
barEnd = round(self.health/self.maxHealth * width) if self.maxHealth > 0 else 0
win.erase()
win.addLine((0,0),"Health: {}/{}".format(self.health, self.maxHealth)[:width])
- if self.colours:
- win.addLine((0, 1), self.char[0]*barEnd, self.char[1:])
- win.addLine((barEnd, 1), self.emptyChar[0]*(width-barEnd), self.emptyChar[1:])
- else:
- win.addLine((0, 1), self.char[0]*barEnd)
- win.addLine((barEnd, 1), self.emptyChar[0]*(width-barEnd))
+ win.addLine((0, 1), self.char[0]*barEnd, self.char[1:])
+ win.addLine((barEnd, 1), self.emptyChar[0]*(width-barEnd), self.emptyChar[1:])
win.noutrefresh()
diff --git a/asciifarm/client/display/messages.py b/asciifarm/client/display/messages.py
index 19cbc5d..d551cc2 100644
--- a/asciifarm/client/display/messages.py
+++ b/asciifarm/client/display/messages.py
@@ -5,13 +5,14 @@ from .widimp import WidImp
class Messages(WidImp):
- def __init__(self):
+ def __init__(self, colours):
self.changed = False
self.messages = []
self.scrolledBack = 0
+ self.colours = colours
- def addMessage(self, message):
- self.messages.append(message)
+ def addMessage(self, message, type=None):
+ self.messages.append([message, type])
if self.scrolledBack:
self.scrolledBack += 1
self.change()
@@ -30,8 +31,10 @@ class Messages(WidImp):
return
lines = []
messages = self.messages
- for message in messages:
- lines += textwrap.wrap(message, width)
+ for message, type in messages:
+ colour = self.colours.get(type, (7,0))
+ for line in textwrap.wrap(message, width):
+ lines.append((line, colour))
self.scrolledBack = max(min(self.scrolledBack, len(lines)-height), 0)
moreDown = False
if self.scrolledBack > 0:
@@ -42,10 +45,10 @@ class Messages(WidImp):
moreUp = True
lines = lines[len(lines)-height:]
elif len(lines) < height:
- lines = (height-len(lines)) * [""] + lines
+ lines = (height-len(lines)) * [("",)] + lines
win.erase()
for i, line in enumerate(lines):
- win.addLine((0,i),line)
+ win.addLine((0,i), *line)
if moreUp:
win.addLine((width-1, 0), '-')
if moreDown:
diff --git a/asciifarm/client/gameclient.py b/asciifarm/client/gameclient.py
index 197f6e7..1995a67 100644
--- a/asciifarm/client/gameclient.py
+++ b/asciifarm/client/gameclient.py
@@ -121,13 +121,13 @@ class Client:
self.display.update()
- def log(self, text, typ=None):
+ def log(self, text, type=None):
if not isinstance(text, str):
text = str(text)
- self.display.addMessage(text)
+ self.display.addMessage(text, type)
if self.logFile:
with(open(self.logFile, 'a')) as f:
- f.write(text+'\n')
+ f.write("[{}] {}\n".format(type or "", text))
def command_loop(self):
diff --git a/asciifarm/client/loaders.py b/asciifarm/client/loaders.py
index fef4769..d3d7ed1 100644
--- a/asciifarm/client/loaders.py
+++ b/asciifarm/client/loaders.py
@@ -64,6 +64,7 @@ def loadCharmap(name):
healthfull = None
healthempty = None
alphabet = ""
+ msgcolours = {}
for template in templates:
mapping.update(template.get("mapping", {}))
@@ -73,6 +74,7 @@ def loadCharmap(name):
healthfull = template.get("healthfull", healthfull)
healthempty = template.get("healthempty", healthempty)
alphabet = template.get("alphabet", alphabet)
+ msgcolours.update(template.get("msgcolours", {}))
return {
"mapping": mapping,
"writable": writable,
@@ -80,5 +82,6 @@ def loadCharmap(name):
"charwidth": charwidth,
"healthfull": healthfull,
"healthempty": healthempty,
- "alphabet": alphabet
+ "alphabet": alphabet,
+ "msgcolours": msgcolours
}