Skip to content

Commit a7abb8c

Browse files
committed
Default file extensions for Image to Tiles files (includes refactoring Tilemap_Format)
1 parent 5567d04 commit a7abb8c

File tree

9 files changed

+87
-69
lines changed

9 files changed

+87
-69
lines changed

ide/tilemap-studio.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<ClInclude Include="..\src\themes.h" />
118118
<ClInclude Include="..\src\tile-buttons.h" />
119119
<ClInclude Include="..\src\tile.h" />
120+
<ClInclude Include="..\src\tilemap-format.h" />
120121
<ClInclude Include="..\src\tilemap.h" />
121122
<ClInclude Include="..\src\tileset.h" />
122123
<ClInclude Include="..\src\utils.h" />
@@ -136,6 +137,7 @@
136137
<ClCompile Include="..\src\themes.cpp" />
137138
<ClCompile Include="..\src\tile-buttons.cpp" />
138139
<ClCompile Include="..\src\tile.cpp" />
140+
<ClCompile Include="..\src\tilemap-format.cpp" />
139141
<ClCompile Include="..\src\tilemap.cpp" />
140142
<ClCompile Include="..\src\tileset.cpp" />
141143
<ClCompile Include="..\src\utils.cpp" />

ide/tilemap-studio.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
<ClInclude Include="..\src\tile.h">
7070
<Filter>Header Files</Filter>
7171
</ClInclude>
72+
<ClInclude Include="..\src\tilemap-format.h">
73+
<Filter>Header Files</Filter>
74+
</ClInclude>
7275
</ItemGroup>
7376
<ItemGroup>
7477
<ClCompile Include="..\src\help-window.cpp">
@@ -119,6 +122,9 @@
119122
<ClCompile Include="..\src\tile.cpp">
120123
<Filter>Source Files</Filter>
121124
</ClCompile>
125+
<ClCompile Include="..\src\tilemap-format.cpp">
126+
<Filter>Source Files</Filter>
127+
</ClCompile>
122128
</ItemGroup>
123129
<ItemGroup>
124130
<None Include="..\res\app.ico">

src/config.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
#define CONFIG_H
33

44
#include "utils.h"
5-
6-
#define NUM_FORMATS 7
7-
8-
enum Tilemap_Format { PLAIN, RLE, FF_END, RLE_FF_END, RLE_NYBBLES, XY_FLIP, TILE_ATTR };
5+
#include "tilemap-format.h"
96

