Fixing contrib test issues

This commit is contained in:
Griatch 2021-12-18 23:56:38 +01:00
parent 04a95297b5
commit 7f2b8c81d7
30 changed files with 248 additions and 565 deletions

View file

@ -1,5 +1,5 @@
"""
Extened Room - Griatch 2012, vincent-lg 2019
Contribs related to moving in and manipulating the game world and grid.
"""

View file

@ -21,7 +21,7 @@ class ForceUTCDatetime(datetime.datetime):
return datetime.datetime.utcfromtimestamp(timestamp)
@patch("evennia.contrib.extended_room.datetime.datetime", ForceUTCDatetime)
@patch("evennia.contrib.grid.extended_room.extended_room.datetime.datetime", ForceUTCDatetime)
# mock gametime to return April 9, 2064, at 21:06 (spring evening)
@patch("evennia.utils.gametime.gametime", new=Mock(return_value=2975000766))
class TestExtendedRoom(CommandTest):

View file

@ -6,12 +6,193 @@ Test map builder.
from evennia.commands.default.tests import CommandTest
from . import mapbuilder
# -*- coding: utf-8 -*-
# Add the necessary imports for your instructions here.
from evennia import create_object
from typeclasses import rooms, exits
from random import randint
import random
# A map with a temple (▲) amongst mountains (n,∩) in a forest (♣,♠) on an
# island surrounded by water (≈). By giving no instructions for the water
# characters we effectively skip it and create no rooms for those squares.
EXAMPLE1_MAP = '''
n
n
'''
def example1_build_forest(x, y, **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.'''
# Create a room and provide a basic description.
room = create_object(rooms.Room, key="forest" + str(x) + str(y))
room.db.desc = "Basic forest room."
# Send a message to the account
kwargs["caller"].msg(room.key + " " + room.dbref)
# This is generally mandatory.
return room
def example1_build_mountains(x, y, **kwargs):
'''A room that is a little more advanced'''
# Create the room.
room = create_object(rooms.Room, key="mountains" + str(x) + str(y))
# Generate a description by randomly selecting an entry from a list.
room_desc = [
"Mountains as far as the eye can see",
"Your path is surrounded by sheer cliffs",
"Haven't you seen that rock before?",
]
room.db.desc = random.choice(room_desc)
# Create a random number of objects to populate the room.
for i in range(randint(0, 3)):
rock = create_object(key="Rock", location=room)
rock.db.desc = "An ordinary rock."
# Send a message to the account
kwargs["caller"].msg(room.key + " " + room.dbref)
# This is generally mandatory.
return room
def example1_build_temple(x, y, **kwargs):
'''A unique room that does not need to be as general'''
# Create the room.
room = create_object(rooms.Room, key="temple" + str(x) + str(y))
# Set the description.
room.db.desc = (
"In what, from the outside, appeared to be a grand and "
"ancient temple you've somehow found yourself in the the "
"Evennia Inn! It consists of one large room filled with "
"tables. The bardisk extends along the east wall, where "
"multiple barrels and bottles line the shelves. The "
"barkeep seems busy handing out ale and chatting with "
"the patrons, which are a rowdy and cheerful lot, "
"keeping the sound level only just below thunderous. "
"This is a rare spot of mirth on this dread moor."
)
# Send a message to the account
kwargs["caller"].msg(room.key + " " + room.dbref)
# This is generally mandatory.
return room
# Include your trigger characters and build functions in a legend dict.
EXAMPLE1_LEGEND = {
("", ""): example1_build_forest,
("", "n"): example1_build_mountains,
(""): example1_build_temple,
}
# Example two
# @mapbuilder/two evennia.contrib.mapbuilder.EXAMPLE2_MAP EXAMPLE2_LEGEND
# -*- coding: utf-8 -*-
# Add the necessary imports for your instructions here.
# from evennia import create_object
# from typeclasses import rooms, exits
# from evennia.utils import utils
# from random import randint
# import random
# This is the same layout as Example 1 but included are characters for exits.
# We can use these characters to determine which rooms should be connected.
EXAMPLE2_MAP = '''
--
| |
| | |
--
'''
def example2_build_forest(x, y, **kwargs):
'''A basic room'''
# If on anything other than the first iteration - Do nothing.
if kwargs["iteration"] > 0:
return None
room = create_object(rooms.Room, key="forest" + str(x) + str(y))
room.db.desc = "Basic forest room."
kwargs["caller"].msg(room.key + " " + room.dbref)
return room
def example2_build_verticle_exit(x, y, **kwargs):
'''Creates two exits to and from the two rooms north and south.'''
# If on the first iteration - Do nothing.
if kwargs["iteration"] == 0:
return
north_room = kwargs["room_dict"][(x, y - 1)]
south_room = kwargs["room_dict"][(x, y + 1)]
# create exits in the rooms
create_object(
exits.Exit, key="south", aliases=["s"], location=north_room, destination=south_room
)
create_object(
exits.Exit, key="north", aliases=["n"], location=south_room, destination=north_room
)
kwargs["caller"].msg("Connected: " + north_room.key + " & " + south_room.key)
def example2_build_horizontal_exit(x, y, **kwargs):
'''Creates two exits to and from the two rooms east and west.'''
# If on the first iteration - Do nothing.
if kwargs["iteration"] == 0:
return
west_room = kwargs["room_dict"][(x - 1, y)]
east_room = kwargs["room_dict"][(x + 1, y)]
create_object(exits.Exit, key="east", aliases=["e"], location=west_room, destination=east_room)
create_object(exits.Exit, key="west", aliases=["w"], location=east_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.
EXAMPLE2_LEGEND = {
("", ""): example2_build_forest,
("|"): example2_build_verticle_exit,
("-"): example2_build_horizontal_exit,
}
class TestMapBuilder(CommandTest):
def test_cmdmapbuilder(self):
self.call(
mapbuilder.CmdMapBuilder(),
"evennia.contrib.mapbuilder.EXAMPLE1_MAP evennia.contrib.mapbuilder.EXAMPLE1_LEGEND",
"evennia.contrib.grid.mapbuilder.tests.EXAMPLE1_MAP "
"evennia.contrib.grid.mapbuilder.tests.EXAMPLE1_LEGEND",
"""Creating Map...|≈≈≈≈≈
n
@ -21,7 +202,8 @@ class TestMapBuilder(CommandTest):
)
self.call(
mapbuilder.CmdMapBuilder(),
"evennia.contrib.mapbuilder.EXAMPLE2_MAP evennia.contrib.mapbuilder.EXAMPLE2_LEGEND",
"evennia.contrib.grid.mapbuilder.tests.EXAMPLE2_MAP "
"evennia.contrib.grid.mapbuilder.tests.EXAMPLE2_LEGEND",
"""Creating Map...|≈ ≈ ≈ ≈ ≈
--

View file

@ -12,7 +12,7 @@ class TestSimpleDoor(CommandTest):
def test_cmdopen(self):
self.call(
simpledoor.CmdOpen(),
"newdoor;door:contrib.simpledoor.SimpleDoor,backdoor;door = Room2",
"newdoor;door:contrib.grid.simpledoor.SimpleDoor,backdoor;door = Room2",
"Created new Exit 'newdoor' from Room to Room2 (aliases: door).|Note: A door-type exit was "
"created - ignored eventual custom return-exit type.|Created new Exit 'newdoor' from Room2 to Room (aliases: door).",
)

View file

@ -1,5 +1,5 @@
"""
XYZGrid - Evennia 2021
XYZGrid - Griatch 2021
"""

View file

@ -4,12 +4,12 @@ the `evennia xyzgrid` launcher command.
First add the launcher extension in your mygame/server/conf/settings.py:
EXTRA_LAUNCHER_COMMANDS['xyzgrid'] = 'evennia.contrib.xyzgrid.launchcmd.xyzcommand'
EXTRA_LAUNCHER_COMMANDS['xyzgrid'] = 'evennia.contrib.grid.xyzgrid.launchcmd.xyzcommand'
Then
evennia xyzgrid init
evennia xyzgrid add evennia.contrib.xyzgrid.map_example
evennia xyzgrid add evennia.contrib.grid.xyzgrid.map_example
evennia xyzgrid build
@ -21,7 +21,7 @@ from evennia.contrib.grid.xyzgrid import xymap_legend
# default prototype parent. It's important that
# the typeclass inherits from the XYZRoom (or XYZExit)
# if adding the evennia.contrib.xyzgrid.prototypes to
# if adding the evennia.contrib.grid.xyzgrid.prototypes to
# settings.PROTOTYPE_MODULES, one could just set the
# prototype_parent to 'xyz_room' and 'xyz_exit' here
# instead.
@ -30,14 +30,14 @@ ROOM_PARENT = {
"key": "An empty room",
"prototype_key": "xyz_exit_prototype",
# "prototype_parent": "xyz_room",
"typeclass": "evennia.contrib.xyzgrid.xyzroom.XYZRoom",
"typeclass": "evennia.contrib.grid.xyzgrid.xyzroom.XYZRoom",
"desc": "An empty room.",
}
EXIT_PARENT = {
"prototype_key": "xyz_exit_prototype",
# "prototype_parent": "xyz_exit",
"typeclass": "evennia.contrib.xyzgrid.xyzroom.XYZExit",
"typeclass": "evennia.contrib.grid.xyzgrid.xyzroom.XYZExit",
"desc": "A path to the next location.",
}

View file

@ -5,7 +5,7 @@ server (since this can be slow).
To use, add to the settings:
::
EXTRA_LAUNCHER_COMMANDS.update({'xyzgrid': 'evennia.contrib.xyzgrid.launchcmd.xyzcommand'})
EXTRA_LAUNCHER_COMMANDS.update({'xyzgrid': 'evennia.contrib.grid.xyzgrid.launchcmd.xyzcommand'})
You should now be able to do
::
@ -80,7 +80,7 @@ add <path.to.xymap.module> [<path> <path>,...]
{"map": mapstring, "zcoord": mapname/zcoord, "legend": dict, "prototypes": dict}
describing one single XYmap, or
- a XYMAP_DATA_LIST - a list of multiple dicts on the XYMAP_DATA form. This allows for
embedding multiple maps in the same module. See evennia/contrib/xyzgrid/example.py
embedding multiple maps in the same module. See evennia/contrib/grid/xyzgrid/example.py
for an example of how this looks.
Note that adding a map does *not* spawn it. If maps are linked to one another, you should
@ -89,7 +89,7 @@ add <path.to.xymap.module> [<path> <path>,...]
Examples:
evennia xyzgrid add evennia.contrib.xyzgrid.example
evennia xyzgrid add evennia.contrib.grid.xyzgrid.example
evennia xyzgrid add world.mymap1 world.mymap2 world.mymap3
"""

View file

@ -3,7 +3,7 @@ Default prototypes for building the XYZ-grid into actual game-rooms.
Add this to mygame/conf/settings/settings.py:
PROTOTYPE_MODULES += ['evennia.contrib.xyzgrid.prototypes']
PROTOTYPE_MODULES += ['evennia.contrib.grid.xyzgrid.prototypes']
The prototypes can then be used in mapping prototypes as
@ -28,7 +28,7 @@ except AttributeError:
room_prototype = {
'prototype_key': 'xyz_room',
'typeclass': 'evennia.contrib.xyzgrid.xyzroom.XYZRoom',
'typeclass': 'evennia.contrib.grid.xyzgrid.xyzroom.XYZRoom',
'prototype_tags': ("xyzroom", ),
'key': "A room",
'desc': "An empty room."
@ -37,7 +37,7 @@ room_prototype.update(room_override)
exit_prototype = {
'prototype_key': 'xyz_exit',
'typeclass': 'evennia.contrib.xyzgrid.xyzroom.XYZExit',
'typeclass': 'evennia.contrib.grid.xyzgrid.xyzroom.XYZExit',
'prototype_tags': ("xyzexit", ),
'desc': "An exit."
}

View file

@ -854,8 +854,6 @@ class TestMap8(_MapTest):
target=target, target_path_style="",
character='@',
max_size=max_size)
self.assertEqual(expected, mapstr.replace("||", "|"))
def test_spawn(self):
"""
Spawn the map into actual objects.
@ -1018,6 +1016,8 @@ class TestMap11(_MapTest):
target=target, target_path_style="",
character='@',
max_size=max_size)
print(f"\n\n{coord}-{target}\n{expected}\n\n{mapstr}")
self.assertEqual(expected, mapstr)
def test_spawn(self):
@ -1252,6 +1252,7 @@ class TestXYZGridTransition(EvenniaTest):
self.assertEqual(east_exit.db_destination, room2)
self.assertEqual(west_exit.db_destination, room1)
class TestBuildExampleGrid(EvenniaTest):
"""
Test building the map-example (this takes about 30s)
@ -1274,7 +1275,7 @@ class TestBuildExampleGrid(EvenniaTest):
Build the map example.
"""
mapdatas = self.grid.maps_from_module("evennia.contrib.xyzgrid.example")
mapdatas = self.grid.maps_from_module("evennia.contrib.grid.xyzgrid.example")
self.assertEqual(len(mapdatas), 2)
self.grid.add_maps(*mapdatas)

View file

@ -210,7 +210,7 @@ class XYMap:
if not _LOADED_PROTOTYPES:
# inject default prototypes, but don't override prototype-keys loaded from
# settings, if they exist (that means the user wants to replace the defaults)
protlib.load_module_prototypes("evennia.contrib.xyzgrid.prototypes", override=False)
protlib.load_module_prototypes("evennia.contrib.grid.xyzgrid.prototypes", override=False)
_LOADED_PROTOTYPES = True
self.Z = Z
@ -636,7 +636,7 @@ class XYMap:
"""
global _XYZROOMCLASS
if not _XYZROOMCLASS:
from evennia.contrib.xyzgrid.xyzroom import XYZRoom as _XYZROOMCLASS
from evennia.contrib.grid.xyzgrid.xyzroom import XYZRoom as _XYZROOMCLASS
x, y = xy
wildcard = '*'
spawned = []

View file

@ -315,7 +315,7 @@ class MapNode:
# create a new entity with proper coordinates etc
tclass = self.prototype['typeclass']
tclass = (f' ({tclass})'
if tclass != 'evennia.contrib.xyzgrid.xyzroom.XYZRoom'
if tclass != 'evennia.contrib.grid.xyzgrid.xyzroom.XYZRoom'
else '')
self.log(f" spawning room at xyz={xyz}{tclass}")
nodeobj, err = NodeTypeclass.create(
@ -413,7 +413,7 @@ class MapNode:
prot = maplinks[key.lower()][3].prototype
tclass = prot['typeclass']
tclass = (f' ({tclass})'
if tclass != 'evennia.contrib.xyzgrid.xyzroom.XYZExit'
if tclass != 'evennia.contrib.grid.xyzgrid.xyzroom.XYZExit'
else '')
self.log(f" spawning/updating exit xyz={xyz}, direction={key}{tclass}")

View file

@ -278,7 +278,7 @@ class XYZRoom(DefaultRoom):
def xyzgrid(self):
global GET_XYZGRID
if not GET_XYZGRID:
from evennia.contrib.xyzgrid.xyzgrid import get_xyzgrid as GET_XYZGRID
from evennia.contrib.grid.xyzgrid.xyzgrid import get_xyzgrid as GET_XYZGRID
return GET_XYZGRID()
@property
@ -493,7 +493,7 @@ class XYZExit(DefaultExit):
def xyzgrid(self):
global GET_XYZGRID
if not GET_XYZGRID:
from evennia.contrib.xyzgrid.xyzgrid import get_xyzgrid as GET_XYZGRID
from evennia.contrib.grid.xyzgrid.xyzgrid import get_xyzgrid as GET_XYZGRID
return GET_XYZGRID()
@property