Skip to content
Browse files

fix some typos and clean whitespace

  • Loading branch information...
1 parent 9bb839b commit dca385bac009757d6f0ac2e7c2cb504e7f3ad4ed Michael Cotterall committed Jul 16, 2012
Showing with 60 additions and 60 deletions.
  1. +16 −16 pytmx/pytmx.py
  2. +5 −5 pytmx/tmxloader.py
  3. +17 −17 pytmx/tmxloader3.py
  4. +15 −15 pytmx/utils.py
  5. +4 −4 tests/demo.py
  6. +3 −3 tests/test.py
View
32 pytmx/pytmx.py
@@ -1,6 +1,6 @@
from itertools import chain, product
from xml.etree import ElementTree
-from collections import defaultdict
+from collections import defaultdict
from utils import decode_gid, types, parse_properties, read_points
from constants import *
@@ -21,7 +21,7 @@ def set_properties(self, node):
"""
# set the attributes reserved for tiled
- [ setattr(self, k, types[str(k)](v)) for (k,v) in node.items() ]
+ [ setattr(self, k, types[str(k)](v)) for (k,v) in node.items() ]
# set the attributes that are derived from tiled 'properties'
for k,v in parse_properties(node).items():
@@ -58,7 +58,7 @@ def __init__(self, filename=None):
self.layernames = {}
# only used tiles are actually loaded, so there will be a difference
- # between the GID's in the Tile map data (tmx) and the data in this
+ # between the GIDs in the Tile map data (tmx) and the data in this
# class and the layers. This dictionary keeps track of that difference.
self.gidmap = defaultdict(list)
@@ -199,7 +199,7 @@ def getTileLocation(self, gid):
xrange(self.height),
xrange(len(self.tilelayers)))
- return [ (x,y,l) for (x,y,l) in p
+ return [ (x,y,l) for (x,y,l) in p
if self.tilelayers[l].data[y][x] == gid ]
@@ -243,15 +243,15 @@ def getTilePropertiesByLayer(self, layer):
props.append((gid, self.tile_properties[gid]))
except:
continue
-
+
return props
def registerGID(self, real_gid, flags=0):
"""
used to manage the mapping of GID between the tmx data and the internal
data.
-
+
number returned is gid used internally
"""
@@ -282,7 +282,7 @@ def mapGID(self, real_gid):
except KeyError:
return None
except TypeError:
- msg = "GID's must be an integer"
+ msg = "GIDs must be an integer"
raise TypeError, msg
@@ -356,8 +356,8 @@ def getTileLayerOrder(self):
def visibleTileLayers(self):
"""
Returns a list of TileLayer objects that are set 'visible'.
-
- Layers have their visivility set in Tiled. Optionally, you can over-
+
+ Layers have their visibility set in Tiled. Optionally, you can over-
ride the Tiled visibility by creating a property named 'visible'.
"""
@@ -418,7 +418,7 @@ def parse(self, node):
else:
msg = "Found external tileset, but cannot handle type: {0}"
raise Exception, msg.format(self.source)
-
+
self.set_properties(node)
# since tile objects [probably] don't have a lot of metadata,
@@ -449,7 +449,7 @@ def __init__(self, parent, node):
self.name = None
self.opacity = 1.0
self.visible = True
-
+
self.parse(node)
@@ -502,7 +502,7 @@ def parse(self, node):
elif compression:
msg = "TMX compression type: {0} is not supported."
raise Exception, msg.format(str(attr["compression"]))
-
+
# if data is None, then it was not decoded or decompressed, so
# we assume here that it is going to be a bunch of tile elements
# TODO: this will probably raise an exception if there are no tiles
@@ -514,13 +514,13 @@ def get_children(parent):
next_gid = get_children(data_node)
elif data:
- # data is a list of gid's. cast as 32-bit ints to format properly
+ # data is a list of gids. cast as 32-bit ints to format properly
# create iterator to efficiently parse data
next_gid=imap(lambda i:unpack("<L", "".join(i))[0], group(data, 4))
# using bytes here limits the layer to 256 unique tiles
# may be a limitation for very detailed maps, but most maps are not
- # so detailed.
+ # so detailed.
[ self.data.append(array.array("B")) for i in xrange(self.height) ]
for (y, x) in product(xrange(self.height), xrange(self.width)):
@@ -599,7 +599,7 @@ def parse(self, node):
if x > x2: x2 = x
if y < y1: y1 = y
if y > y2: y2 = y
- self.width = abs(x1) + abs(x2)
+ self.width = abs(x1) + abs(x2)
self.height = abs(y1) + abs(y2)
polyline = node.find('polyline')
@@ -612,7 +612,7 @@ def parse(self, node):
if x > x2: x2 = x
if y < y1: y1 = y
if y > y2: y2 = y
- self.width = abs(x1) + abs(x2)
+ self.width = abs(x1) + abs(x2)
self.height = abs(y1) + abs(y2)
View
10 pytmx/tmxloader.py
@@ -87,9 +87,9 @@
I have been intentionally not including a module rendering utility since
rendering a map will have different requirements for every situation. However,
-I can appreciate that some poeple won't understand how it works unless they see
+I can appreciate that some people won't understand how it works unless they see
it, so I am including a sample map and viewer. It includes a scrolling/zooming
-renderer. They are for demonstation purposes, and may not be suitable for all
+renderer. They are for demonstration purposes, and may not be suitable for all
projects. Use at your own risk.
I've also included a copy of this loader that may work with python 3.x. I
@@ -117,7 +117,7 @@
When you want to draw tiles, you simply call "getTileImage":
- >>> image = tmxdata.getTileImage(x, y, layer)
+ >>> image = tmxdata.getTileImage(x, y, layer)
>>> screen.blit(position, image)
@@ -148,7 +148,7 @@
* The Tiled "properties" have reserved names.
If you use "properties" for any of the following object types, you cannot use
-any of theese words as a name for your property. A ValueError will be raised
+any of these words as a name for your property. A ValueError will be raised
if there are any conflicts.
As of 0.8.1, these values are:
@@ -308,7 +308,7 @@ def handle_transformation(tile, flags):
colorkey = None
if t.trans:
- colorkey = pygame.Color("#{0}".format(t.trans))
+ colorkey = pygame.Color("#{0}".format(t.trans))
# i dont agree with margins and spacing, but i'll support it anyway
# such is life. okay.jpg
View
34 pytmx/tmxloader3.py
@@ -27,7 +27,7 @@
Pygame: test colorkey transparency
Optimized for maps that do not make heavy use of tile
- properties. If i find that it is used a lot then i can rework
+ properties. If I find that it is used a lot then I can rework
it for better performance.
======================================================================
@@ -40,7 +40,7 @@
When you want to draw tiles, you simply call "get_tile_image":
- >>> image = tiledmap.get_tile_image(x, y, layer)
+ >>> image = tiledmap.get_tile_image(x, y, layer)
>>> screen.blit(position, image)
@@ -102,7 +102,7 @@ def __init__(self):
self.width = 0
self.height = 0
self.tilewidth = 0
- self.tileheight = 0
+ self.tileheight = 0
def get_tile_image(self, x, y, layer):
"""
@@ -153,8 +153,8 @@ def getTileImages(self, r, layer):
return a group of tiles in an area
expects a pygame rect or rect-like list/tuple
- usefull if you don't want to repeatedly call get_tile_image
- probably not the most effecient way of doing this, but oh well.
+ useful if you don't want to repeatedly call get_tile_image
+ probably not the most efficient way of doing this, but oh well.
"""
raise NotImplementedError
@@ -217,7 +217,7 @@ def __init__(self):
self.name = None
self.opacity = 1.0
self.visible = 1
-
+
class TiledObjectGroup(TiledElement):
def __init__(self):
TiledElement.__init__(self)
@@ -252,7 +252,7 @@ def load_tmx(filename):
from xml.dom.minidom import parse
from itertools import tee, islice, chain
- from collections import defaultdict
+ from collections import defaultdict
from struct import unpack
import array, os
@@ -283,7 +283,7 @@ def load_tmx(filename):
"y": int,
"value": str,
}
-
+
def pairwise(iterable):
# return a list as a sequence of pairs
a, b = tee(iterable)
@@ -324,7 +324,7 @@ def get_properties(node):
# get vlues of the properties element, if any
d.update(parse_properties(node))
-
+
return d
def set_properties(obj, node):
@@ -349,7 +349,7 @@ def get_attributes(node):
return d
def decode_gid(raw_gid):
- # gid's are encoded with extra information
+ # gids are encoded with extra information
# as of 0.7.0 it determines if the tile should be flipped when rendered
flags = 0
@@ -401,7 +401,7 @@ def parse_tileset(node, firstgid=None):
tileset.firstgid = firstgid
# since tile objects probably don't have a lot of metadata,
- # we store it seperately from the class itself
+ # we store it separately from the class itself
for child in node.childNodes:
if child.nodeName == "tile":
p = get_properties(child)
@@ -439,7 +439,7 @@ def parse_tileset(node, firstgid=None):
y, r = divmod(attr["height"], tileset.tileheight)
tileset.lastgid = tileset.firstgid + x + y
-
+
return tileset, tiles
@@ -470,7 +470,7 @@ def parse_layer(tilesets, node):
elif not attr["encoding"] is None:
raise Exception("TMX encoding type: " + str(attr["encoding"]) + " is not supported.")
-
+
if attr["compression"] == "gzip":
from io import BytesIO
import gzip
@@ -479,7 +479,7 @@ def parse_layer(tilesets, node):
elif not attr["compression"] is None:
raise Exception("TMX compression type: " + str(attr["compression"]) + " is not supported.")
-
+
# if data is None, then it was not decoded or decompressed, so
# we assume here that it is going to be a bunch of tile elements
if attr["encoding"] == next_gid is None:
@@ -496,7 +496,7 @@ def u(i): return unpack("<L", bytes(i))[0]
gids = [ i.firstgid for i in tilesets ]
- # fill up our 2D array of gid's.
+ # fill up our 2D array of gids.
for y in range(layer.height):
# store as 16-bit ints, since we will never use enough tiles to fill a 32-bit int
@@ -557,7 +557,7 @@ def load_pygame(filename):
tile_size = (t.tilewidth, t.tileheight)
# some tileset images may be slightly larger than the tiles area
- # ie: may include a banner, copyright, ect. this compensates for that
+ # ie: may include a banner, copyright, etc. this compensates for that
for y in range(0, int(h / t.tileheight) * t.tileheight, t.tileheight):
for x in range(0, int(w / t.tilewidth) * t.tilewidth, t.tilewidth):
@@ -572,7 +572,7 @@ def load_pygame(filename):
# make a unique id for this image, not sure if this is the best way, but it works
key = pygame.image.tostring(tile, "RGBA")
-
+
# make sure we don't have a duplicate tile
try:
tile = cache[key]
View
30 pytmx/utils.py
@@ -34,7 +34,7 @@ def parse_properties(node):
def decode_gid(raw_gid):
- # gid's are encoded with extra information
+ # gids are encoded with extra information
# as of 0.7.0 it determines if the tile should be flipped when rendered
# as of 0.8.0 bit 30 determines if GID is rotated
@@ -62,11 +62,11 @@ def handle_bool(text):
if text == "no": return False
except:
pass
-
+
raise ValueError
-# used to change the unicode string returned from xml to proper python
+# used to change the unicode string returned from xml to proper python
# variable types.
types = defaultdict(lambda: str)
types.update({
@@ -111,11 +111,11 @@ def group(l, n):
def buildDistributionRects(tmxmap, layer, tileset=None, real_gid=None):
"""
generate a set of non-overlapping rects that represents the distribution
- of the specfied gid.
+ of the specified gid.
useful for generating rects for use in collision detection
"""
-
+
if isinstance(tileset, int):
try:
tileset = tmxmap.tilesets[tileset]
@@ -165,29 +165,29 @@ def buildDistributionRects(tmxmap, layer, tileset=None, real_gid=None):
def simplify(all_points, tilewidth, tileheight):
"""
- klugde:
+ kludge:
"A kludge (or kluge) is a workaround, a quick-and-dirty solution,
a clumsy or inelegant, yet effective, solution to a problem, typically
using parts that are cobbled together."
-- wikipedia
-
- turn a list of points into a rects
+
+ turn a list of points into a rects
adjacent rects will be combined.
plain english:
- the input list must be a a list of tuples that represent
+ the input list must be a list of tuples that represent
the areas to be combined into rects
the rects will be blended together over solid groups
so if data is something like:
- 0 1 1 1 0 0 0
- 0 1 1 0 0 0 0
- 0 0 0 0 0 4 0
+ 0 1 1 1 0 0 0
+ 0 1 1 0 0 0 0
+ 0 0 0 0 0 4 0
0 0 0 0 0 4 0
- 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0
0 0 1 1 1 1 1
you'll have the 4 rects that mask the area like this:
@@ -202,7 +202,7 @@ def simplify(all_points, tilewidth, tileheight):
pretty cool, right?
there may be cases where the number of rectangles is not as low as possible,
- but i haven't found that it is excessively bad. certainly much better than
+ but I haven't found that it is excessively bad. certainly much better than
making a list of rects, one for each tile on the map!
"""
@@ -211,7 +211,7 @@ def pick_rect(points, rects):
ox, oy = sorted([ (sum(p), p) for p in points ])[0][1]
x = ox
y = oy
- ex = None
+ ex = None
while 1:
x += 1
View
8 tests/demo.py
@@ -22,8 +22,8 @@ class TiledRenderer(object):
def __init__(self, filename):
from pytmx import tmxloader
self.tiledmap = tmxloader.load_pygame(filename, pixelalpha=True)
-
-
+
+
def render(self, surface):
# not going for effeciency here
# for demonstration purposes only
@@ -69,7 +69,7 @@ def render(self, surface, (cx, cy)):
th = self.tiledmap.tileheight
gt = self.tiledmap.getTileImage
- stw = int(math.ceil(float(sw) / tw)) + 1
+ stw = int(math.ceil(float(sw) / tw)) + 1
sth = int(math.ceil(float(sh) / th)) + 1
txf, pxf = divmod((cx-sw/2), tw)
@@ -200,7 +200,7 @@ def draw():
center[0] = hsw
movt[0] = 0
elif center[0] > mw - hsw-1:
- center[0] = mw - hsw-1
+ center[0] = mw - hsw-1
movt[0] = 0
else:
center[0] = formosa.width / 2
View
6 tests/test.py
@@ -16,10 +16,10 @@ class TiledRenderer(object):
def __init__(self, filename):
from pytmx import tmxloader
self.tiledmap = tmxloader.load_pygame(filename, pixelalpha=True)
-
-
+
+
def render(self, surface):
- # not going for effeciency here
+ # not going for efficiency here
# for demonstration purposes only
tw = self.tiledmap.tilewidth

0 comments on commit dca385b

Please sign in to comment.
Something went wrong with that request. Please try again.