107
class Config {
118
private:

src/main-window.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ void Main_Window::update_tilemap_metadata() {
693693
const char *basename = fl_filename_name(_tilemap_file.c_str());
694694
_tilemap_name->label(basename);
695695
}
696-
const char *name = _tilemap.format_name(Config::format());
696+
const char *name = format_name(Config::format());
697697
_tilemap_format->label(name);
698698
}
699699
else {
@@ -798,7 +798,7 @@ void Main_Window::update_active_controls() {
798798
_y_flip->clear();
799799
_y_flip->deactivate();
800800
}
801-
int n = Tilemap::format_tileset_size(Config::format());
801+
int n = format_tileset_size(Config::format());
802802
for (int i = 0; i < n; i++) {
803803
_tile_buttons[i]->activate();
804804
}
@@ -945,7 +945,7 @@ bool Main_Window::save_tilemap(bool force) {
945945

946946
if (!_tilemap.can_write_tiles()) {
947947
std::string msg = "Cannot format the tilemap as ";
948-
msg = msg + Tilemap::format_name(Config::format()) + "!";
948+
msg = msg + format_name(Config::format()) + "!";
949949
_error_dialog->message(msg);
950950
_error_dialog->show(this);
951951
return false;
@@ -1289,7 +1289,7 @@ void Main_Window::save_as_cb(Fl_Widget *, Main_Window *mw) {
12891289
Tilemap_Format fmt = Config::format();
12901290

12911291
char filename[FL_PATH_MAX] = {};
1292-
const char *ext = Tilemap::format_extension(fmt);
1292+
const char *ext = format_extension(fmt);
12931293
add_dot_ext(mw->_tilemap_save_chooser->filename(), ext, filename);
12941294
const char *basename = fl_filename_name(filename);
12951295

src/option-dialogs.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ void Image_To_Tiles_Dialog::tilemap_cb(Fl_Widget *, Image_To_Tiles_Dialog *itd)
470470
itd->_tilemap_name->label("No file selected");
471471
}
472472
else {
473-
const char *filename = itd->_tilemap_chooser->filename();
473+
char filename[FL_PATH_MAX] = {};
474+
const char *ext = format_extension(itd->format());
475+
add_dot_ext(itd->_tilemap_chooser->filename(), ext, filename);
474476
const char *basename = fl_filename_name(filename);
475477
itd->_tilemap_filename = filename;
476478
itd->_tilemap_name->copy_label(basename);
@@ -486,7 +488,8 @@ void Image_To_Tiles_Dialog::tileset_cb(Fl_Widget *, Image_To_Tiles_Dialog *itd)
486488
itd->_tileset_name->label("No file selected");
487489
}
488490
else {
489-
const char *filename = itd->_tileset_chooser->filename();
491+
char filename[FL_PATH_MAX] = {};
492+
add_dot_ext(itd->_tileset_chooser->filename(), ".png", filename);
490493
const char *basename = fl_filename_name(filename);
491494
itd->_tileset_filename = filename;
492495
itd->_tileset_name->copy_label(basename);

src/tilemap-format.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "tilemap-format.h"
2+
3+
int format_tileset_size(Tilemap_Format fmt) {
4+
switch (fmt) {
5+
case Tilemap_Format::RLE_NYBBLES:
6+
// High nybble is reserved for run length
7+
return 0x10;
8+
case Tilemap_Format::XY_FLIP:
9+
// High two bits are reserved for X/Y flip
10+
return 0x40;
11+
case Tilemap_Format::FF_END:
12+
case Tilemap_Format::RLE_FF_END:
13+
// $FF is reserved for the end marker
14+
return 0xFF;
15+
default:
16+
return 0x100;
17+
}
18+
}
19+
20+
const char *format_name(Tilemap_Format fmt) {
21+
switch (fmt) {
22+
case Tilemap_Format::PLAIN:
23+
return "Plain";
24+
case Tilemap_Format::RLE:
25+
return "Run-length encoded";
26+
case Tilemap_Format::FF_END:
27+
return "GSC Town Map";
28+
case Tilemap_Format::RLE_FF_END:
29+
return "Pok\xc3\xa9gear card";
30+
case Tilemap_Format::RLE_NYBBLES:
31+
return "RBY Town Map";
32+
case Tilemap_Format::XY_FLIP:
33+
return "PC Town Map";
34+
case Tilemap_Format::TILE_ATTR:
35+
return "SGB border";
36+
default:
37+
return "Any";
38+
}
39+
}
40+
41+
const char *format_extension(Tilemap_Format fmt) {
42+
switch (fmt) {
43+
case Tilemap_Format::PLAIN:
44+
default:
45+
return ".tilemap"; // e.g. pokecrystal/gfx/card_flip/card_flip.tilemap
46+
case Tilemap_Format::RLE:
47+
case Tilemap_Format::RLE_NYBBLES:
48+
return ".rle"; // e.g. pokered/gfx/town_map.rle
49+
case Tilemap_Format::FF_END:
50+
case Tilemap_Format::XY_FLIP:
51+
return ".bin"; // e.g. pokecrystal/gfx/pokegear/*.bin, polishedcrystal/gfx/town_map/*.bin
52+
case Tilemap_Format::RLE_FF_END:
53+
return ".tilemap.rle"; // e.g. pokecrystal/gfx/pokegear/*.tilemap.bin
54+
case Tilemap_Format::TILE_ATTR:
55+
return ".map"; // e.g. pokered/gfx/{red|blue}/sgbborder.map
56+
}
57+
}

src/tilemap-format.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef TILEMAP_FORMAT_H
2+
#define TILEMAP_FORMAT_H
3+
4+
#define NUM_FORMATS 7
5+
6+
enum Tilemap_Format { PLAIN, RLE, FF_END, RLE_FF_END, RLE_NYBBLES, XY_FLIP, TILE_ATTR };
7+
8+
int format_tileset_size(Tilemap_Format fmt);
9+
const char *format_name(Tilemap_Format fmt);
10+
const char *format_extension(Tilemap_Format fmt);
11+
12+
#endif

src/tilemap.cpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -423,62 +423,6 @@ void Tilemap::guess_width() {
423423
}
424424
}
425425

426-
int Tilemap::format_tileset_size(Tilemap_Format fmt) {
427-
switch (fmt) {
428-
case Tilemap_Format::RLE_NYBBLES:
429-
// High nybble is reserved for run length
430-
return 0x10;
431-
case Tilemap_Format::XY_FLIP:
432-
// High two bits are reserved for X/Y flip
433-
return 0x40;
434-
case Tilemap_Format::FF_END:
435-
case Tilemap_Format::RLE_FF_END:
436-
// $FF is reserved for the end marker
437-
return 0xFF;
438-
default:
439-
return 0x100;
440-
}
441-
}
442-
443-
const char *Tilemap::format_name(Tilemap_Format fmt) {
444-
switch (fmt) {
445-
case Tilemap_Format::PLAIN:
446-
return "Plain";
447-
case Tilemap_Format::RLE:
448-
return "Run-length encoded";
449-
case Tilemap_Format::FF_END:
450-
return "GSC Town Map";
451-
case Tilemap_Format::RLE_FF_END:
452-
return "Pok\xc3\xa9gear card";
453-
case Tilemap_Format::RLE_NYBBLES:
454-
return "RBY Town Map";
455-
case Tilemap_Format::XY_FLIP:
456-
return "PC Town Map";
457-
case Tilemap_Format::TILE_ATTR:
458-
return "SGB border";
459-
default:
460-
return "Any";
461-
}
462-
}
463-
464-
const char *Tilemap::format_extension(Tilemap_Format fmt) {
465-
switch (fmt) {
466-
case Tilemap_Format::PLAIN:
467-
default:
468-
return ".tilemap"; // e.g. pokecrystal/gfx/card_flip/card_flip.tilemap
469-
case Tilemap_Format::RLE:
470-
case Tilemap_Format::RLE_NYBBLES:
471-
return ".rle"; // e.g. pokered/gfx/town_map.rle
472-
case Tilemap_Format::FF_END:
473-
case Tilemap_Format::XY_FLIP:
474-
return ".bin"; // e.g. pokecrystal/gfx/pokegear/*.bin, polishedcrystal/gfx/town_map/*.bin
475-
case Tilemap_Format::RLE_FF_END:
476-
return ".tilemap.rle"; // e.g. pokecrystal/gfx/pokegear/*.tilemap.bin
477-
case Tilemap_Format::TILE_ATTR:
478-
return ".map"; // e.g. pokered/gfx/{red|blue}/sgbborder.map
479-
}
480-
}
481-
482426
const char *Tilemap::error_message(Result result) {
483427
switch (result) {
484428
case TILEMAP_OK:

src/tilemap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ class Tilemap {
6161
void guess_width(void);
6262
public:
6363
static bool write_tiles(const char *f, std::vector<Tile_Tessera *> &tiles, Tilemap_Format fmt);
64-
static int format_tileset_size(Tilemap_Format fmt);
65-
static const char *format_name(Tilemap_Format fmt);
66-
static const char *format_extension(Tilemap_Format fmt);
6764
static const char *error_message(Result result);
6865
};
6966

0 commit comments

Comments
 (0)