1.5: Fuckin' UE5... #38

Manually merged
williamjcm merged 126 commits from one-point-five into master 2024-07-22 11:06:13 +02:00
6 changed files with 17 additions and 142 deletions
Showing only changes of commit 57f6364b7f - Show all commits

View file

@ -40,6 +40,7 @@
#include "../Managers/BackupManager.h"
#include "../Managers/MassManager.h"
#include "../Managers/ProfileManager.h"
#include "../Managers/StagedMassManager.h"
#include "../ToastQueue/ToastQueue.h"
#include "../UpdateChecker/UpdateChecker.h"
@ -260,6 +261,8 @@ class Application: public Platform::Sdl2Application, public efsw::FileWatchListe
Containers::Pointer<Managers::MassManager> _massManager;
GameObjects::Mass* _currentMass = nullptr;
Containers::Pointer<Managers::StagedMassManager> _stagedMassManager;
GameObjects::Weapon* _currentWeapon = nullptr;
Containers::Pointer<efsw::FileWatcher> _fileWatcher;

View file

@ -68,7 +68,7 @@ Application::fileUpdateEvent(SDL_Event& event) {
std::strlen(static_cast<char*>(event.user.data1)), nullptr};
if((event.user.code & StagedUpdate) == StagedUpdate) {
_massManager->refreshStagedMass(filename);
_stagedMassManager->refreshMass(filename);
return;
}

View file

@ -117,6 +117,8 @@ Application::initialiseManager() {
_backupManager.emplace();
_stagedMassManager.emplace();
event.user.code = InitSuccess;
SDL_PushEvent(&event);
}

View file

