various tweaks and fixes
This commit is contained in:
parent
ed7fe60a6d
commit
ed7d265b48
5 changed files with 524 additions and 212 deletions
39
gamemap.py
39
gamemap.py
|
@ -358,7 +358,7 @@ class MapExit(Thing):
|
|||
yaml_flag = u'!MapExit'
|
||||
defaultGraphic = ('clear', '#FF0000', 'x')
|
||||
|
||||
def __init__(self, name, x: int, y: int, exitid: int, destination: str, prefix: None, graphic = defaultGraphic):
|
||||
def __init__(self, name, x: int, y: int, exitid: int, destination: str, prefix = None, onUse = '', key = True, graphic = defaultGraphic):
|
||||
description = name
|
||||
if prefix:
|
||||
description = "{0} {1}".format(prefix, name)
|
||||
|
@ -366,6 +366,8 @@ class MapExit(Thing):
|
|||
self.exitid = exitid
|
||||
self.destination = destination
|
||||
self.prefix = prefix
|
||||
self.onUse = onUse
|
||||
self.key = key
|
||||
self.graphic = graphic
|
||||
|
||||
@classmethod
|
||||
|
@ -384,6 +386,10 @@ class MapExit(Thing):
|
|||
ret['graphic'] = graphic
|
||||
if node.prefix != None:
|
||||
ret['prefix'] = node.prefix
|
||||
if node.onUse != '':
|
||||
ret['onUse'] = node.onUse
|
||||
if node.key != True:
|
||||
ret['key'] = node.key
|
||||
return representer.represent_mapping(cls.yaml_flag, ret)
|
||||
|
||||
@classmethod
|
||||
|
@ -392,6 +398,8 @@ class MapExit(Thing):
|
|||
constructor.construct_mapping(node, parts, True)
|
||||
# set default values for optional arguments
|
||||
prefix = None
|
||||
onUse = ''
|
||||
key = True
|
||||
bgc = MapExit.defaultGraphic[0]
|
||||
fgc = MapExit.defaultGraphic[1]
|
||||
shape = MapExit.defaultGraphic[2]
|
||||
|
@ -406,8 +414,12 @@ class MapExit(Thing):
|
|||
graphic = (bgc, fgc, shape)
|
||||
if 'prefix' in parts:
|
||||
prefix = parts['prefix']
|
||||
if 'onUse' in parts:
|
||||
onUse = parts['onUse']
|
||||
if 'key' in parts:
|
||||
key = parts['key']
|
||||
return cls(parts['name'], parts['location'][0], parts['location'][1],
|
||||
parts['id'], parts['destination'], prefix, graphic)
|
||||
parts['id'], parts['destination'], prefix, onUse, key, graphic)
|
||||
|
||||
class MapEntrance(Thing):
|
||||
yaml_flag = u'!MapEntrance'
|
||||
|
@ -417,7 +429,7 @@ class MapEntrance(Thing):
|
|||
def __init__(self, x: int, y: int, exitid: int, name = None):
|
||||
if name == None:
|
||||
name = 'entrance {}'.format(exitid)
|
||||
super(MapEntrance, self).__init__('a', name, x, y, description, 1)
|
||||
super(MapEntrance, self).__init__('a', name, x, y, '', 1)
|
||||
self.exitid = exitid
|
||||
|
||||
@classmethod
|
||||
|
@ -574,6 +586,7 @@ Entering a map through stdin will be obsolete once testing is over."""
|
|||
yaml.register_class(NPC)
|
||||
yaml.register_class(Door)
|
||||
yaml.register_class(MapExit)
|
||||
yaml.register_class(MapEntrance)
|
||||
if infile != None:
|
||||
try:
|
||||
with open(infile, 'r') as f:
|
||||
|
@ -582,7 +595,7 @@ Entering a map through stdin will be obsolete once testing is over."""
|
|||
print("The file could not be read.")
|
||||
return None, nextThing
|
||||
else:
|
||||
raise RuntimeError("No file was specified for loading.")
|
||||
raise MapError("No file was specified for loading.")
|
||||
|
||||
# Now what we do with the data
|
||||
mat = None
|
||||
|
@ -593,10 +606,10 @@ Entering a map through stdin will be obsolete once testing is over."""
|
|||
#print(layout.text)
|
||||
match = GameMap.matrixRegex.match(layout.lstrip())
|
||||
if match == None:
|
||||
raise RuntimeError('Map read a file without a map matrix.')
|
||||
raise MapError('Map read a file without a map matrix.')
|
||||
mat = match.group()
|
||||
else:
|
||||
raise RuntimeError('Map read a file without a map matrix.')
|
||||
raise MapError('Map read a file without a map matrix.')
|
||||
|
||||
# generate matrix and graph first
|
||||
mapMatrix, mapGraph, dimensions = GameMap.parseMatrix(mat)
|
||||
|
@ -632,7 +645,7 @@ list of lists of tuples."""
|
|||
if x == 0:
|
||||
x = len(mat[l])
|
||||
elif x != len(mat[l]):
|
||||
raise RuntimeError("Map matrix has jagged edges.")
|
||||
raise MapError("Map matrix has jagged edges.")
|
||||
l += 1
|
||||
#x = 0
|
||||
mat.append([])
|
||||
|
@ -644,7 +657,7 @@ list of lists of tuples."""
|
|||
else:
|
||||
matrixStr = matrixStr[i:]
|
||||
else: # This should happen when it finishes?
|
||||
raise RuntimeError("Unexpected token in map matrix: '{0}'".format(matrixStr))
|
||||
raise MapError("Unexpected token in map matrix: '{0}'".format(matrixStr))
|
||||
y = len(mat) - 1
|
||||
|
||||
# Now for the graph
|
||||
|
@ -995,19 +1008,19 @@ The closeEnough parameter will create a path that lands beside the source if nec
|
|||
newPos = self.coordsToInt(x, y)
|
||||
else:
|
||||
x, y = self.intToCoords(x)
|
||||
if thing:
|
||||
if thing != None:
|
||||
oldPos = self.coordsToInt(thing.x, thing.y)
|
||||
if oldPos in self.thingPos:
|
||||
self.thingPos[oldPos].remove(name)
|
||||
self.thingPos[oldPos].remove(thing.thingID)
|
||||
if len(self.thingPos[oldPos]) == 0:
|
||||
del self.thingPos[oldPos]
|
||||
if newPos not in self.thingPos:
|
||||
self.thingPos[newPos] = [name]
|
||||
self.thingPos[newPos] = [thing.thingID]
|
||||
else:
|
||||
self.thingPos[newPos].append(name)
|
||||
self.thingPos[newPos].append(thing.thingID)
|
||||
relPlayerx, relPlayery = thing.playerx - thing.x, thing.playery - thing.y
|
||||
thing.x, thing.y = x, y
|
||||
thing.playerx, thing.playery = thing.x + relPlayerx, thing.y + relPlayery
|
||||
else:
|
||||
raise RuntimeError("There is nothing to move.".format(name))
|
||||
raise MapError("There is nothing to move.")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue