Refactor AsepriteExternalFiles usage

This commit is contained in:
Martín Capello 2022-12-20 16:45:40 -03:00
parent 243fbc3fbc
commit 8b4b803a22
3 changed files with 13 additions and 6 deletions

View File

@ -1235,10 +1235,7 @@ static void ase_file_write_external_files_chunk(
{
for (const Tileset* tileset : *sprite->tilesets()) {
if (!tileset->externalFilename().empty()) {
auto id = ++ext_files.lastid;
auto fn = tileset->externalFilename();
ext_files.to_fn[id] = fn;
ext_files.to_id[fn] = id;
ext_files.put(tileset->externalFilename());
}
}

View File

@ -104,6 +104,17 @@ struct AsepriteExternalFiles {
std::map<uint32_t, std::string> to_fn; // ID -> filename
std::map<std::string, uint32_t> to_id; // filename -> ID
uint32_t lastid = 0;
// Adds the external filename with the next autogenerated ID.
void put(const std::string& filename) {
auto id = ++lastid;
to_fn[id] = filename;
to_id[filename] = id;
}
// Adds the external filename using the specified ID.
void put(uint32_t id, const std::string& filename) {
to_fn[id] = filename;
to_id[filename] = id;
}
};
} // namespace dio

View File

@ -940,8 +940,7 @@ void AsepriteDecoder::readExternalFiles(AsepriteExternalFiles& extFiles)
uint32_t id = read32();
readPadding(8);
std::string fn = readString();
extFiles.to_fn[id] = fn;
extFiles.to_id[fn] = id;
extFiles.put(id, fn);
}
}