Save a spritesheet's image from one Document method
The spritesheets window and the close-document prompt both use it.
This commit is contained in:
1 parent
f6325a794b
commit
f78d35b12b
4 files changed
+20
-33
No files matched your search
@@ -1291,3 +1291,19 @@ bool Document::is_able_to_redo()
|
||||
{
|
||||
return !snapshots.redoStack.is_empty();
|
||||
}
|
||||
|
||||
// Writes a spritesheet's image to its file, beside the document, and says how it went.
|
||||
void Document::spritesheet_save(int id)
|
||||
{
|
||||
auto spritesheet = item_get(model.content.spritesheets, id);
|
||||
auto texture = texture_get(id);
|
||||
if (!spritesheet || !texture)
|
||||
return;
|
||||
auto path = directory_get() / spritesheet->path;
|
||||
path_ensure_directory(path.parent_path());
|
||||
auto isSaved = texture->write(path);
|
||||
if (isSaved)
|
||||
spritesheet_hash_set_saved(id);
|
||||
toast_log(isSaved ? Level::INFO : Level::ERROR, isSaved ? TOAST_SAVE_SPRITESHEET : TOAST_SAVE_SPRITESHEET_FAILED,
|
||||
id, path_to_utf8(spritesheet->path));
|
||||
}
|
||||
@@ -187,6 +187,7 @@ public:
|
||||
void command_run(Manager&, Command&);
|
||||
void spritesheet_hash_update(int);
|
||||
void spritesheet_hash_set_saved(int);
|
||||
void spritesheet_save(int);
|
||||
bool spritesheet_is_dirty(int);
|
||||
bool spritesheet_any_dirty();
|
||||
void spritesheet_hashes_sync();
|
||||
|
||||
+2
-19
@@ -296,25 +296,8 @@ void Documents::update(Taskbar& taskbar, Manager& manager, Settings& settings, R
|
||||
{
|
||||
if (isSpritesheetDirty)
|
||||
for (auto& spritesheet : closeDocument.model.content.spritesheets)
|
||||
{
|
||||
auto id = spritesheet.id;
|
||||
auto texture = closeDocument.texture_get(id);
|
||||
if (texture && closeDocument.spritesheet_is_dirty(id))
|
||||
{
|
||||
auto pathString = path_to_utf8(spritesheet.path);
|
||||
auto savePath = closeDocument.directory_get() / spritesheet.path;
|
||||
path_ensure_directory(savePath.parent_path());
|
||||
if (texture->write(savePath))
|
||||
{
|
||||
closeDocument.spritesheet_hash_set_saved(id);
|
||||
toast_log(Level::INFO, TOAST_SAVE_SPRITESHEET, id, pathString);
|
||||
}
|
||||
else
|
||||
{
|
||||
toast_log(Level::ERROR, TOAST_SAVE_SPRITESHEET_FAILED, id, pathString);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (closeDocument.spritesheet_is_dirty(spritesheet.id))
|
||||
closeDocument.spritesheet_save(spritesheet.id);
|
||||
auto index = closeDocumentIndex;
|
||||
manager.command_push({.runManager = [index](Manager& manager) { manager.close(index); }});
|
||||
close();
|
||||
|
||||
+1
-14
@@ -27,20 +27,7 @@ static bool is_spritesheet_regions(Document& document, int id)
|
||||
static void spritesheets_save(Document& document, const std::set<int>& ids)
|
||||
{
|
||||
for (auto id : ids)
|
||||
{
|
||||
auto spritesheet = spritesheet_get(document, id);
|
||||
auto texture = document.texture_get(id);
|
||||
if (!spritesheet || !texture)
|
||||
continue;
|
||||
auto pathString = path_to_utf8(spritesheet->path);
|
||||
WorkingDirectory workingDirectory(document.directory_get());
|
||||
path_ensure_directory(spritesheet->path.parent_path());
|
||||
auto isSaved = texture->write(spritesheet->path);
|
||||
if (isSaved)
|
||||
document.spritesheet_hash_set_saved(id);
|
||||
toast_log(isSaved ? Level::INFO : Level::ERROR,
|
||||
isSaved ? TOAST_SAVE_SPRITESHEET : TOAST_SAVE_SPRITESHEET_FAILED, id, pathString);
|
||||
}
|
||||
document.spritesheet_save(id);
|
||||
}
|
||||
|
||||
// Points a spritesheet at a new file: replacing loads it, setting the path writes the current texture there.
|
||||
|
||||
Reference in new issue
Block a user