summary refs log tree commit diff stats
path: root/tools/sprite_dumper
diff options
context:
space:
mode:
Diffstat (limited to 'tools/sprite_dumper')
-rw-r--r--tools/sprite_dumper/tileset_dumper.cpp44
1 files changed, 21 insertions, 23 deletions
diff --git a/tools/sprite_dumper/tileset_dumper.cpp b/tools/sprite_dumper/tileset_dumper.cpp index d8997a5..f09fbd9 100644 --- a/tools/sprite_dumper/tileset_dumper.cpp +++ b/tools/sprite_dumper/tileset_dumper.cpp
@@ -264,15 +264,32 @@ int main(int argc, char** argv) {
264 itemised.push_back(std::move(newLayer)); 264 itemised.push_back(std::move(newLayer));
265 } 265 }
266 266
267 constexpr int TILES_PER_ROW = 10;
268 int sheetWidth;
269 int sheetHeight;
267 270
271 if (metatiles.size() < TILES_PER_ROW) {
272 sheetWidth = metatiles.size() * 16;
273 sheetHeight = 16;
274 } else {
275 sheetWidth = TILES_PER_ROW * 16;
276 sheetHeight = (metatiles.size() / TILES_PER_ROW + 1) * 16;
277 }
268 278
279 // Generate map datafile.
269 std::ofstream mapfile("out.tmx"); 280 std::ofstream mapfile("out.tmx");
270 mapfile << R"(<map version="1.0" orientation="orthogonal" renderorder="right-down" width=")"; 281 mapfile << R"(<map version="1.0" orientation="orthogonal" renderorder="right-down" width=")";
271 mapfile << width; 282 mapfile << width;
272 mapfile << R"(" height=")"; 283 mapfile << R"(" height=")";
273 mapfile << height; 284 mapfile << height;
274 mapfile << R"(" tilewidth="16" tileheight="16">)" << std::endl; 285 mapfile << R"(" tilewidth="16" tileheight="16">)" << std::endl;
275 mapfile << R"( <tileset firstgid="0" source="out.tsx" />)" << std::endl; 286 mapfile << R"( <tileset firstgid="1" name="fromRom" tilewidth="16" tileheight="16" tilecount=")";
287 mapfile << metatiles.size();
288 mapfile << R"(" columns=")";
289 mapfile << TILES_PER_ROW;
290 mapfile << R"(">)" << std::endl;
291 mapfile << R"( <image source="tiles.png" />)" << std::endl;
292 mapfile << R"( </tileset>)" << std::endl;
276 293
277 for (int layer=itemised.size()-1; layer>=0; layer--) { 294 for (int layer=itemised.size()-1; layer>=0; layer--) {
278 mapfile << R"( <layer id=")"; 295 mapfile << R"( <layer id=")";
@@ -294,7 +311,7 @@ int main(int argc, char** argv) {
294 mapfile << ","; 311 mapfile << ",";
295 } 312 }
296 313
297 unsigned int outChar = tu.id; 314 unsigned int outChar = tu.id + 1;
298 if (tu.tflipx) outChar |= 0x80000000; 315 if (tu.tflipx) outChar |= 0x80000000;
299 if (tu.tflipy) outChar |= 0x40000000; 316 if (tu.tflipy) outChar |= 0x40000000;
300 mapfile << outChar; 317 mapfile << outChar;
@@ -306,6 +323,7 @@ int main(int argc, char** argv) {
306 323
307 mapfile << R"(</map>)" << std::endl; 324 mapfile << R"(</map>)" << std::endl;
308 325
326 // Render map to image.
309 for (int layer=itemised.size()-1; layer>=0; layer--) { 327 for (int layer=itemised.size()-1; layer>=0; layer--) {
310 for (int mapy = 0; mapy < height; mapy++) { 328 for (int mapy = 0; mapy < height; mapy++) {
311 for (int mapx = 0; mapx < width; mapx++) { 329 for (int mapx = 0; mapx < width; mapx++) {
@@ -319,27 +337,7 @@ int main(int argc, char** argv) {
319 image.magick("png"); 337 image.magick("png");
320 image.write("out.png"); 338 image.write("out.png");
321 339
322 constexpr int TILES_PER_ROW = 10; 340 // Render tileset image.
323 int sheetWidth;
324 int sheetHeight;
325
326 if (metatiles.size() < TILES_PER_ROW) {
327 sheetWidth = metatiles.size() * 16;
328 sheetHeight = 16;
329 } else {
330 sheetWidth = TILES_PER_ROW * 16;
331 sheetHeight = (metatiles.size() / TILES_PER_ROW + 1) * 16;
332 }
333
334 std::ofstream tilesetfile("out.tsx");
335 tilesetfile << R"(<tileset name="fromRom" tilewidth="16" tileheight="16" tilecount=")";
336 tilesetfile << metatiles.size();
337 tilesetfile << R"(" columns=")";
338 tilesetfile << TILES_PER_ROW;
339 tilesetfile << R"(">)" << std::endl;
340 tilesetfile << R"( <image source="tiles.png" />)" << std::endl;
341 tilesetfile << R"(</tileset>)" << std::endl;
342
343 Magick::Image tilesetImage(Magick::Geometry(sheetWidth, sheetHeight), "transparent"); 341 Magick::Image tilesetImage(Magick::Geometry(sheetWidth, sheetHeight), "transparent");
344 for (int i=0; i<metatiles.size(); i++) { 342 for (int i=0; i<metatiles.size(); i++) {
345 Magick::Image tileRender = renderTile(metatiles.get(i), false, false, palettes, mapTiles, tilesets); 343 Magick::Image tileRender = renderTile(metatiles.get(i), false, false, palettes, mapTiles, tilesets);