summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asciifarm/charmaps/default.json40
-rw-r--r--asciifarm/charmaps/fullwidth.json52
-rw-r--r--asciifarm/client/__init__.py1
-rw-r--r--asciifarm/client/client.py17
-rw-r--r--asciifarm/client/display/__init__.py19
-rw-r--r--asciifarm/client/display/colours.py18
-rw-r--r--asciifarm/client/display/fieldpad.py6
-rw-r--r--asciifarm/client/display/healthpad.py6
-rw-r--r--asciifarm/keybindings/default.json3
9 files changed, 97 insertions, 65 deletions
diff --git a/asciifarm/charmaps/default.json b/asciifarm/charmaps/default.json
index 433745d..0ed12a9 100644
--- a/asciifarm/charmaps/default.json
+++ b/asciifarm/charmaps/default.json
@@ -1,31 +1,33 @@
{
"mapping":{
"tree": ["T", 2],
- "wall": ["#", 135],
- "rock": ["X", 8],
- "stone": ["o", 8],
- "pebble": ["*", 8],
+ "wall": ["#", 7, 8],
+ "rock": ["X", 7, 8],
+ "stone": ["o", 7],
+ "pebble": ["*", 7],
"player": ["@", 15],
"ground": [".", 3],
"grass1": [",", 2],
"grass2": ["'", 2],
"grass3": ["`", 10],
- "water": ["~", 70],
- "rabbit": "r",
- "floor": "+",
- "portal": "$",
- "stairdown": ">",
- "stairup": "<",
- "dummy": "d",
- "spikes": "^",
- "goblin": "g",
- "seed": ":",
- "plant": "Y",
- "youngplant": "v",
- "food": "8",
- "troll": "T",
+ "water": ["~", 6, 4],
+ "rabbit": ["r", 15],
+ "floor": [".", 8],
+ "portal": ["$", 5],
+ "stairdown": [">",7],
+ "stairup": ["<",7],
+ "dummy": ["d", 3],
+ "spikes": ["^",7],
+ "goblin": ["g",2],
+ "seed": [":",10],
+ "plant": ["Y",10],
+ "youngplant": ["v",10],
+ "food": ["8",13],
+ "troll": ["T",1],
" ": " "
},
"default": "?",
- "charwidth": 1
+ "charwidth": 1,
+ "healthfull": ["#", 7, 2],
+ "healthempty": ["_", 7, 1]
}
diff --git a/asciifarm/charmaps/fullwidth.json b/asciifarm/charmaps/fullwidth.json
index dc1cec8..bd1590e 100644
--- a/asciifarm/charmaps/fullwidth.json
+++ b/asciifarm/charmaps/fullwidth.json
@@ -1,31 +1,33 @@
{
"mapping":{
- "tree": "T",
- "wall": "#",
- "rock": "X",
- "stone": "o",
- "pebble": "*",
- "player": "@",
- "ground": ".",
- "grass1": ",",
- "grass2": "'",
- "grass3": "`",
- "rabbit": "r",
- "water": "~",
- "floor": "+",
- "portal": "$",
- "stairdown": ">",
- "stairup": "<",
- "dummy": "d",
- "spikes": "^",
- "goblin": "g",
- "seed": ":",
- "plant": "Y",
- "youngplant": "v",
- "food": "8",
- "troll": "T",
+ "tree": ["T",2],
+ "wall": ["#",7,8],
+ "rock": ["X",7,8],
+ "stone": ["o",7],
+ "pebble": ["*",7],
+ "player": ["@",15],
+ "ground": [".",3],
+ "grass1": [",",2],
+ "grass2": ["'",2],
+ "grass3": ["`",10],
+ "rabbit": ["r",15],
+ "water": ["~",6,4],
+ "floor": [".",8],
+ "portal": ["$", 5],
+ "stairdown": [">",7],
+ "stairup": ["<",7],
+ "dummy": ["d",3],
+ "spikes": ["^",7],
+ "goblin": ["g",2],
+ "seed": [":",10],
+ "plant": ["Y",10],
+ "youngplant": ["v",10],
+ "food": ["8",13],
+ "troll": ["T",1],
" ": " "
},
"default": "?",
- "charwidth": 2
+ "charwidth": 2,
+ "healthfull": ["#", 7, 2],
+ "healthemtpy": ["_", 7, 1]
}
diff --git a/asciifarm/client/__init__.py b/asciifarm/client/__init__.py
index 5047151..f2814d7 100644
--- a/asciifarm/client/__init__.py
+++ b/asciifarm/client/__init__.py
@@ -33,6 +33,7 @@ def main(name, socketType, address, keybindings, characters, colours=False):
client.start()
except KeyboardInterrupt:
caught_ctrl_c = True
+ client.keepAlive = False
curses.wrapper(start)
diff --git a/asciifarm/client/client.py b/asciifarm/client/client.py
index 5ad91e0..d6e2595 100644
--- a/asciifarm/client/client.py
+++ b/asciifarm/client/client.py
@@ -24,11 +24,15 @@ class Client:
self.keepalive = True
self.connection = connection
- self.commands = {ord(key): command for key, command in keybindings['input'].items()}
+ self.commands = {}
+ for key, commands in keybindings["input"].items():
+ if isinstance(commands[0], str):
+ commands = [commands]
+ self.commands[ord(key)] = [["input", command] for command in commands]
self.controlsString = "Controls:\n"+'\n'.join(
- chr(key) + ": " + ' '.join(action)
- for key, action in self.commands.items()
+ chr(key) + ": " + ', '.join(' '.join(action[1]) for action in actions)
+ for key, actions in self.commands.items()
if chr(key) in string.printable)
self.display.showInfo(self.controlsString)
@@ -67,6 +71,7 @@ class Client:
field = msg[1]
fieldWidth = field['width']
fieldHeight = field['height']
+ self.display.resizeField((fieldWidth, fieldHeight))
fieldCells = field['field']
mapping = field['mapping']
self.display.drawFieldCells(
@@ -81,7 +86,9 @@ class Client:
self.display.setFieldCenter(msg[1])
if msgType == "health":
- self.display.setHealth(*msg[1])
+ health = msg[1]
+ if health:
+ self.display.setHealth(*health)
if msgType == "inventory":
self.display.setInventory(msg[1])
if msgType == "ground":
@@ -96,7 +103,7 @@ class Client:
if key == 27:
self.keepalive = False
if key in self.commands:
- self.connection.send(json.dumps(["input", self.commands[key]]))
+ self.connection.send(json.dumps(self.commands[key]))
diff --git a/asciifarm/client/display/__init__.py b/asciifarm/client/display/__init__.py
index 80e2904..dc553a8 100644
--- a/asciifarm/client/display/__init__.py
+++ b/asciifarm/client/display/__init__.py
@@ -6,32 +6,33 @@ from .infopad import InfoPad
from .healthpad import HealthPad
from .inventorypad import InventoryPad
from .screen import Screen
+from .colours import Colours
SIDEWIDTH = 20
-HEALTHHEIGHT = 2
-INVENTORYHEIGHT = 12
class Display:
def __init__(self, stdscr, charMap, colours=False):
+ if colours:
+ self.colours = Colours()
+ else:
+ self.colours = None
self.screen = Screen(stdscr)
- self.fieldPad = FieldPad((64, 32), charMap.get("charwidth", 1), colours)
+ self.fieldPad = FieldPad((1, 1), charMap.get("charwidth", 1), self.colours)
self.characters = charMap["mapping"]
self.defaultChar = charMap.get("default", "?")
self.infoPad = InfoPad((100, 100))
- self.healthPad = HealthPad(20, ("@",39), ("-",23), colours)
+ self.healthPad = HealthPad(20,
+ charMap.get("healthfull", ("@",7, 2)),
+ charMap.get("healthempty", ("-",7, 1)),
+ self.colours)
self.inventoryPad = InventoryPad("Inventory", 16)
self.groundPad = InventoryPad("Ground", 8)
self.lastinfostring = None
- self.colours = colours
self.changed = False
- if colours:
- curses.use_default_colors()
- for i in range(0, min(256, curses.COLORS, curses.COLOR_PAIRS)):
- curses.init_pair(i, i%16, i//16)
def resizeField(self, size):
diff --git a/asciifarm/client/display/colours.py b/asciifarm/client/display/colours.py
new file mode 100644
index 0000000..cef2675
--- /dev/null
+++ b/asciifarm/client/display/colours.py
@@ -0,0 +1,18 @@
+
+import curses
+
+class Colours:
+
+ def __init__(self):
+
+ self.colours = min(curses.COLORS, 16)
+ self.pairs = self.colours*self.colours
+
+ curses.use_default_colors()
+ for i in range(0, self.pairs):
+ curses.init_pair(i, i%self.colours, i//self.colours)
+
+ def get(self, fg=0, bg=0):
+ fg %= self.colours
+ bg %= self.colours
+ return curses.color_pair(fg + bg*self.colours)
diff --git a/asciifarm/client/display/fieldpad.py b/asciifarm/client/display/fieldpad.py
index 461cb57..8d177d5 100644
--- a/asciifarm/client/display/fieldpad.py
+++ b/asciifarm/client/display/fieldpad.py
@@ -17,11 +17,11 @@ class FieldPad:
def resize(self, width, height):
self.size = (width, height)
- self.pad.resize(height+1, width*self.charSize1)
+ self.pad.resize(height+1, width*self.charSize+1)
- def changeCell(self, x, y, char, colour=None):
+ def changeCell(self, x, y, char, colour=None, bgcolour=0):
if colour != None and self.colours:
- self.pad.addstr(y, x*self.charSize, char, curses.color_pair(colour))
+ self.pad.addstr(y, x*self.charSize, char, self.colours.get(colour, bgcolour))
else:
self.pad.addstr(y, x*self.charSize, char)
self.changed = True
diff --git a/asciifarm/client/display/healthpad.py b/asciifarm/client/display/healthpad.py
index 64838d3..8c7a9b1 100644
--- a/asciifarm/client/display/healthpad.py
+++ b/asciifarm/client/display/healthpad.py
@@ -3,7 +3,7 @@ import curses
class HealthPad:
- def __init__(self, width=1, char=('@',0), emptyChar=('-',0), colours=False):
+ def __init__(self, width=1, char=('@',7,0), emptyChar=('-',7,0), colours=False):
self.char = char
self.emptyChar = emptyChar
self.pad = curses.newpad(2, width+1)
@@ -17,8 +17,8 @@ class HealthPad:
barEnd = round(health/maxHealth * self.width)
self.pad.addstr(0,0,"Health: {}/{}".format(health, maxHealth)[:self.width])
if self.colours:
- self.pad.addstr(1,0, self.char[0]*barEnd, curses.color_pair(self.char[1]))
- self.pad.addstr(1,barEnd, self.emptyChar[0]*(self.width-barEnd), curses.color_pair(self.emptyChar[1]))
+ self.pad.addstr(1,0, self.char[0]*barEnd, self.colours.get(*self.char[1:]))
+ self.pad.addstr(1,barEnd, self.emptyChar[0]*(self.width-barEnd), self.colours.get(*self.emptyChar[1:]))
else:
self.pad.addstr(1,0, self.char[0]*barEnd)
self.pad.addstr(1,barEnd, self.emptyChar[0]*(self.width-barEnd))
diff --git a/asciifarm/keybindings/default.json b/asciifarm/keybindings/default.json
index f0fdf10..270eaa9 100644
--- a/asciifarm/keybindings/default.json
+++ b/asciifarm/keybindings/default.json
@@ -6,12 +6,13 @@
"a": ["move", "west"],
"e": ["take"],
"q": ["drop"],
+ "f": [["attack"],["attack", "north"],["attack", "south"],["attack", "east"],["attack", "west"]],
"F": ["attack"],
"W": ["attack", "north"],
"S": ["attack", "south"],
"D": ["attack", "east"],
"A": ["attack", "west"],
"E": ["use"],
- "f": ["interact"]
+ "r": ["interact"]
}
}