init commit

This commit is contained in:
Benjamin Kirkbride
2019-04-28 21:41:55 -04:00
parent 69b18bc6aa
commit b117bd6fc2
20 changed files with 2067 additions and 0 deletions

10
dev_requirements.txt Normal file
View File

@@ -0,0 +1,10 @@
-e .
pytest
sphinx
coverage
coveralls
sphinx_rtd_theme
setuptools
pytest-cov
pytest-mock
wheel

15
make.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
rm -rf doc/build
rm dist/*
python3 setup.py clean
python3 setup.py build
python3 setup.py bdist_wheel
pip3 uninstall -y pytiled_parser
for file in dist/*
do
pip3 install $file
done
# sphinx-build -b html doc doc/build/html
coverage run --source arcade setup.py test
coverage report -m

View File

1244
pytiled_parser/foo.py Normal file

File diff suppressed because it is too large Load Diff

40
setup.py Normal file
View File

@@ -0,0 +1,40 @@
from os import path
import sys
from setuptools import setup
BUILD = 0
VERSION = '0.1'
RELEASE = VERSION
if __name__ == '__main__':
readme = path.join(path.dirname(path.abspath(__file__)), 'README.md')
with open(readme, 'r') as f:
long_desc = f.read()
setup(
name='pytiled_parser',
version=RELEASE,
description='Python Library for parsing Tiled Map Editor maps.',
long_description=long_desc,
author='Benjamin Kirkbride',
author_email='BenjaminKirkbride@gmail.com',
license='MIT',
url='https://github.com/Beefy-Swain/pytiled_parser',
download_url='https://github.com/Beefy-Swain/pytiled_parser',
install_requires=[
'dataclasses',
],
packages=['pytiled_parser'],
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development :: Libraries :: Python Modules',
],
test_suite='tests',
)

1
test/assets Symbolic link
View File

@@ -0,0 +1 @@
../../../the_decay_factor_assets/the-decay-factor---assets/assets/

65
test/collision_test.py Normal file
View File

@@ -0,0 +1,65 @@
import os
import arcade
import arcade.tiled
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SPRITE_SCALING = 1
GRAVITY = 1.1
class BasicTestWindow(arcade.Window):
def __init__(self, width, height, title, map_name):
super().__init__(width, height, title)
file_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(file_path)
self.layers = []
my_map = arcade.tiled.read_tiled_map(map_name, 1)
for layer in my_map.layers:
self.layers.append(arcade.tiled.generate_sprites(
my_map, layer, 1, "../arcade/arcade/examples/"))
def on_draw(self):
arcade.start_render()
for layer in self.layers:
layer.draw()
class CollisionTestWindow(BasicTestWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.frame_count = 0
self.player_list = arcade.SpriteList()
self.player_sprite = arcade.Sprite(
"../arcade/arcade/examples/images/character.png", SPRITE_SCALING)
self.player_sprite.center_x = 400
self.player_sprite.center_y = 800
self.player_list.append(self.player_sprite)
self.physics_engine = arcade.PhysicsEnginePlatformer(
self.player_sprite, self.layers[0], gravity_constant=GRAVITY)
def on_draw(self):
super().on_draw()
self.frame_count += 1
self.player_list.draw()
if self.frame_count == 20:
print(self.player_sprite.center_x, self.player_sprite.center_y)
def update(self, delta_time):
self.physics_engine.update()
window = CollisionTestWindow(
SCREEN_WIDTH,
SCREEN_HEIGHT,
"Test Text",
"../arcade/arcade/examples/map_polyline_collision.tmx"
)
arcade.run()

1
test/config.py Normal file
View File

@@ -0,0 +1 @@
MAP_NAME = 'assets/tiled_test_4.tmx'

1
test/foo.py Normal file

File diff suppressed because one or more lines are too long

23
test/output.py Normal file
View File

@@ -0,0 +1,23 @@
hi
{ 'background_color': None,
'height': 10,
'hex_side_length': None,
'infinite': False,
'layers': [ Layer(width=10, height=10, data=[[9, 10, 11, 12, 13, 14, 15, 16, 30, 30], [17, 18, 19, 20, 21, 22, 23, 24, 30, 30], [25, 26, 27, 28, 29, 30, 31, 32, 30, 30], [33, 34, 35, 36, 37, 38, 39, 40, 30, 30], [41, 42, 43, 44, 45, 46, 47, 48, 30, 30], [30, 30, 30, 30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30, 30, 30, 30], [30, 30, 30, 30, 30, 30, 30, 30, 30, 30]], id=1, name='Tile Layer 1', offset=OrderedPair(x=0, y=0), opacity=255, properties=None),
Layer(width=10, height=10, data=[[0, 0, 0, 0, 0, 0, 46, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 6, 7, 7, 7, 7, 7, 8, 0], [0, 0, 14, 15, 15, 15, 15, 15, 16, 0]], id=2, name='Tile Layer 2', offset=OrderedPair(x=0, y=0), opacity=128, properties=None),
None,
ObjectGroup(objects=[Object(id=1, location=OrderedPair(x=200.25, y=210.75), size=OrderedPair(x=47.25, y=25.0), rotation=15, opacity=255, name='rectangle 1', type=None, properties=None, template=None), Object(id=2, location=OrderedPair(x=252.5, y=87.75), size=OrderedPair(x=0, y=0), rotation=-21, opacity=255, name='polygon 1', type=None, properties=None, template=None), Object(id=3, location=OrderedPair(x=198.75, y=102.5), size=OrderedPair(x=17.75, y=14.25), rotation=0, opacity=255, name='elipse 1', type=None, properties=None, template=None), Object(id=4, location=OrderedPair(x=174.25, y=186.0), size=OrderedPair(x=0, y=0), rotation=0, opacity=255, name='point 1', type=None, properties=None, template=None), Object(id=7, location=OrderedPair(x=11.3958, y=48.5833), size=OrderedPair(x=107.625, y=27.25), rotation=0, opacity=255, name='insert text 1', type=None, properties=None, template=None), Object(id=6, location=OrderedPair(x=47.25, y=72.5), size=OrderedPair(x=47.0, y=53.0), rotation=31, opacity=255, name='inserted tile 1', type=None, properties={'tile property bool': True}, template=None), Object(id=8, location=OrderedPair(x=144.667, y=112.0), size=OrderedPair(x=0, y=0), rotation=0, opacity=255, name='polyline 1', type=None, properties=None, template=None), Object(id=9, location=OrderedPair(x=69.8333, y=168.333), size=OrderedPair(x=0, y=0), rotation=0, opacity=255, name='polygon 2', type=None, properties=None, template=None)], id=6, name='Object Layer 1', offset=OrderedPair(x=0, y=0), opacity=230, properties=None, color=None, draworder='topdown')],
'next_layer_id': 16,
'next_object_id': 10,
'orientation': 'orthogonal',
'parent_dir': PosixPath('/home/ben/Projects/arcade/arcade-venv/arcade/tests/test_data'),
'properties': None,
'render_order': 'right-down',
'stagger_axis': None,
'stagger_index': None,
'tile_height': 32,
'tile_sets': { 1: TileSet(name='tile_set_image', max_tile_size=OrderedPair(x=32, y=32), spacing=1, margin=1, tile_count=48, columns=8, tile_offset=None, grid=None, properties=None, image=Image(source='images/tmw_desert_spacing.png', trans=None, width=265, height=199), terrain_types=None, tiles={})},
'tile_width': 32,
'tiled_version': '1.2.3',
'version': '1.2',
'width': 10}

27
test/test2.py Normal file
View File

@@ -0,0 +1,27 @@
import arcade
import config
from arcade.tiled import read_tiled_map
class MyTestWindow(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.map = arcade.generate_sprites(my_map, "Tile Layer 1", 1, "./assets/")
def on_draw(self):
arcade.start_render()
self.map.draw()
MAP_NAME = 'assets/tiled_test_4.tmx'
my_map = arcade.read_tiled_map(config.MAP_NAME, 1)
for row in my_map.layers["Tile Layer 1"]:
for grid_object in row:
print(grid_object)
print(
f"{grid_object.tile.local_id}, {grid_object.center_x}, {grid_object.center_y}")
test = MyTestWindow(640,800,"meme")
test.test()
test.close()

28
test/test_tiled-bak.py Normal file
View File

@@ -0,0 +1,28 @@
import arcade
import arcade.tiled
import pprint
pp = pprint.PrettyPrinter(indent=4, compact=True, width=200)
class MyTestWindow(arcade.Window):
def __init__(self, width, height, title, map_name):
super().__init__(width, height, title)
self.layers = []
my_map = arcade.tiled.read_tiled_map(map_name, 1)
pp.pprint(my_map.layers_int_data)
for layer in my_map.layers_int_data:
self.layers.append(arcade.tiled.generate_sprites(
my_map, layer, 1, "../arcade/arcade/examples/"))
def on_draw(self):
arcade.start_render()
for layer in self.layers:
layer.draw()
MAP_NAME = '../arcade/arcade/examples/map_base64_gzip.tmx'
test = MyTestWindow(640, 800, "meme", MAP_NAME)
arcade.run()

18
test/test_tiled.py Normal file
View File

@@ -0,0 +1,18 @@
import pprint
import pickle
from io import StringIO
import arcade
import arcade.tiled
pp = pprint.PrettyPrinter(indent=4, compact=True, width=100)
pp = pp.pprint
MAP_NAME = '/home/ben/Projects/arcade/arcade-venv/arcade/tests/test_data/test_map_image_tile_set.tmx'
map = arcade.tiled.parse_tile_map(MAP_NAME)
pp(map.__dict__)

3
tests/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
import pytest
pytest.main(["-x", "tests/unit2"])

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="32" tileheight="32" infinite="0" nextlayerid="16" nextobjectid="10">
<tileset firstgid="1" source="tile_set_image.tsx"/>
<layer id="1" name="Tile Layer 1" width="10" height="10">
<data encoding="csv">
1,2,3,4,5,6,7,8,30,30,
9,10,11,12,13,14,15,16,30,30,
17,18,19,20,21,22,23,24,30,30,
25,26,27,28,29,30,31,32,30,30,
33,34,35,36,37,38,39,40,30,30,
41,42,43,44,45,46,47,48,30,30,
30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30
</data>
</layer>
<layer id="2" name="Tile Layer 2" width="10" height="10" opacity="0.5">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,46,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,6,7,7,7,7,7,8,0,
0,0,14,15,15,15,15,15,16,0,
0,0,22,23,23,23,23,23,24,0
</data>
</layer>
<group id="3" name="Group 1">
<properties>
<property name="bool property" type="bool" value="true"/>
</properties>
<layer id="5" name="Tile Layer 4" width="10" height="10" offsetx="49" offsety="-50">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,31,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="4" name="Tile Layer 3" width="10" height="10">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
1,2,3,0,0,0,0,0,0,0,
9,10,11,0,0,0,0,0,0,0,
17,18,19,0,0,0,0,0,0,0
</data>
</layer>
</group>
<objectgroup color="#000000" draworder="index" id="6" name="Object Layer 1" opacity="0.9" offsetx="4.66667" offsety="-4.33333">
<object id="1" name="rectangle 1" type="rectangle type" x="200.25" y="210.75" width="47.25" height="25" rotation="15"/>
<object id="2" name="polygon 1" type="polygon type" x="252.5" y="87.75" rotation="-21">
<polygon points="0,0 -41.25,24.25 -11,67.25 25.75,39.75 -9,37.75"/>
</object>
<object id="3" name="elipse 1" type="elipse type" x="198.75" y="102.5" width="17.75" height="14.25">
<ellipse/>
</object>
<object id="4" name="point 1" type="point type" x="174.25" y="186">
<point/>
</object>
<object id="7" name="insert text 1" type="insert text type" x="11.3958" y="48.5833" width="107.625" height="27.25">
<text fontfamily="Sans Serif" pixelsize="17" wrap="1" color="#b40303" italic="1" underline="1" strikeout="1">Hello World</text>
</object>
<object id="6" name="inserted tile 1" type="inserted tile type" gid="3221225503" x="47.25" y="72.5" width="47" height="53" rotation="31">
<properties>
<property name="tile property bool" type="bool" value="true"/>
</properties>
</object>
<object id="8" name="polyline 1" type="polyline type" x="144.667" y="112">
<polyline points="0,0 -14.3333,35.6667 15.3333,18.3333"/>
</object>
<object id="9" name="polygon 2" type="polygon type" x="69.8333" y="168.333">
<polygon points="-3.25,-17.25 -15,10.75 20.75,4.5"/>
</object>
</objectgroup>
</map>

View File

@@ -0,0 +1,390 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="8" height="6" tilewidth="32" tileheight="32" infinite="1" nextlayerid="3" nextobjectid="1">
<tileset firstgid="1" source="tile_set_image.tsx"/>
<layer id="1" name="Tile Layer 1" width="8" height="6">
<data encoding="csv">
<chunk x="-32" y="-32" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="-16" y="-32" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="0" y="-32" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="16" y="-32" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="-32" y="-16" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="-16" y="-16" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,1,2,3,
30,30,30,30,30,30,30,30,30,30,30,30,30,9,10,11,
30,30,30,30,30,30,30,30,30,30,30,30,30,17,18,19
</chunk>
<chunk x="0" y="-16" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
4,5,6,7,8,30,30,30,30,30,30,30,30,30,30,30,
12,13,14,15,16,30,30,30,30,30,30,30,30,30,30,30,
20,21,22,23,24,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="16" y="-16" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="-32" y="0" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="-16" y="0" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,25,26,27,
30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,35,
30,30,30,30,30,30,30,30,30,30,30,30,30,41,42,43,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="0" y="0" width="16" height="16">
28,29,30,31,32,30,30,30,30,30,30,30,30,30,30,30,
36,37,38,39,40,30,30,30,30,30,30,30,30,30,30,30,
44,45,46,47,48,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="16" y="0" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="-32" y="16" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="-16" y="16" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="0" y="16" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
<chunk x="16" y="16" width="16" height="16">
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30
</chunk>
</data>
</layer>
<layer id="2" name="Tile Layer 2" width="8" height="6">
<data encoding="csv">
<chunk x="-32" y="-16" width="16" height="16">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,20,21,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,29,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</chunk>
<chunk x="16" y="-16" width="16" height="16">
0,0,20,21,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,28,29,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</chunk>
<chunk x="-16" y="0" width="16" height="16">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
20,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</chunk>
<chunk x="16" y="0" width="16" height="16">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
20,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
28,29,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</chunk>
<chunk x="-16" y="16" width="16" height="16">
28,29,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</chunk>
</data>
</layer>
</map>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
<properties>
<property name="bool property - false" type="bool" value="false"/>
<property name="bool property - true" type="bool" value="true"/>
<property name="color property" type="color" value="#ff49fcff"/>
<property name="file property" type="file" value="/var/log/syslog"/>
<property name="float property" type="float" value="1.23456789"/>
<property name="int property" type="int" value="13"/>
<property name="string property" value="Hello, World!!"/>
</properties>
<tileset firstgid="1" source="tile_set_image.tsx"/>
<layer id="1" name="Tile Layer 1" width="8" height="6">
<data encoding="csv">
1,2,3,4,5,6,7,8,
9,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,
33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48
</data>
</layer>
</map>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.2" tiledversion="1.2.3" name="tile_set_image" tilewidth="32" tileheight="32" spacing="1" margin="1" tilecount="48" columns="8">
<image source="images/tmw_desert_spacing.png" width="265" height="199"/>
</tileset>

View File

@@ -0,0 +1,83 @@
import os
from pathlib import Path
import pytest
import pytiled_parser
print(os.path.dirname(os.path.abspath(__file__)))
os.chdir(os.path.dirname(os.path.abspath(__file__)))
def test_map_simple():
"""
TMX with a very simple tileset and some properties.
"""
map = pytiled_parser.parse_tile_map(Path("../test_data/test_map_simple.tmx"))
properties = {
"bool property - false": False,
"bool property - true": True,
"color property": (0x49, 0xfc, 0xff, 0xff),
"file property": Path("/var/log/syslog"),
"float property": 1.23456789,
"int property": 13,
"string property": "Hello, World!!"
}
assert map.version == "1.2"
assert map.tiled_version == "1.2.3"
assert map.orientation == "orthogonal"
assert map.render_order == "right-down"
assert map.width == 8
assert map.height == 6
assert map.tile_width == 32
assert map.tile_height == 32
assert map.infinite == False
assert map.hex_side_length == None
assert map.stagger_axis == None
assert map.stagger_index == None
assert map.background_color == None
assert map.next_layer_id == 2
assert map.next_object_id == 1
assert map.properties == properties
assert map.tile_sets[1].name == "tile_set_image"
assert map.tile_sets[1].tilewidth == 32
assert map.tile_sets[1].tileheight == 32
assert map.tile_sets[1].spacing == 1
assert map.tile_sets[1].margin == 1
assert map.tile_sets[1].tilecount == 48
assert map.tile_sets[1].columns == 8
assert map.tile_sets[1].tileoffset == None
assert map.tile_sets[1].grid == None
assert map.tile_sets[1].properties == None
assert map.tile_sets[1].terraintypes == None
assert map.tile_sets[1].tiles == {}
# unsure how to get paths to compare propperly
assert str(map.tile_sets[1].image.source) == (
"images/tmw_desert_spacing.png")
assert map.tile_sets[1].image.trans == None
assert map.tile_sets[1].image.width == 265
assert map.tile_sets[1].image.height == 199
# assert map.layers ==
@pytest.mark.parametrize(
"test_input,expected", [
("#001122", (0x00, 0x11, 0x22, 0xff)),
("001122", (0x00, 0x11, 0x22, 0xff)),
("#FF001122", (0x00, 0x11, 0x22, 0xff)),
("FF001122", (0x00, 0x11, 0x22, 0xff)),
("FF001122", (0x00, 0x11, 0x22, 0xff)),
]
)
def test_color_parsing(test_input, expected):
"""
Tiled has a few different types of color representations.
"""
assert pytiled_parser._parse_color(test_input) == expected