Source data is now in toml format
The input text is now expected to be a toml file with a leading comment section defining the battle map, according to the following rules: 1. Blank lines are ignored 2. Lines at the top of the file beginning with '#', optionally with leading spaces, is treated as map data 3. Map data continues until the first line not starting with a #. 4. Any subsequent lines are treated as metadata in toml format. 5. The metadata must contain the [map] section. 6. The [map] section must contain the "name" attribute. The metadata is available as BattleMap.metadata; the map source is available as BattleMap.map_string. New convenience properties ahve been added to the BattleMap class for accessing portions of the text-only output. This includes the header and footer attributes.
This commit is contained in:
+31
-17
@@ -16,18 +16,33 @@ def manager():
|
||||
def sample_map():
|
||||
return dedent(
|
||||
"""
|
||||
........ 1
|
||||
........ ........ 2
|
||||
........ ........
|
||||
.......L...D... D
|
||||
........ .... ...
|
||||
........ ...d ...
|
||||
.
|
||||
.........S. 3
|
||||
5 . .
|
||||
....S... ...d.... 4
|
||||
........ ........
|
||||
........ ........
|
||||
# ........ 1
|
||||
# ........ ........ 2
|
||||
# ........ ........
|
||||
# .......L...D... D
|
||||
# ........ .... ...
|
||||
# ........ ...d ...
|
||||
# .
|
||||
# .........S. 3
|
||||
# 5 . .
|
||||
# ....S... ...d.... 4
|
||||
# ........ ........
|
||||
# ........ ........
|
||||
|
||||
[map]
|
||||
name = "sample map"
|
||||
description = "sample dungeon"
|
||||
|
||||
[1]
|
||||
name = "room 1"
|
||||
[2]
|
||||
name = "room 2"
|
||||
[3]
|
||||
name = "room 3"
|
||||
[4]
|
||||
name = "room 4"
|
||||
[5]
|
||||
name = "room 5"
|
||||
|
||||
"""
|
||||
)
|
||||
@@ -39,23 +54,22 @@ def test_tileset_loader(manager):
|
||||
|
||||
|
||||
def test_renderer(manager, sample_map):
|
||||
test_map = battlemap.BattleMap("test map", source=StringIO(sample_map), tileset=manager.load("ascii"))
|
||||
test_map = battlemap.BattleMap(source=StringIO(sample_map), tileset=manager.load("ascii"))
|
||||
test_map.load()
|
||||
assert test_map.width == 21
|
||||
assert test_map.height == 12
|
||||
assert test_map.source_data == sample_map.strip("\n")
|
||||
|
||||
srclines = sample_map.splitlines()[1:]
|
||||
strlines = str(test_map).splitlines()
|
||||
for i in range(len(strlines)):
|
||||
assert strlines[i] == srclines[i].ljust(21, " ")
|
||||
assert strlines[i] == srclines[i].lstrip(' #').ljust(21, " ")
|
||||
|
||||
|
||||
def test_grid_coordiates(manager):
|
||||
coord_length = len(X_COORDS)
|
||||
map_size = 2 * coord_length + 1
|
||||
bigmap = StringIO((("." * map_size) + "\n") * map_size)
|
||||
test_map = battlemap.BattleMap("test map", source=bigmap, tileset=manager.load("ascii"))
|
||||
bigmap = StringIO((' # ' + ("." * map_size) + "\n") * map_size)
|
||||
test_map = battlemap.BattleMap(source=bigmap, tileset=manager.load("ascii"))
|
||||
test_map.load()
|
||||
assert test_map.grid.data[-1][-1].coordinates == (f"{map_size - 1}", X_COORDS[0] * 3)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user