@ -438,7 +438,7 @@ Application::drawMassManager() {
Containers::StringView file = *static_cast<Containers::String*>(payload->Data);
if(!_massManager->importMass(file, i)) {
if(!_stagedMassManager->import(file, i, _currentProfile->account(), _currentProfile->isDemo())) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
}
}
@ -530,26 +530,26 @@ Application::drawMassManager() {
openUri(Utility::Path::toNativeSeparators(conf().directories().staging));
}
for(const auto& pair : _massManager->stagedMasses()) {
for(const auto& mass : _stagedMassManager->stagedMasses()) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
Containers::String staged_formatted = Utility::format("{} ({})", pair.second, pair.first);
Containers::String staged_formatted = Utility::format("{} ({})", mass.name, mass.filename);
ImGui::Selectable(staged_formatted.data());
if((ImGui::CalcTextSize(staged_formatted.data()).x + ImGui::GetStyle().FramePadding.x) > ImGui::GetContentRegionAvail().x) {
drawTooltip(staged_formatted.data());
}
if(ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) {
ImGui::SetDragDropPayload("StagedMass", &(pair.first), sizeof(Containers::String));
ImGui::SetDragDropPayload("StagedMass", &(mass.filename), sizeof(Containers::String));
ImGui::Text("%s - Staged", pair.second.data());
ImGui::Text("%s - Staged", mass.name.cbegin());
ImGui::EndDragDropSource();
}
ImGui::TableSetColumnIndex(1);
ImGui::PushID(pair.first.data());
ImGui::PushID(mass.filename.data());
if(ImGui::SmallButton(ICON_FA_TRASH_ALT)) {
staged_mass_to_delete = pair.first;
staged_mass_to_delete = mass.filename;
ImGui::OpenPopup("Confirmation##DeleteStagedMassConfirmation");
}
drawTooltip("Delete");
@ -644,7 +644,7 @@ Application::drawDeleteStagedMassPopup(Containers::StringView filename) {
ImGui::PushTextWrapPos(float(windowSize().x()) * 0.40f);
ImGui::Text("Are you sure you want to delete the staged M.A.S.S. named %s ? This operation is irreversible.",
_massManager->stagedMasses().at(filename).data());
_stagedMassManager->at(filename).filename.cbegin());
ImGui::PopTextWrapPos();
if(ImGui::BeginTable("##DeleteStagedMassLayout", 2)) {
@ -655,8 +655,9 @@ Application::drawDeleteStagedMassPopup(Containers::StringView filename) {
ImGui::TableSetColumnIndex(1);
if(ImGui::Button("Yes")) {
if(!_massManager->deleteStagedMass(filename)) {
_queue.addToast(Toast::Type::Error, _massManager->lastError());
if(!_stagedMassManager->remove(filename)) {
_queue.addToast(Toast::Type::Error,
"Couldn't delete the staged M.A.S.S. at " + filename + ": " + _stagedMassManager->lastError());
}
ImGui::CloseCurrentPopup();
}

View file

@ -37,8 +37,6 @@ MassManager::MassManager(Containers::StringView account, bool demo):
Utility::format("{}Unit{:.2d}{}.sav", demo ? "Demo"_s : ""_s, i, _account));
new(&_hangars[i]) GameObjects::Mass{mass_filename};
}
refreshStagedMasses();
}
Containers::StringView
@ -65,49 +63,6 @@ MassManager::refreshHangar(std::int32_t hangar) {
_hangars[hangar] = GameObjects::Mass{mass_filename};
}
bool
MassManager::importMass(Containers::StringView staged_fn, std::int32_t hangar) {
if(hangar < 0 || hangar >= 32) {
_lastError = "Hangar index out of range.";
LOG_ERROR(_lastError);
return false;
}
auto it = _stagedMasses.find(Containers::String::nullTerminatedView(staged_fn));
if(it == _stagedMasses.end()) {
_lastError = "Couldn't find "_s + staged_fn + " in the staged M.A.S.S.es."_s;
LOG_ERROR(_lastError);
return false;
}
Containers::String source = Utility::Path::join(conf().directories().staging, staged_fn);
Utility::Path::copy(source, source + ".tmp"_s);
{
GameObjects::Mass mass{source + ".tmp"_s};
if(!mass.updateAccount(_account)) {
_lastError = mass.lastError();
Utility::Path::remove(source + ".tmp"_s);
return false;
}
}
Containers::String dest = Utility::Path::join(conf().directories().gameSaves, _hangars[hangar].filename());
if(Utility::Path::exists(dest)) {
Utility::Path::remove(dest);
}
if(!Utility::Path::move(source + ".tmp"_s, dest)) {
_lastError = Utility::format("Couldn't move {} to hangar {:.2d}", staged_fn, hangar + 1);
LOG_ERROR(_lastError);
return false;
}
return true;
}
bool
MassManager::exportMass(std::int32_t hangar) {
if(hangar < 0 || hangar >= 32) {
@ -192,80 +147,4 @@ MassManager::deleteMass(std::int32_t hangar) {
return true;
}
const std::map<Containers::String, Containers::String>&
MassManager::stagedMasses() {
return _stagedMasses;
}
void
MassManager::refreshStagedMasses() {
_stagedMasses.clear();
using Utility::Path::ListFlag;
auto file_list = Utility::Path::list(conf().directories().staging,
ListFlag::SkipSpecial|ListFlag::SkipDirectories|ListFlag::SkipDotAndDotDot);
if(!file_list) {
LOG_ERROR_FORMAT("{} couldn't be opened.", conf().directories().staging);
return;
}
auto iter = std::remove_if(file_list->begin(), file_list->end(), [](Containers::StringView file){
return !file.hasSuffix(".sav"_s);
});
auto list_view = file_list->exceptSuffix(file_list->end() - iter);
LOG_INFO("Scanning for staged M.A.S.S.es...");
for(Containers::StringView file : list_view) {
auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(conf().directories().staging, file));
if(name) {
LOG_INFO_FORMAT("Found staged M.A.S.S.: {}", *name);
_stagedMasses[file] = *name;
}
else {
LOG_WARNING_FORMAT("Skipped {}.", file);
}
}
}
void
MassManager::refreshStagedMass(Containers::StringView filename) {
LOG_INFO_FORMAT("Refreshing staged unit with filename {}.", filename);
bool file_exists = Utility::Path::exists(Utility::Path::join(conf().directories().staging, filename));
auto it = _stagedMasses.find(filename);
if(file_exists) {
auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(conf().directories().staging, filename));
if(name) {
_stagedMasses[filename] = *name;
}
else if(it != _stagedMasses.cend()) {
_stagedMasses.erase(it);
}
}
else if(it != _stagedMasses.cend()) {
_stagedMasses.erase(it);
}
}
bool
MassManager::deleteStagedMass(Containers::StringView filename) {
if(_stagedMasses.find(filename) == _stagedMasses.cend()) {
_lastError = "The file "_s + filename + " couldn't be found in the list of staged M.A.S.S.es."_s;
LOG_ERROR(_lastError);
return false;
}
if(!Utility::Path::remove(Utility::Path::join(conf().directories().staging, filename))) {
_lastError = filename + " couldn't be deleted: " + std::strerror(errno);
LOG_ERROR(_lastError);
return false;
}
return true;
}
}

View file

@ -16,8 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <map>
#include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
@ -38,17 +36,11 @@ class MassManager {
void refreshHangar(int hangar);
bool importMass(Containers::StringView staged_fn, int hangar);
bool exportMass(int hangar);
bool moveMass(int source, int destination);
bool deleteMass(int hangar);
auto stagedMasses() -> std::map<Containers::String, Containers::String> const&;
void refreshStagedMasses();
void refreshStagedMass(Containers::StringView filename);
bool deleteStagedMass(Containers::StringView filename);
private:
Containers::StringView _account;
bool _demo;
@ -56,8 +48,6 @@ class MassManager {
Containers::String _lastError;
Containers::StaticArray<32, GameObjects::Mass> _hangars{NoInit};
std::map<Containers::String, Containers::String> _stagedMasses;
};
}