mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-11-18 03:02:07 +00:00
feat: combine loading bar and zone list
This commit is contained in:
@@ -23,7 +23,7 @@ namespace
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(ZoneUnlinkProgressDto, zoneName, percentage);
|
||||
|
||||
constexpr double MIN_PROGRESS_TO_REPORT = 0.005;
|
||||
constexpr double MIN_PROGRESS_TO_REPORT = 0.5;
|
||||
|
||||
class UnlinkingEventProgressReporter : public ProgressCallback
|
||||
{
|
||||
@@ -36,7 +36,7 @@ namespace
|
||||
|
||||
void OnProgress(const size_t current, const size_t total) override
|
||||
{
|
||||
const double percentage = static_cast<double>(current) / static_cast<double>(total);
|
||||
const double percentage = static_cast<double>(current) / static_cast<double>(total) * 100.0;
|
||||
|
||||
if (percentage - m_last_progress >= MIN_PROGRESS_TO_REPORT)
|
||||
{
|
||||
@@ -54,17 +54,17 @@ namespace
|
||||
{
|
||||
const auto& context = ModManContext::Get().m_fast_file;
|
||||
const auto existingZone = std::ranges::find_if(context.m_loaded_zones,
|
||||
[&zoneName](const std::unique_ptr<Zone>& zone)
|
||||
[&zoneName](const std::unique_ptr<LoadedZone>& loadedZone)
|
||||
{
|
||||
return zone->m_name == zoneName;
|
||||
return loadedZone->m_zone->m_name == zoneName;
|
||||
});
|
||||
|
||||
if (existingZone == context.m_loaded_zones.end())
|
||||
return result::Unexpected(std::format("No zone with name {} loaded", zoneName));
|
||||
|
||||
const auto& zone = *existingZone->get();
|
||||
const auto& loadedZone = *existingZone->get();
|
||||
|
||||
const auto* objWriter = IObjWriter::GetObjWriterForGame(zone.m_game_id);
|
||||
const auto* objWriter = IObjWriter::GetObjWriterForGame(loadedZone.m_zone->m_game_id);
|
||||
|
||||
const auto outputFolderPath = fs::path(utils::GetExecutablePath()).parent_path() / "zone_dump" / zoneName;
|
||||
const auto outputFolderPathStr = outputFolderPath.string();
|
||||
@@ -72,7 +72,7 @@ namespace
|
||||
OutputPathFilesystem outputFolderOutputPath(outputFolderPath);
|
||||
SearchPaths searchPaths;
|
||||
AssetDumpingContext dumpingContext(
|
||||
zone, outputFolderPathStr, outputFolderOutputPath, searchPaths, std::make_unique<UnlinkingEventProgressReporter>(zoneName));
|
||||
*loadedZone.m_zone, outputFolderPathStr, outputFolderOutputPath, searchPaths, std::make_unique<UnlinkingEventProgressReporter>(zoneName));
|
||||
objWriter->DumpZone(dumpingContext);
|
||||
|
||||
return NoResult();
|
||||
|
||||
@@ -7,6 +7,15 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
class ZoneDto
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
std::string filePath;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(ZoneDto, name, filePath);
|
||||
|
||||
class ZoneLoadProgressDto
|
||||
{
|
||||
public:
|
||||
@@ -19,11 +28,10 @@ namespace
|
||||
class ZoneLoadedDto
|
||||
{
|
||||
public:
|
||||
std::string zoneName;
|
||||
std::string filePath;
|
||||
ZoneDto zone;
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(ZoneLoadedDto, zoneName, filePath);
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(ZoneLoadedDto, zone);
|
||||
|
||||
class ZoneUnloadedDto
|
||||
{
|
||||
@@ -33,6 +41,33 @@ namespace
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_EXTENSION(ZoneUnloadedDto, zoneName);
|
||||
|
||||
ZoneDto CreateZoneDto(const LoadedZone& loadedZone)
|
||||
{
|
||||
return ZoneDto{
|
||||
.name = loadedZone.m_zone->m_name,
|
||||
.filePath = loadedZone.m_file_path,
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<ZoneDto> GetLoadedZones()
|
||||
{
|
||||
auto& context = ModManContext::Get().m_fast_file;
|
||||
|
||||
std::vector<ZoneDto> result;
|
||||
|
||||
{
|
||||
std::shared_lock lock(context.m_zone_lock);
|
||||
result.reserve(context.m_loaded_zones.size());
|
||||
|
||||
for (const auto& loadedZone : context.m_loaded_zones)
|
||||
{
|
||||
result.emplace_back(CreateZoneDto(*loadedZone));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void LoadFastFile(webview::webview& wv, std::string id, std::string path) // NOLINT(performance-unnecessary-value-param) Copy is made for thread safety
|
||||
{
|
||||
ModManContext::Get().m_db_thread.Dispatch(
|
||||
@@ -45,10 +80,9 @@ namespace
|
||||
ui::PromiseResolve(wv,
|
||||
id,
|
||||
ZoneLoadedDto{
|
||||
.zoneName = maybeZone.value()->m_name,
|
||||
.filePath = path,
|
||||
.zone = CreateZoneDto(*maybeZone.value()),
|
||||
});
|
||||
con::debug("Loaded zone \"{}\"", maybeZone.value()->m_name);
|
||||
con::debug("Loaded zone \"{}\"", maybeZone.value()->m_zone->m_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -89,11 +123,10 @@ namespace ui
|
||||
Notify(*ModManContext::Get().m_main_webview, "zoneLoadProgress", dto);
|
||||
}
|
||||
|
||||
void NotifyZoneLoaded(std::string zoneName, std::string fastFilePath)
|
||||
void NotifyZoneLoaded(const LoadedZone& loadedZone)
|
||||
{
|
||||
const ZoneLoadedDto dto{
|
||||
.zoneName = std::move(zoneName),
|
||||
.filePath = std::move(fastFilePath),
|
||||
.zone = CreateZoneDto(loadedZone),
|
||||
};
|
||||
Notify(*ModManContext::Get().m_main_webview, "zoneLoaded", dto);
|
||||
}
|
||||
@@ -108,6 +141,13 @@ namespace ui
|
||||
|
||||
void RegisterZoneBinds(webview::webview& wv)
|
||||
{
|
||||
BindRetOnly<std::vector<ZoneDto>>(wv,
|
||||
"getZones",
|
||||
[]
|
||||
{
|
||||
return GetLoadedZones();
|
||||
});
|
||||
|
||||
BindAsync<std::string>(wv,
|
||||
"loadFastFile",
|
||||
[&wv](const std::string& id, std::string path)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "Context/FastFileContext.h"
|
||||
#include "Web/WebViewLib.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
void NotifyZoneLoadProgress(std::string zoneName, double percentage);
|
||||
void NotifyZoneLoaded(std::string zoneName, std::string fastFilePath);
|
||||
void NotifyZoneLoaded(const LoadedZone& loadedZone);
|
||||
void NotifyZoneUnloaded(std::string zoneName);
|
||||
|
||||
void RegisterZoneBinds(webview::webview& wv);
|
||||
|
||||
Reference in New Issue
Block a user