colours now work a bit better

This commit is contained in:
troido 2017-10-26 16:30:53 +02:00
parent d2a2e7ce19
commit bcba143581
6 changed files with 26 additions and 54 deletions

View File

@ -1,31 +0,0 @@
{
"mapping":{
"tree": ["T", 2],
"wall": ["#", 8],
"rock": ["X", 8],
"stone": ["o", 8],
"pebble": ["*", 8],
"player": ["@", 15],
"ground": [".", 3],
"grass1": [",", 2],
"grass2": ["'", 2],
"grass3": ["`", 2],
"water": ["~", 12],
"rabbit": "r",
"floor": "+",
"portal": "$",
"stairdown": ">",
"stairup": "<",
"dummy": "d",
"spikes": "^",
"goblin": "g",
"seed": ":",
"plant": "Y",
"youngplant": "v",
"food": "8",
"troll": "T",
" ": " "
},
"default": "?",
"charwidth": 1
}

View File

@ -1,17 +1,17 @@
{
"mapping":{
"tree": "T",
"wall": "#",
"rock": "X",
"stone": "o",
"pebble": "*",
"player": "@",
"ground": ".",
"grass1": ",",
"grass2": "'",
"grass3": "`",
"tree": ["T", 2],
"wall": ["#", 135],
"rock": ["X", 8],
"stone": ["o", 8],
"pebble": ["*", 8],
"player": ["@", 15],
"ground": [".", 3],
"grass1": [",", 2],
"grass2": ["'", 2],
"grass3": ["`", 10],
"water": ["~", 70],
"rabbit": "r",
"water": "~",
"floor": "+",
"portal": "$",
"stairdown": ">",

View File

@ -14,7 +14,7 @@ defaultAdresses = {
"inet": "localhost:9021",
}
def main(name, socketType, address, keybindings, characters):
def main(name, socketType, address, keybindings, characters, colours=False):
connection = Connection(socketType)
try:
@ -26,7 +26,7 @@ def main(name, socketType, address, keybindings, characters):
caught_ctrl_c = False
def start(stdscr):
display = Display(stdscr, characters)
display = Display(stdscr, characters, colours)
client = Client(stdscr, display, name, connection, keybindings)
nonlocal caught_ctrl_c
try:

View File

@ -8,19 +8,20 @@ from .screen import Screen
class Display:
def __init__(self, stdscr, charMap):
def __init__(self, stdscr, charMap, colours=False):
self.screen = Screen(stdscr)
self.fieldPad = FieldPad((64, 32), charMap.get("charwidth", 1))
self.fieldPad = FieldPad((64, 32), charMap.get("charwidth", 1), colours)
self.characters = charMap["mapping"]
self.defaultChar = charMap.get("default", "?")
self.infoPad = InfoPad((100, 100))
self.healthPad = HealthPad((20, 1))
self.lastinfostring = None
curses.use_default_colors()
for i in range(0, curses.COLORS):
curses.init_pair(i+1, i, -1);
self.colours = colours
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):

View File

@ -6,19 +6,20 @@ class FieldPad:
def __init__(self, size=(1,1), charSize=1, *args):
def __init__(self, size=(1,1), charSize=1, colours=False):
self.pad = curses.newpad(size[1]+1, (size[0]+1)*charSize)
self.size = size
self.charSize = charSize
self.center = (0, 0)
self.colours = colours
def resize(self, width, height):
self.size = (width, height)
self.pad.resize(height+1, width*self.charSize1)
def changeCell(self, x, y, char, colour=None):
if colour != None:
self.pad.addstr(y, x*self.charSize, char, curses.color_pair(colour+1))
if colour != None and self.colours:
self.pad.addstr(y, x*self.charSize, char, curses.color_pair(colour))
else:
self.pad.addstr(y, x*self.charSize, char)

View File

@ -40,6 +40,7 @@ def main():
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 keybindings. If it is either of these names: {} it will be loaded from the keybindings directory.'.format(standardKeyFiles), 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('-l', '--colours', '--colors', help='', action="store_true")
args = parser.parse_args()
charFile = args.characters
@ -62,7 +63,7 @@ def main():
hostname, sep, port = address.partition(':')
address = (hostname, int(port))
client.main(args.name, args.socket, address, keybindings, charMap)
client.main(args.name, args.socket, address, keybindings, charMap, args.colours)
if __name__=="__main__":