@@ -39,16 +39,23 @@ TileSetParser::TileSetParser(TileSet& tileset, const std::string& filename) :
39
39
}
40
40
41
41
void
42
- TileSetParser::parse (uint32_t start, uint32_t end, int32_t offset, bool imported)
42
+ TileSetParser::parse (int32_t start, int32_t end, int32_t offset, bool imported)
43
43
{
44
- if (offset && static_cast < int32_t >( start) + offset < 1 ) {
44
+ if (offset && start + offset < 1 ) {
45
45
start = -offset + 1 ;
46
46
log_warning << " The defined offset would assign non-positive ids to tiles, tiles below " << -offset + 1 << " will be ignored." << std::endl;
47
47
}
48
- if (end < start ) {
49
- log_warning << " The defined range has a negative size, no tiles will be imported ." << std::endl;
48
+ if (end < 0 ) {
49
+ log_warning << " Cannot import tiles with negative IDs ." << std::endl;
50
50
return ;
51
51
}
52
+ if (start < 0 ) {
53
+ log_warning << " Cannot import tiles with negative IDs. Importing will start at ID 1." << std::endl;
54
+ start = 1 ;
55
+ }
56
+ if (imported && !end) {
57
+ log_warning << " Importing a tileset with no upper ID limit can cause ID conflicts if the imported tileset is expanded in the future." <<std::endl;
58
+ }
52
59
53
60
m_tiles_path = FileSystem::dirname (m_filename);
54
61
@@ -104,12 +111,22 @@ TileSetParser::parse(uint32_t start, uint32_t end, int32_t offset, bool imported
104
111
{
105
112
ReaderMapping reader = iter.as_mapping ();
106
113
std::string import_filename;
107
- uint32_t import_start = 0 , import_end = 0 ;
108
- int32_t import_offset = 0 ;
114
+ int32_t import_start = 0 , import_end = 0 , import_offset = 0 ;
109
115
reader.get (" file" , import_filename);
110
116
reader.get (" start" , import_start);
111
117
reader.get (" end" , import_end);
112
118
reader.get (" offset" , import_offset);
119
+ if (import_start + import_offset < start) {
120
+ import_start = (start - import_offset) < 0 ? 0 : (start - import_offset);
121
+ }
122
+ if (end && (!import_end || (import_end + import_offset) > end)) {
123
+ import_end = end - import_offset;
124
+ }
125
+ if (import_end < import_start) {
126
+ if (!imported) log_warning << " The defined range has a negative size, no tiles will be imported." << std::endl;
127
+ continue ;
128
+ }
129
+ import_offset += offset;
113
130
TileSetParser import_parser (m_tileset, import_filename);
114
131
import_parser.parse (import_start, import_end, import_offset, true );
115
132
}
@@ -126,14 +143,14 @@ TileSetParser::parse(uint32_t start, uint32_t end, int32_t offset, bool imported
126
143
}
127
144
128
145
void
129
- TileSetParser::parse_tile (const ReaderMapping& reader, uint32_t min, uint32_t max, int32_t offset)
146
+ TileSetParser::parse_tile (const ReaderMapping& reader, int32_t min, int32_t max, int32_t offset)
130
147
{
131
148
uint32_t id;
132
149
if (!reader.get (" id" , id))
133
150
{
134
151
throw std::runtime_error (" Missing tile-id." );
135
152
}
136
- if (max && (id < min || id > max)) return ;
153
+ if (max && (id < static_cast < uint32_t >( min) || id > static_cast < uint32_t >( max) )) return ;
137
154
id += offset;
138
155
139
156
uint32_t attributes = 0 ;
@@ -211,7 +228,7 @@ TileSetParser::parse_tile(const ReaderMapping& reader, uint32_t min, uint32_t ma
211
228
}
212
229
213
230
void
214
- TileSetParser::parse_tiles (const ReaderMapping& reader, uint32_t min, uint32_t max, int32_t offset)
231
+ TileSetParser::parse_tiles (const ReaderMapping& reader, int32_t min, int32_t max, int32_t offset)
215
232
{
216
233
// List of ids (use 0 if the tile should be ignored)
217
234
std::vector<uint32_t > ids;
@@ -300,7 +317,7 @@ TileSetParser::parse_tiles(const ReaderMapping& reader, uint32_t min, uint32_t m
300
317
301
318
for (size_t i = 0 ; i < ids.size (); ++i)
302
319
{
303
- if (!ids[i] || (max && (ids[i] < min || ids[i] > max))) continue ;
320
+ if (!ids[i] || (max && (ids[i] < static_cast < uint32_t >( min) || ids[i] > static_cast < uint32_t >( max) ))) continue ;
304
321
ids[i] += offset;
305
322
306
323
const int x = static_cast <int >(32 * (i % width));
@@ -333,7 +350,7 @@ TileSetParser::parse_tiles(const ReaderMapping& reader, uint32_t min, uint32_t m
333
350
{
334
351
for (size_t i = 0 ; i < ids.size (); ++i)
335
352
{
336
- if (!ids[i] || (max && (ids[i] < min || ids[i] > max))) continue ;
353
+ if (!ids[i] || (max && (ids[i] < static_cast < uint32_t >( min) || ids[i] > static_cast < uint32_t >( max) ))) continue ;
337
354
ids[i] += offset;
338
355
339
356
int x = static_cast <int >(32 * (i % width));
0 commit comments