Refactor + render animation tweaks + updated frame properties + bug fixes
This commit is contained in:
+22
-27
@@ -5,8 +5,9 @@
|
||||
|
||||
#include <format>
|
||||
|
||||
#include "filesystem_.h"
|
||||
#include "log.h"
|
||||
#include "path_.h"
|
||||
#include "sdl.h"
|
||||
#include "strings.h"
|
||||
#include "toast.h"
|
||||
#include "vector_.h"
|
||||
@@ -26,9 +27,7 @@ namespace anm2ed
|
||||
if (parent.empty()) return;
|
||||
std::error_code ec{};
|
||||
std::filesystem::create_directories(parent, ec);
|
||||
if (ec)
|
||||
logger.warning(
|
||||
std::format("Could not create directory for {}: {}", filesystem::path_to_utf8(path), ec.message()));
|
||||
if (ec) logger.warning(std::format("Could not create directory for {}: {}", path::to_utf8(path), ec.message()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +58,8 @@ namespace anm2ed
|
||||
if (documents.empty()) selectionHistory.clear();
|
||||
}
|
||||
|
||||
std::filesystem::path Manager::recent_files_path_get() { return filesystem::path_preferences_get() / "recent.txt"; }
|
||||
std::filesystem::path Manager::autosave_path_get() { return filesystem::path_preferences_get() / "autosave.txt"; }
|
||||
std::filesystem::path Manager::recent_files_path_get() { return sdl::preferences_directory_get() / "recent.txt"; }
|
||||
std::filesystem::path Manager::autosave_path_get() { return sdl::preferences_directory_get() / "autosave.txt"; }
|
||||
|
||||
Manager::Manager()
|
||||
{
|
||||
@@ -74,7 +73,7 @@ namespace anm2ed
|
||||
{
|
||||
std::string errorString{};
|
||||
documents.emplace_back(path, isNew, &errorString);
|
||||
auto pathString = filesystem::path_to_utf8(path);
|
||||
auto pathString = path::to_utf8(path);
|
||||
|
||||
auto& document = documents.back();
|
||||
if (!document.is_valid())
|
||||
@@ -136,8 +135,7 @@ namespace anm2ed
|
||||
std::error_code ec{};
|
||||
std::filesystem::remove(autosavePath, ec);
|
||||
if (ec)
|
||||
logger.warning(std::format("Could not remove autosave file {}: {}", filesystem::path_to_utf8(autosavePath),
|
||||
ec.message()));
|
||||
logger.warning(std::format("Could not remove autosave file {}: {}", path::to_utf8(autosavePath), ec.message()));
|
||||
}
|
||||
|
||||
autosave_files_write();
|
||||
@@ -252,7 +250,7 @@ namespace anm2ed
|
||||
std::vector<std::filesystem::path> ordered;
|
||||
ordered.reserve(orderedEntries.size());
|
||||
for (const auto& [pathString, _] : orderedEntries)
|
||||
ordered.emplace_back(filesystem::path_from_utf8(pathString));
|
||||
ordered.emplace_back(path::from_utf8(pathString));
|
||||
return ordered;
|
||||
}
|
||||
|
||||
@@ -262,11 +260,11 @@ namespace anm2ed
|
||||
std::error_code ec{};
|
||||
if (!std::filesystem::exists(path, ec))
|
||||
{
|
||||
logger.warning(std::format("Skipping missing recent file: {}", filesystem::path_to_utf8(path)));
|
||||
logger.warning(std::format("Skipping missing recent file: {}", path::to_utf8(path)));
|
||||
return;
|
||||
}
|
||||
|
||||
recentFiles[filesystem::path_to_utf8(path)] = ++recentFilesCounter;
|
||||
recentFiles[path::to_utf8(path)] = ++recentFilesCounter;
|
||||
recent_files_trim();
|
||||
recent_files_write();
|
||||
}
|
||||
@@ -278,12 +276,11 @@ namespace anm2ed
|
||||
std::ifstream file(path);
|
||||
if (!file)
|
||||
{
|
||||
logger.warning(
|
||||
std::format("Could not load recent files from: {}. Skipping...", filesystem::path_to_utf8(path)));
|
||||
logger.warning(std::format("Could not load recent files from: {}. Skipping...", path::to_utf8(path)));
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(std::format("Loading recent files from: {}", filesystem::path_to_utf8(path)));
|
||||
logger.info(std::format("Loading recent files from: {}", path::to_utf8(path)));
|
||||
|
||||
std::string line{};
|
||||
std::vector<std::string> loaded{};
|
||||
@@ -293,14 +290,14 @@ namespace anm2ed
|
||||
{
|
||||
if (line.empty()) continue;
|
||||
if (!line.empty() && line.back() == '\r') line.pop_back();
|
||||
auto entry = filesystem::path_from_utf8(line);
|
||||
auto entry = path::from_utf8(line);
|
||||
std::error_code ec{};
|
||||
if (!std::filesystem::exists(entry, ec))
|
||||
{
|
||||
logger.warning(std::format("Skipping missing recent file: {}", line));
|
||||
continue;
|
||||
}
|
||||
auto entryString = filesystem::path_to_utf8(entry);
|
||||
auto entryString = path::to_utf8(entry);
|
||||
if (!seen.insert(entryString).second) continue;
|
||||
loaded.emplace_back(std::move(entryString));
|
||||
}
|
||||
@@ -324,14 +321,13 @@ namespace anm2ed
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
logger.warning(
|
||||
std::format("Could not write recent files to: {}. Skipping...", filesystem::path_to_utf8(path)));
|
||||
logger.warning(std::format("Could not write recent files to: {}. Skipping...", path::to_utf8(path)));
|
||||
return;
|
||||
}
|
||||
|
||||
auto ordered = recent_files_ordered();
|
||||
for (auto& entry : ordered)
|
||||
file << filesystem::path_to_utf8(entry) << '\n';
|
||||
file << path::to_utf8(entry) << '\n';
|
||||
}
|
||||
|
||||
void Manager::recent_files_clear()
|
||||
@@ -346,9 +342,9 @@ namespace anm2ed
|
||||
for (auto& path : autosaveFiles)
|
||||
{
|
||||
auto fileNamePath = path.filename();
|
||||
auto fileNameUtf8 = filesystem::path_to_utf8(fileNamePath);
|
||||
auto fileNameUtf8 = path::to_utf8(fileNamePath);
|
||||
if (!fileNameUtf8.empty() && fileNameUtf8.front() == '.') fileNameUtf8.erase(fileNameUtf8.begin());
|
||||
fileNamePath = filesystem::path_from_utf8(fileNameUtf8);
|
||||
fileNamePath = path::from_utf8(fileNameUtf8);
|
||||
|
||||
auto restorePath = path.parent_path() / fileNamePath;
|
||||
restorePath.replace_extension("");
|
||||
@@ -372,12 +368,11 @@ namespace anm2ed
|
||||
std::ifstream file(path);
|
||||
if (!file)
|
||||
{
|
||||
logger.warning(
|
||||
std::format("Could not load autosave files from: {}. Skipping...", filesystem::path_to_utf8(path)));
|
||||
logger.warning(std::format("Could not load autosave files from: {}. Skipping...", path::to_utf8(path)));
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(std::format("Loading autosave files from: {}", filesystem::path_to_utf8(path)));
|
||||
logger.info(std::format("Loading autosave files from: {}", path::to_utf8(path)));
|
||||
|
||||
std::string line{};
|
||||
|
||||
@@ -385,7 +380,7 @@ namespace anm2ed
|
||||
{
|
||||
if (line.empty()) continue;
|
||||
if (!line.empty() && line.back() == '\r') line.pop_back();
|
||||
auto entry = filesystem::path_from_utf8(line);
|
||||
auto entry = path::from_utf8(line);
|
||||
if (std::find(autosaveFiles.begin(), autosaveFiles.end(), entry) != autosaveFiles.end()) continue;
|
||||
autosaveFiles.emplace_back(std::move(entry));
|
||||
}
|
||||
@@ -398,7 +393,7 @@ namespace anm2ed
|
||||
autosaveWriteFile.open(autosave_path_get(), std::ofstream::out | std::ofstream::trunc);
|
||||
|
||||
for (auto& path : autosaveFiles)
|
||||
autosaveWriteFile << filesystem::path_to_utf8(path) << "\n";
|
||||
autosaveWriteFile << path::to_utf8(path) << "\n";
|
||||
|
||||
autosaveWriteFile.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user