Addresses issues identified above.

1. Second pass not working, room has no exits when using example 2:
The suggested commands for the example code didn't include the relevant switch. Wasn't an issue with the code, it just only iterated once.
2. First `build_forest` function not being reached due to duplicate function name:
Changed name of example code build functions to unique names. Funnily enough Pycharm didn't pick that up either.
3. Attribute errors not caught:
Added appropriate return statements.
4. Example on line 297 wrong:
Changed examples.
5.Suggestion - pass back Dbref:
Dbref is now returned on creation. This was in the original code, I just overlooked it.
This commit is contained in:
CloudKeeper1 2016-09-11 20:46:35 +10:00 committed by Griatch
parent a489b6df55
commit 760865f26f

View file

@ -74,7 +74,8 @@ Switches:
Example: Example:
@mapbuilder world.gamemap.MAP world.maplegend.MAP_LEGEND @mapbuilder world.gamemap.MAP world.maplegend.MAP_LEGEND
@mapbuilder evennia.contrib.mapbuilder.EXAMPLE2_MAP EXAMPLE2_LEGEND @mapbuilder evennia.contrib.mapbuilder.EXAMPLE1_MAP EXAMPLE1_LEGEND
@mapbuilder/two evennia.contrib.mapbuilder.EXAMPLE2_MAP EXAMPLE2_LEGEND
(Legend path defaults to map path) (Legend path defaults to map path)
Below are two examples showcasing the use of automatic exit generation and Below are two examples showcasing the use of automatic exit generation and
@ -110,7 +111,7 @@ EXAMPLE1_MAP = """\
""" """
def build_forest(x, y, **kwargs): def example1_build_forest(x, y, **kwargs):
"""A basic example of build instructions. Make sure to include **kwargs """A basic example of build instructions. Make sure to include **kwargs
in the arguments and return an instance of the room for exit generation.""" in the arguments and return an instance of the room for exit generation."""
@ -119,13 +120,13 @@ def build_forest(x, y, **kwargs):
room.db.desc = "Basic forest room." room.db.desc = "Basic forest room."
# Send a message to the player # Send a message to the player
kwargs["caller"].msg("Forest Room Created.") kwargs["caller"].msg(room.key + " " + room.dbref)
# This is generally mandatory. # This is generally mandatory.
return room return room
def build_mountains(x, y, **kwargs): def example1_build_mountains(x, y, **kwargs):
"""A room that is a little more advanced""" """A room that is a little more advanced"""
# Create the room. # Create the room.
@ -143,13 +144,13 @@ def build_mountains(x, y, **kwargs):
rock.db.desc = "An ordinary rock." rock.db.desc = "An ordinary rock."
# Send a message to the player # Send a message to the player
kwargs["caller"].msg("Mountain Room Created.") kwargs["caller"].msg(room.key + " " + room.dbref)
# This is generally mandatory. # This is generally mandatory.
return room return room
def build_temple(x, y, **kwargs): def example1_build_temple(x, y, **kwargs):
"""A unique room that does not need to be as general""" """A unique room that does not need to be as general"""
# Create the room. # Create the room.
@ -167,15 +168,15 @@ def build_temple(x, y, **kwargs):
"This is a rare spot of mirth on this dread moor.") "This is a rare spot of mirth on this dread moor.")
# Send a message to the player # Send a message to the player
kwargs["caller"].msg("Temple Room Created.") kwargs["caller"].msg(room.key + " " + room.dbref)
# This is generally mandatory. # This is generally mandatory.
return room return room
# Include your trigger characters and build functions in a legend dict. # Include your trigger characters and build functions in a legend dict.
EXAMPLE1_LEGEND = {("", ""): build_forest, EXAMPLE1_LEGEND = {("", ""): example1_build_forest,
("", "n"): build_mountains, ("", "n"): example1_build_mountains,
(""): build_temple} (""): example1_build_temple}
# ---------- EXAMPLE 2 ---------- # # ---------- EXAMPLE 2 ---------- #
# @mapbuilder/two evennia.contrib.mapbuilder.EXAMPLE2_MAP EXAMPLE2_LEGEND # @mapbuilder/two evennia.contrib.mapbuilder.EXAMPLE2_MAP EXAMPLE2_LEGEND
@ -204,7 +205,7 @@ EXAMPLE2_MAP = """\
""" """
def build_forest(x, y, **kwargs): def example2_build_forest(x, y, **kwargs):
"""A basic room""" """A basic room"""
# If on anything other than the first iteration - Do nothing. # If on anything other than the first iteration - Do nothing.
if kwargs["iteration"] > 0: if kwargs["iteration"] > 0:
@ -213,19 +214,17 @@ def build_forest(x, y, **kwargs):
room = create_object(rooms.Room, key="forest" + str(x) + str(y)) room = create_object(rooms.Room, key="forest" + str(x) + str(y))
room.db.desc = "Basic forest room." room.db.desc = "Basic forest room."
kwargs["caller"].msg(room.key + " " + room.dbref)
return room return room
def build_vertical_exit(x, y, **kwargs): def example2_build_verticle_exit(x, y, **kwargs):
"""Creates two exits to and from the two rooms north and south.""" """Creates two exits to and from the two rooms north and south."""
# If on the first iteration - Do nothing. # If on the first iteration - Do nothing.
if kwargs["iteration"] == 0: if kwargs["iteration"] == 0:
return return
for key, value in kwargs["room_dict"].iteritems():
kwargs["caller"].msg(str(key))
kwargs["caller"].msg(str(value))
north_room = kwargs["room_dict"][(x, y-1)] north_room = kwargs["room_dict"][(x, y-1)]
south_room = kwargs["room_dict"][(x, y+1)] south_room = kwargs["room_dict"][(x, y+1)]
@ -237,8 +236,11 @@ def build_vertical_exit(x, y, **kwargs):
aliases=["n"], location=south_room, aliases=["n"], location=south_room,
destination=north_room) destination=north_room)
kwargs["caller"].msg("Connected: " + north_room.key +
" & " + south_room.key)
def build_horizontal_exit(x, y, **kwargs):
def example2_build_horizontal_exit(x, y, **kwargs):
"""Creates two exits to and from the two rooms east and west.""" """Creates two exits to and from the two rooms east and west."""
# If on the first iteration - Do nothing. # If on the first iteration - Do nothing.
if kwargs["iteration"] == 0: if kwargs["iteration"] == 0:
@ -255,10 +257,13 @@ def build_horizontal_exit(x, y, **kwargs):
aliases=["w"], location=east_room, aliases=["w"], location=east_room,
destination=west_room) destination=west_room)
kwargs["caller"].msg("Connected: " + west_room.key +
" & " + east_room.key)
# Include your trigger characters and build functions in a legend dict. # Include your trigger characters and build functions in a legend dict.
EXAMPLE2_LEGEND = {("", ""): build_forest, EXAMPLE2_LEGEND = {("", ""): example2_build_forest,
("|"): build_vertical_exit, ("|"): example2_build_verticle_exit,
("-"): build_horizontal_exit} ("-"): example2_build_horizontal_exit}
# ---------- END OF EXAMPLES ---------- # # ---------- END OF EXAMPLES ---------- #
@ -294,8 +299,10 @@ class CmdMapBuilder(COMMAND_DEFAULT_CLASS):
two - execute build instructions twice without automatic exit creation two - execute build instructions twice without automatic exit creation
Example: Example:
@mapbuilder evennia.contrib.mapbuilder.EXAMPLE_MAP MAP_LEGEND
@mapbuilder world.gamemap.MAP world.maplegend.MAP_LEGEND @mapbuilder world.gamemap.MAP world.maplegend.MAP_LEGEND
@mapbuilder evennia.contrib.mapbuilder.EXAMPLE1_MAP EXAMPLE1_LEGEND
@mapbuilder/two evennia.contrib.mapbuilder.EXAMPLE2_MAP EXAMPLE2_LEGEND
(Legend path defaults to map path)
This is a command which takes two inputs: This is a command which takes two inputs:
A string of ASCII characters representing a map and a dictionary of A string of ASCII characters representing a map and a dictionary of
@ -348,6 +355,7 @@ class CmdMapBuilder(COMMAND_DEFAULT_CLASS):
except Exception as exc: except Exception as exc:
# Or relays error message if fails. # Or relays error message if fails.
caller.msg(exc) caller.msg(exc)
return
# OBTAIN MAP_LEGEND FROM MODULE # OBTAIN MAP_LEGEND FROM MODULE
@ -372,6 +380,7 @@ class CmdMapBuilder(COMMAND_DEFAULT_CLASS):
except Exception as exc: except Exception as exc:
# Or relays error message if fails. # Or relays error message if fails.
caller.msg(exc) caller.msg(exc)
return
# Set up build_map arguments from switches # Set up build_map arguments from switches
iterations = 1 iterations = 1