diff --git a/src/app/file/ase_format.cpp b/src/app/file/ase_format.cpp index 68ee01dc7..2e5b5e508 100644 --- a/src/app/file/ase_format.cpp +++ b/src/app/file/ase_format.cpp @@ -1338,13 +1338,13 @@ static void ase_file_write_external_files_chunk( return; ChunkWriter chunk(f, frame_header, ASE_FILE_CHUNK_EXTERNAL_FILE); - fputl(ext_files.to_fn.size(), f); // Number of entries + fputl(ext_files.items.size(), f); // Number of entries ase_file_write_padding(f, 8); - for (auto item : ext_files.to_fn) { - fputl(item.first, f); // ID - fputc(ext_files.types[item.first], f); // Type + for (const auto& it : ext_files.items) { + fputl(it.first, f); // ID + fputc(it.second.type, f); // Type ase_file_write_padding(f, 7); - ase_file_write_string(f, item.second); // Filename + ase_file_write_string(f, it.second.fn); // Filename } } diff --git a/src/dio/aseprite_common.h b/src/dio/aseprite_common.h index 33afd4d6c..10ccdb1b9 100644 --- a/src/dio/aseprite_common.h +++ b/src/dio/aseprite_common.h @@ -106,25 +106,24 @@ struct AsepriteChunk { }; struct AsepriteExternalFiles { - std::map to_fn; // ID -> filename + struct Item { + std::string fn; // filename + uint8_t type; // type has one of the ASE_EXTERNAL_FILE_* values + }; + std::map items; std::map to_id; // filename -> ID - std::map types; // ID -> type (type has one of the ASE_EXTERNAL_FILE_* values) uint32_t lastid = 0; // Adds the external filename with the next autogenerated ID and specified type. void put(const std::string& filename, uint8_t type) { - auto id = ++lastid; - to_fn[id] = filename; - to_id[filename] = id; - types[id] = type; + put(++lastid, filename, type); } // Adds the external filename using the specified ID and type. void put(uint32_t id, const std::string& filename, uint8_t type) { - to_fn[id] = filename; + items[id] = Item{ filename, type }; to_id[filename] = id; - types[id] = type; } // Returns true if the given filename exists in the external files @@ -138,10 +137,10 @@ struct AsepriteExternalFiles { } bool getFilenameByID(uint32_t id, std::string& fn) const { - auto it = to_fn.find(id); - if (it == to_fn.end()) + auto it = items.find(id); + if (it == items.end()) return false; - fn = it->second; + fn = it->second.fn; return true; } }; diff --git a/src/dio/aseprite_decoder.cpp b/src/dio/aseprite_decoder.cpp index e22edff81..aaeb8d5b2 100644 --- a/src/dio/aseprite_decoder.cpp +++ b/src/dio/aseprite_decoder.cpp @@ -1197,9 +1197,8 @@ doc::Tileset* AsepriteDecoder::readTilesetChunk(doc::Sprite* sprite, const uint32_t extFileId = read32(); // filename ID in the external files chunk const doc::tileset_index extTilesetId = read32(); // tileset ID in the external file - auto it = extFiles.to_fn.find(extFileId); - if (it != extFiles.to_fn.end()) { - auto fn = it->second; + std::string fn; + if (extFiles.getFilenameByID(extFileId, fn)) { tileset->setExternal(fn, extTilesetId); } else {