diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-28 16:01:34 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-28 16:01:34 -0500 |
commit | 451241bc002efc99f628e399a63bf1b6c29b19c8 (patch) | |
tree | 2d85aac40bacdbb91c99f51b9b467e46f9e951c2 /tools/sprite_dumper | |
parent | b844c6186a108d9b9ffce49950c969e916cf2745 (diff) | |
download | tanetane-451241bc002efc99f628e399a63bf1b6c29b19c8.tar.gz tanetane-451241bc002efc99f628e399a63bf1b6c29b19c8.tar.bz2 tanetane-451241bc002efc99f628e399a63bf1b6c29b19c8.zip |
Added option to override palette in tileset_dumper
Useful because the hallucination version of Mixolydia's house is not a separate map, it's just a special palette (which you can dump from the game while it's running in an emulator).
Diffstat (limited to 'tools/sprite_dumper')
-rw-r--r-- | tools/sprite_dumper/common.h | 2 | ||||
-rw-r--r-- | tools/sprite_dumper/tileset_dumper.cpp | 61 |
2 files changed, 51 insertions, 12 deletions
diff --git a/tools/sprite_dumper/common.h b/tools/sprite_dumper/common.h index d9fb5da..0c7eefe 100644 --- a/tools/sprite_dumper/common.h +++ b/tools/sprite_dumper/common.h | |||
@@ -154,6 +154,8 @@ public: | |||
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | explicit Palette(std::vector<Magick::Color> colors) : colors_(colors) {} | ||
158 | |||
157 | const std::vector<Magick::Color>& Colors() const { return colors_; } | 159 | const std::vector<Magick::Color>& Colors() const { return colors_; } |
158 | 160 | ||
159 | private: | 161 | private: |
diff --git a/tools/sprite_dumper/tileset_dumper.cpp b/tools/sprite_dumper/tileset_dumper.cpp index 4ca0785..c6816ff 100644 --- a/tools/sprite_dumper/tileset_dumper.cpp +++ b/tools/sprite_dumper/tileset_dumper.cpp | |||
@@ -121,12 +121,13 @@ public: | |||
121 | BufferView m3, | 121 | BufferView m3, |
122 | int roomNum, | 122 | int roomNum, |
123 | RoomInfo roomInfo, | 123 | RoomInfo roomInfo, |
124 | RoomGfxPal roomGfxPal) | 124 | std::vector<Palette> palettes, |
125 | std::vector<std::vector<char>> tilesets) | ||
125 | : roomNum_(roomNum), | 126 | : roomNum_(roomNum), |
126 | width_(roomInfo.width), | 127 | width_(roomInfo.width), |
127 | height_(roomInfo.height), | 128 | height_(roomInfo.height), |
128 | palettes_(roomGfxPal.GetPalettes(m3)), | 129 | palettes_(palettes), |
129 | tilesets_(roomGfxPal.GetTilesets(m3)), | 130 | tilesets_(tilesets), |
130 | mapTiles_(GetMapTiles(m3, roomNum)), | 131 | mapTiles_(GetMapTiles(m3, roomNum)), |
131 | mapLayers_(GetMapLayers(m3, roomNum)) | 132 | mapLayers_(GetMapLayers(m3, roomNum)) |
132 | { | 133 | { |
@@ -149,12 +150,6 @@ public: | |||
149 | 150 | ||
150 | itemised_.push_back(std::move(newLayer)); | 151 | itemised_.push_back(std::move(newLayer)); |
151 | } | 152 | } |
152 | |||
153 | // Debug info | ||
154 | std::cout << width_ << "," << height_ << std::endl; | ||
155 | std::cout << roomGfxPal.paletteId; | ||
156 | for (int i=0;i<12;i++) std::cout << "," << roomGfxPal.tilesetId[i]; | ||
157 | std::cout << std::endl; | ||
158 | } | 153 | } |
159 | 154 | ||
160 | Magick::Image renderTile(size_t metatile_id, bool tflipx, bool tflipy) const { | 155 | Magick::Image renderTile(size_t metatile_id, bool tflipx, bool tflipy) const { |
@@ -297,20 +292,62 @@ using globaltile_id = globaltile_identifier::id_type; | |||
297 | 292 | ||
298 | int main(int argc, char** argv) { | 293 | int main(int argc, char** argv) { |
299 | if (argc < 3) { | 294 | if (argc < 3) { |
300 | std::cout << "Usage: ./tileset_dumper [path to rom] {map ID}" << std::endl; | 295 | std::cout << "Usage: ./tileset_dumper [path to rom] [--palette=path to override palette in ACT format] {map ID}" << std::endl; |
301 | return -1; | 296 | return -1; |
302 | } | 297 | } |
303 | 298 | ||
304 | Magick::InitializeMagick(nullptr); | 299 | Magick::InitializeMagick(nullptr); |
305 | 300 | ||
301 | int mapArgStart = 2; | ||
302 | |||
303 | bool shouldOverridePalette = false; | ||
304 | std::vector<Palette> overridePalettes; | ||
305 | if (std::string(argv[2]).substr(0, 10) == "--palette=") { | ||
306 | mapArgStart++; | ||
307 | shouldOverridePalette = true; | ||
308 | |||
309 | std::string filename = std::string(argv[2]).substr(10); | ||
310 | std::ifstream palfile(filename, std::ios::binary); | ||
311 | if (!palfile.is_open()) { | ||
312 | throw std::invalid_argument("Could not find palette file: " + filename); | ||
313 | } | ||
314 | |||
315 | palfile.seekg(0, palfile.end); | ||
316 | int length = palfile.tellg(); | ||
317 | palfile.seekg(0, palfile.beg); | ||
318 | std::vector<char> paletteData(length, 0); | ||
319 | palfile.read(paletteData.data(), length); | ||
320 | |||
321 | BufferView palbuf(paletteData); | ||
322 | for (int i=0; i<12; i++) { | ||
323 | std::vector<Magick::Color> colors; | ||
324 | |||
325 | for (int j=0; j<16; j++) { | ||
326 | unsigned char r = palbuf.ReadNextByte(); | ||
327 | unsigned char g = palbuf.ReadNextByte(); | ||
328 | unsigned char b = palbuf.ReadNextByte(); | ||
329 | colors.push_back(Magick::ColorRGB(r/256.0, g/256.0, b/256.0)); | ||
330 | } | ||
331 | |||
332 | overridePalettes.emplace_back(std::move(colors)); | ||
333 | } | ||
334 | } | ||
335 | |||
306 | Rom m3(argv[1]); | 336 | Rom m3(argv[1]); |
307 | auto roomInfos = RoomInfo::ReadFromRom(m3.buffer()); | 337 | auto roomInfos = RoomInfo::ReadFromRom(m3.buffer()); |
308 | auto roomGfxPals = RoomGfxPal::ReadFromRom(m3.buffer()); | 338 | auto roomGfxPals = RoomGfxPal::ReadFromRom(m3.buffer()); |
309 | 339 | ||
310 | std::list<Map> maps; | 340 | std::list<Map> maps; |
311 | for (int i=2; i<argc; i++) { | 341 | for (int i=mapArgStart; i<argc; i++) { |
312 | int roomNum = std::stoi(argv[i]); | 342 | int roomNum = std::stoi(argv[i]); |
313 | maps.emplace_back(m3.buffer(), roomNum, roomInfos[roomNum], roomGfxPals[roomNum]); | 343 | RoomGfxPal& roomGfxPal = roomGfxPals[roomNum]; |
344 | |||
345 | maps.emplace_back( | ||
346 | m3.buffer(), | ||
347 | roomNum, | ||
348 | roomInfos[roomNum], | ||
349 | shouldOverridePalette ? overridePalettes : roomGfxPal.GetPalettes(m3.buffer()), | ||
350 | roomGfxPal.GetTilesets(m3.buffer())); | ||
314 | } | 351 | } |
315 | 352 | ||
316 | globaltile_identifier globaltiles; | 353 | globaltile_identifier globaltiles; |