@@ -39,7 +39,7 @@ TileSetParser::TileSetParser(TileSet& tileset, const std::string& filename) :
39
39
}
40
40
41
41
void
42
- TileSetParser::parse ()
42
+ TileSetParser::parse (uint32_t start, uint32_t end, int32_t offset )
43
43
{
44
44
m_tiles_path = FileSystem::dirname (m_filename);
45
45
@@ -56,11 +56,13 @@ TileSetParser::parse()
56
56
if (iter.get_key () == " tile" )
57
57
{
58
58
ReaderMapping tile_mapping = iter.as_mapping ();
59
- parse_tile (tile_mapping);
59
+ parse_tile (tile_mapping, start, end, offset );
60
60
}
61
61
else if (iter.get_key () == " tilegroup" )
62
62
{
63
63
/* tilegroups are only interesting for the editor */
64
+ /* ignore tilegroups for imported tilesets */
65
+ if (end) continue ;
64
66
ReaderMapping reader = iter.as_mapping ();
65
67
Tilegroup tilegroup;
66
68
reader.get (" name" , tilegroup.name );
@@ -70,10 +72,12 @@ TileSetParser::parse()
70
72
else if (iter.get_key () == " tiles" )
71
73
{
72
74
ReaderMapping tiles_mapping = iter.as_mapping ();
73
- parse_tiles (tiles_mapping);
75
+ parse_tiles (tiles_mapping, start, end, offset );
74
76
}
75
77
else if (iter.get_key () == " autotileset" )
76
78
{
79
+ /* ignore autotiles for imported tilesets */
80
+ if (end) continue ;
77
81
ReaderMapping reader = iter.as_mapping ();
78
82
std::string autotile_filename;
79
83
if (!reader.get (" source" , autotile_filename))
@@ -87,25 +91,41 @@ TileSetParser::parse()
87
91
parser->parse ();
88
92
}
89
93
}
94
+ else if (iter.get_key () == " import-tileset" )
95
+ {
96
+ ReaderMapping reader = iter.as_mapping ();
97
+ std::string import_filename;
98
+ uint32_t start = 0 , end = 0 ;
99
+ int32_t offset = 0 ;
100
+ reader.get (" file" , import_filename);
101
+ reader.get (" start" , start);
102
+ reader.get (" end" , end);
103
+ reader.get (" offset" , offset);
104
+ TileSetParser import_parser (m_tileset, import_filename);
105
+ import_parser.parse (start, end, offset);
106
+ }
90
107
else
91
108
{
92
109
log_warning << " Unknown symbol '" << iter.get_key () << " ' in tileset file" << std::endl;
93
110
}
94
111
}
95
- if (g_config->developer_mode )
112
+ /* only create the unassigned tilegroup from the parent strf */
113
+ if (g_config->developer_mode && !end)
96
114
{
97
115
m_tileset.add_unassigned_tilegroup ();
98
116
}
99
117
}
100
118
101
119
void
102
- TileSetParser::parse_tile (const ReaderMapping& reader)
120
+ TileSetParser::parse_tile (const ReaderMapping& reader, uint32_t min, uint32_t max, int32_t offset )
103
121
{
104
122
uint32_t id;
105
123
if (!reader.get (" id" , id))
106
124
{
107
125
throw std::runtime_error (" Missing tile-id." );
108
126
}
127
+ if (max && (id < min || id > max)) return ;
128
+ id += offset;
109
129
110
130
uint32_t attributes = 0 ;
111
131
@@ -182,7 +202,7 @@ TileSetParser::parse_tile(const ReaderMapping& reader)
182
202
}
183
203
184
204
void
185
- TileSetParser::parse_tiles (const ReaderMapping& reader)
205
+ TileSetParser::parse_tiles (const ReaderMapping& reader, uint32_t min, uint32_t max, int32_t offset )
186
206
{
187
207
// List of ids (use 0 if the tile should be ignored)
188
208
std::vector<uint32_t > ids;
@@ -271,65 +291,65 @@ TileSetParser::parse_tiles(const ReaderMapping& reader)
271
291
272
292
for (size_t i = 0 ; i < ids.size (); ++i)
273
293
{
274
- if ( ids[i] != 0 )
275
- {
276
- const int x = static_cast < int >( 32 * (i % width));
277
- const int y = static_cast <int >(32 * (i / width));
278
-
279
- std::vector<SurfacePtr> regions;
280
- regions. reserve (surfaces. size ()) ;
281
- std::transform (surfaces. begin (), surfaces.end (), std::back_inserter (regions),
282
- [x, y] ( const SurfacePtr& surface) {
283
- return surface-> region ( Rect ( x, y, Size ( 32 , 32 )));
284
- } );
285
-
286
- std::vector<SurfacePtr> editor_regions;
287
- editor_regions. reserve (editor_surfaces. size ()) ;
288
- std::transform (editor_surfaces. begin (), editor_surfaces.end (), std::back_inserter (editor_regions),
289
- [x, y] ( const SurfacePtr& surface) {
290
- return surface-> region ( Rect ( x, y, Size ( 32 , 32 )));
291
- } );
292
-
293
- auto tile = std::make_unique<Tile>(regions,
294
- editor_regions ,
295
- (has_attributes ? attributes[i] : 0 ) ,
296
- (has_datas ? datas [i] : 0 ),
297
- fps);
298
-
299
- m_tileset. add_tile (ids[i], std::move (tile));
300
- }
294
+ if (!ids[i] || (max && ( ids[i] < min || ids[i] > max))) continue ;
295
+ ids[i] += offset;
296
+
297
+ const int x = static_cast <int >(32 * (i % width));
298
+ const int y = static_cast < int >( 32 * (i / width));
299
+
300
+ std::vector<SurfacePtr> regions;
301
+ regions. reserve ( surfaces.size ());
302
+ std::transform (surfaces. begin (), surfaces. end (), std::back_inserter (regions),
303
+ [ x, y] ( const SurfacePtr& surface) {
304
+ return surface-> region ( Rect (x, y, Size ( 32 , 32 )) );
305
+ });
306
+
307
+ std::vector<SurfacePtr> editor_regions;
308
+ editor_regions. reserve ( editor_surfaces.size ());
309
+ std::transform (editor_surfaces. begin (), editor_surfaces. end (), std::back_inserter (editor_regions),
310
+ [ x, y] ( const SurfacePtr& surface) {
311
+ return surface-> region ( Rect (x, y, Size ( 32 , 32 )) );
312
+ });
313
+
314
+ auto tile = std::make_unique<Tile>(regions ,
315
+ editor_regions ,
316
+ (has_attributes ? attributes [i] : 0 ),
317
+ (has_datas ? datas[i] : 0 ),
318
+ fps);
319
+
320
+ m_tileset. add_tile (ids[i], std::move (tile));
301
321
}
302
322
}
303
323
else // (!shared_surface)
304
324
{
305
325
for (size_t i = 0 ; i < ids.size (); ++i)
306
326
{
307
- if (ids[i] != 0 )
308
- {
309
- int x = static_cast <int >(32 * (i % width));
310
- int y = static_cast <int >(32 * (i / width));
311
-
312
- std::vector<SurfacePtr> surfaces;
313
- boost::optional<ReaderMapping> surfaces_mapping;
314
- if (reader.get (" image" , surfaces_mapping) ||
315
- reader.get (" images" , surfaces_mapping)) {
316
- surfaces = parse_imagespecs (*surfaces_mapping, Rect (x, y, Size (32 , 32 )));
317
- }
318
-
319
- std::vector<SurfacePtr> editor_surfaces;
320
- boost::optional<ReaderMapping> editor_surfaces_mapping;
321
- if (reader.get (" editor-images" , editor_surfaces_mapping)) {
322
- editor_surfaces = parse_imagespecs (*editor_surfaces_mapping, Rect (x, y, Size (32 , 32 )));
323
- }
324
-
325
- auto tile = std::make_unique<Tile>(surfaces,
326
- editor_surfaces,
327
- (has_attributes ? attributes[i] : 0 ),
328
- (has_datas ? datas[i] : 0 ),
329
- fps);
330
-
331
- m_tileset.add_tile (ids[i], std::move (tile));
327
+ if (!ids[i] || (max && (ids[i] < min || ids[i] > max))) continue ;
328
+ ids[i] += offset;
329
+
330
+ int x = static_cast <int >(32 * (i % width));
331
+ int y = static_cast <int >(32 * (i / width));
332
+
333
+ std::vector<SurfacePtr> surfaces;
334
+ boost::optional<ReaderMapping> surfaces_mapping;
335
+ if (reader.get (" image" , surfaces_mapping) ||
336
+ reader.get (" images" , surfaces_mapping)) {
337
+ surfaces = parse_imagespecs (*surfaces_mapping, Rect (x, y, Size (32 , 32 )));
338
+ }
339
+
340
+ std::vector<SurfacePtr> editor_surfaces;
341
+ boost::optional<ReaderMapping> editor_surfaces_mapping;
342
+ if (reader.get (" editor-images" , editor_surfaces_mapping)) {
343
+ editor_surfaces = parse_imagespecs (*editor_surfaces_mapping, Rect (x, y, Size (32 , 32 )));
332
344
}
345
+
346
+ auto tile = std::make_unique<Tile>(surfaces,
347
+ editor_surfaces,
348
+ (has_attributes ? attributes[i] : 0 ),
349
+ (has_datas ? datas[i] : 0 ),
350
+ fps);
351
+
352
+ m_tileset.add_tile (ids[i], std::move (tile));
333
353
}
334
354
}
335
355
}
0 commit comments