-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJSTileMap.h
193 lines (144 loc) · 5.83 KB
/
JSTileMap.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//
// JSTileMap.h
// TMXMapSample
//
// Created by Jeremy on 6/11/13.
// Copyright (c) 2013 Jeremy. All rights reserved.
//
#import <SpriteKit/SpriteKit.h>
#import <Foundation/Foundation.h>
#import "LFCGzipUtility.h"
enum
{
TMXLayerAttributeNone = 1 << 0,
TMXLayerAttributeBase64 = 1 << 1,
TMXLayerAttributeGzip = 1 << 2,
TMXLayerAttributeZlib = 1 << 3,
};
typedef enum
{
TMXPropertyNone,
TMXPropertyMap,
TMXPropertyLayer,
TMXPropertyObjectGroup,
TMXPropertyObject,
TMXPropertyTile,
TMXPropertyImageLayer
} PropertyType;
typedef enum
{
kTileDiagonalFlag = 0x20000000,
kTileVerticalFlag = 0x40000000,
kTileHorizontalFlag = 0x80000000,
kFlippedAll = (kTileHorizontalFlag | kTileVerticalFlag | kTileDiagonalFlag),
kFlippedMask = ~(kFlippedAll),
} TMXTileFlags;
typedef enum
{
OrientationStyle_Orthogonal,
OrientationStyle_Isometric
} OrientationStyle;
@interface TMXTilesetInfo : NSObject <NSCoding>
@property (readonly, nonatomic) NSString* name;
@property (readonly, nonatomic) NSUInteger firstGid;
@property (readonly, nonatomic) CGSize tileSize;
@property (readonly, nonatomic) CGSize unitTileSize;
@property (readonly, nonatomic) NSUInteger spacing;
@property (readonly, nonatomic) NSUInteger margin;
@property (readonly, nonatomic) NSString* sourceImage;
@property (readonly, nonatomic) CGSize imageSize;
@property (readonly, nonatomic) NSInteger atlasTilesPerRow;
@property (readonly, nonatomic) NSInteger atlasTilesPerCol;
@property (readonly, nonatomic) SKTexture* atlasTexture;
-(instancetype)initWithGid:(NSInteger)gid attributes:(NSDictionary*)attributes;
-(void)setSourceImage:(NSString *)sourceImage;
-(NSInteger)rowFromGid:(NSInteger)gid;
-(NSInteger)colFromGid:(NSInteger)gid;
-(SKTexture*)textureForGid:(NSInteger)gid;
/** Given the location of the upper left corner of a tile in this tileset,
returns a new SKTexture for that tile. */
-(SKTexture*)textureAtPoint:(CGPoint)p;
@end
@class TMXLayer;
@interface TMXLayerInfo : NSObject <NSCoding>
@property (strong, nonatomic) NSString *name;
@property (assign, nonatomic) CGSize layerGridSize;
@property (assign, nonatomic) NSInteger* tiles;
@property (assign, nonatomic) BOOL visible;
@property (assign, nonatomic) CGFloat opacity;
@property (assign, nonatomic) NSUInteger minGID;
@property (assign, nonatomic) NSUInteger maxGID;
@property (strong, nonatomic) NSMutableDictionary *properties;
@property (assign, nonatomic) CGPoint offset;
@property (assign, nonatomic) TMXLayer* layer;
-(NSInteger)tileGidAtCoord:(CGPoint)coord;
@end
@interface TMXImageLayer : NSObject <NSCoding>
@property (strong, nonatomic) NSString* name;
@property (strong, nonatomic) NSMutableDictionary *properties;
@property (strong, nonatomic) NSString* imageSource;
//@property (strong, nonatomic) NSString* transparencyColor; // Will maybe support this in the future. I think this is what the "trans" property is...
@end
@interface TMXObjectGroup : NSObject <NSCoding>
@property (strong, nonatomic) NSString *groupName;
@property (assign, nonatomic) CGPoint positionOffset;
@property (strong, nonatomic) NSMutableArray *objects;
@property (strong, nonatomic) NSMutableDictionary *properties;
- (NSDictionary *)objectNamed:(NSString *)objectName; // returns the first object with the specified name. Nil, if no object matches
- (NSArray *)objectsNamed:(NSString *)objectName; // returns an NSArray of objects with the specified name
- (id)propertyNamed:(NSString *)propertyName; // returns the property with the specified name
@end
@class JSTileMap;
@interface TMXLayer : SKNode
@property (strong, nonatomic) TMXLayerInfo* layerInfo;
@property (strong, nonatomic) NSMutableSet* tileInfo; // contains TMXTilesetInfo objects
@property (assign, nonatomic) CGSize mapTileSize;
/** Returns the width of the layer (layerGridSize.width * mapTileSize.width) */
@property (readonly,nonatomic) CGFloat layerWidth;
/** Returns the height of the layer (layerGridSize.height * mapTileSize.height) */
@property (readonly,nonatomic) CGFloat layerHeight;
/** Returns the JSTileMap that contains this layer */
@property (weak, nonatomic) JSTileMap* map;
- (CGPoint)pointForCoord:(CGPoint)coord;
- (CGPoint)coordForPoint:(CGPoint)point;
- (void)removeTileAtCoord:(CGPoint)coord;
- (SKSpriteNode*)tileAt:(CGPoint)point;
- (SKSpriteNode*)tileAtCoord:(CGPoint)coord;
- (NSInteger)tileGidAt:(CGPoint)point;
- (id) propertyWithName:(NSString*)name;
- (NSDictionary*)properties;
@end
@interface JSTileMap : SKNode <NSXMLParserDelegate>
@property (assign, nonatomic) CGSize mapSize;
@property (assign, nonatomic) CGSize tileSize;
@property (assign, nonatomic) PropertyType parentElement;
@property (assign, nonatomic) NSInteger parentGID;
@property (assign, nonatomic) NSUInteger orientation;
// minimum and maximum range of zPositioning of the map.
@property (readonly) CGFloat minZPositioning;
@property (readonly) CGFloat maxZPositioning;
// tmx filename
@property (strong, nonatomic) NSString *filename;
// tmx resource path
@property (strong, nonatomic) NSString *resources;
// tilesets
@property (strong, nonatomic) NSMutableArray* tilesets;
// tile properties
@property (strong, nonatomic) NSMutableDictionary* tileProperties;
// properties
@property (strong, nonatomic) NSMutableDictionary* properties;
// layers
@property (strong, nonatomic) NSMutableArray* layers;
// image layers
@property (strong, nonatomic) NSMutableArray* imageLayers;
// object groups
@property (strong, nonatomic) NSMutableArray* objectGroups;
// xml tile gids
@property (strong, nonatomic) NSMutableArray* gidData;
+ (JSTileMap*)mapNamed:(NSString*)mapName;
+ (JSTileMap*)mapNamed:(NSString*)mapName withBaseZPosition:(CGFloat)baseZPosition andZOrderModifier:(CGFloat)zOrderModifier;
-(TMXLayer*)layerNamed:(NSString*)name;
-(TMXObjectGroup*)groupNamed:(NSString*)name;
-(TMXTilesetInfo*)tilesetInfoForGid:(NSInteger)gID;
-(NSDictionary*)propertiesForGid:(NSInteger)gID;
@end