From: Jeremy Stanley Date: Wed, 24 Aug 2016 01:17:08 +0000 (+0000) Subject: Rename internal:directions to .mudpy.movement.* X-Git-Tag: 0.0.1~181 X-Git-Url: https://mudpy.org/gitweb?a=commitdiff_plain;h=76ae128e10c23e0518f331ee4c5638c993d95101;p=mudpy.git Rename internal:directions to .mudpy.movement.* Convert the old style internal:directions element to a series of new style .mudpy.movement.* elements and adjust the move_direction() function accordingly. Also extend the Universe class to provide a set-based index of direction names found in the data. --- diff --git a/etc/mudpy.yaml b/etc/mudpy.yaml index 74cfe6e..512f27f 100644 --- a/etc/mudpy.yaml +++ b/etc/mudpy.yaml @@ -23,6 +23,25 @@ __control__: .mudpy.log.stdout: true #.mudpy.log.syslog: mudpy +.mudpy.movement.down.enter_term: above +.mudpy.movement.down.exit_term: downward +.mudpy.movement.down.vector: [0,0,-1] +.mudpy.movement.east.enter_term: the west +.mudpy.movement.east.exit_term: to the east +.mudpy.movement.east.vector: [1,0,0] +.mudpy.movement.north.enter_term: the south +.mudpy.movement.north.exit_term: to the north +.mudpy.movement.north.vector: [0,1,0] +.mudpy.movement.south.enter_term: the north +.mudpy.movement.south.exit_term: to the south +.mudpy.movement.south.vector: [0,-1,0] +.mudpy.movement.up.enter_term: below +.mudpy.movement.up.exit_term: upward +.mudpy.movement.up.vector: [0,0,1] +.mudpy.movement.west.enter_term: the east +.mudpy.movement.west.exit_term: to the west +.mudpy.movement.west.vector: [-1,0,0] + internal:network: host: ::1 #host: 127.0.0.1 @@ -50,11 +69,3 @@ internal:time: linkdead: { "default": 6000, "entering_account_name": 600, "active": 6048000 } idle: { "default": 5000, "entering_account_name": 500, "active": 5040000 } increment: 0.1 - -internal:directions: - down: { "vector": [0,0,-1], "exit": "downward", "enter": "above" } - east: { "vector": [1,0,0], "exit": "to the east", "enter": "the west" } - north: { "vector": [0,1,0], "exit": "to the north", "enter": "the south" } - south: { "vector": [0,-1,0], "exit": "to the south", "enter": "the north" } - up: { "vector": [0,0,1], "exit": "upward", "enter": "below" } - west: { "vector": [-1,0,0], "exit": "to the west", "enter": "the east" } diff --git a/lib/mudpy/data.py b/lib/mudpy/data.py index 02a9139..00ab923 100644 --- a/lib/mudpy/data.py +++ b/lib/mudpy/data.py @@ -99,6 +99,9 @@ class DataFile: element = mudpy.misc.Element(prefix, self.universe, self.filename) element.set(node[facet_pos:], self.data[node]) + if prefix.startswith("mudpy.movement."): + self.universe.directions.add( + prefix[prefix.rfind(".") + 1:]) for include_file in includes: if not os.path.isabs(include_file): include_file = find_file( diff --git a/lib/mudpy/misc.py b/lib/mudpy/misc.py index c5e1d1b..616065b 100644 --- a/lib/mudpy/misc.py +++ b/lib/mudpy/misc.py @@ -252,48 +252,17 @@ class Element: def move_direction(self, direction): """Relocate the element in a specified direction.""" - self.echo_to_location( - self.get( - "name" - ) + " exits " + self.universe.categories[ - "internal" - ][ - "directions" - ].get( - direction - )[ - "exit" - ] + "." - ) - self.send( - "You exit " + self.universe.categories[ - "internal" - ][ - "directions" - ].get( - direction - )[ - "exit" - ] + ".", - add_prompt=False - ) + motion = self.universe.contents["mudpy.movement.%s" % direction] + enter_term = motion.get("enter_term") + exit_term = motion.get("exit_term") + self.echo_to_location("%s exits %s." % (self.get("name"), exit_term)) + self.send("You exit %s." % exit_term, add_prompt=False) self.go_to( self.universe.contents[ self.get("location")].link_neighbor(direction) ) - self.echo_to_location( - self.get( - "name" - ) + " arrives from " + self.universe.categories[ - "internal" - ][ - "directions" - ].get( - direction - )[ - "enter" - ] + "." - ) + self.echo_to_location("%s arrives from %s." % ( + self.get("name"), enter_term)) def look_at(self, key): """Show an element to another element.""" @@ -331,14 +300,9 @@ class Element: if re.match("""^area:-?\d+,-?\d+,-?\d+$""", self.key): coordinates = [(int(x)) for x in self.key.split(":")[1].split(",")] - directions = self.universe.categories["internal"]["directions"] - offsets = dict( - [ - ( - x, directions.get(x)["vector"] - ) for x in directions.facets() - ] - ) + offsets = dict((x, + self.universe.contents["mudpy.movement.%s" % x].get("vector") + ) for x in self.universe.directions) for portal in self.get("gridlinks"): adjacent = map(lambda c, o: c + o, coordinates, offsets[portal]) @@ -379,6 +343,7 @@ class Universe: self.categories = {} self.contents = {} self.default_origins = {} + self.directions = set() self.loglines = [] self.private_files = [] self.reload_flag = False