format: reformat project
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
#include "EngineController.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
#include "../coders/commons.hpp"
|
||||
#include "../content/ContentLUT.hpp"
|
||||
#include "../debug/Logger.hpp"
|
||||
#include "../engine.hpp"
|
||||
#include "../files/WorldFiles.hpp"
|
||||
#include "../files/WorldConverter.hpp"
|
||||
#include "../files/WorldFiles.hpp"
|
||||
#include "../frontend/locale.hpp"
|
||||
#include "../frontend/screens/MenuScreen.hpp"
|
||||
#include "../frontend/screens/LevelScreen.hpp"
|
||||
#include "../frontend/menu.hpp"
|
||||
#include "../frontend/screens/LevelScreen.hpp"
|
||||
#include "../frontend/screens/MenuScreen.hpp"
|
||||
#include "../graphics/ui/elements/Menu.hpp"
|
||||
#include "../graphics/ui/gui_util.hpp"
|
||||
#include "../interfaces/Task.hpp"
|
||||
#include "../util/stringutil.hpp"
|
||||
#include "../world/World.hpp"
|
||||
#include "../world/Level.hpp"
|
||||
#include "../world/World.hpp"
|
||||
#include "LevelController.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static debug::Logger logger("engine-control");
|
||||
@@ -31,46 +31,62 @@ EngineController::EngineController(Engine* engine) : engine(engine) {
|
||||
|
||||
void EngineController::deleteWorld(const std::string& name) {
|
||||
fs::path folder = engine->getPaths()->getWorldFolder(name);
|
||||
guiutil::confirm(engine->getGUI(), langs::get(L"delete-confirm", L"world")+
|
||||
L" ("+util::str2wstr_utf8(folder.u8string())+L")", [=]() {
|
||||
logger.info() << "deleting " << folder.u8string();
|
||||
fs::remove_all(folder);
|
||||
});
|
||||
guiutil::confirm(
|
||||
engine->getGUI(),
|
||||
langs::get(L"delete-confirm", L"world") + L" (" +
|
||||
util::str2wstr_utf8(folder.u8string()) + L")",
|
||||
[=]() {
|
||||
logger.info() << "deleting " << folder.u8string();
|
||||
fs::remove_all(folder);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<Task> create_converter(
|
||||
Engine* engine,
|
||||
const fs::path& folder,
|
||||
const Content* content,
|
||||
const Content* content,
|
||||
const std::shared_ptr<ContentLUT>& lut,
|
||||
const runnable& postRunnable)
|
||||
{
|
||||
return WorldConverter::startTask(folder, content, lut, [=](){
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
menu->reset();
|
||||
menu->setPage("main", false);
|
||||
engine->getGUI()->postRunnable([=]() {
|
||||
postRunnable();
|
||||
});
|
||||
}, true);
|
||||
const runnable& postRunnable
|
||||
) {
|
||||
return WorldConverter::startTask(
|
||||
folder,
|
||||
content,
|
||||
lut,
|
||||
[=]() {
|
||||
auto menu = engine->getGUI()->getMenu();
|
||||
menu->reset();
|
||||
menu->setPage("main", false);
|
||||
engine->getGUI()->postRunnable([=]() { postRunnable(); });
|
||||
},
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
void show_convert_request(
|
||||
Engine* engine,
|
||||
const Content* content,
|
||||
Engine* engine,
|
||||
const Content* content,
|
||||
const std::shared_ptr<ContentLUT>& lut,
|
||||
const fs::path& folder,
|
||||
const runnable& postRunnable
|
||||
) {
|
||||
guiutil::confirm(engine->getGUI(), langs::get(L"world.convert-request"), [=]() {
|
||||
auto converter = create_converter(engine, folder, content, lut, postRunnable);
|
||||
menus::show_process_panel(engine, converter, L"Converting world...");
|
||||
}, L"", langs::get(L"Cancel"));
|
||||
guiutil::confirm(
|
||||
engine->getGUI(),
|
||||
langs::get(L"world.convert-request"),
|
||||
[=]() {
|
||||
auto converter =
|
||||
create_converter(engine, folder, content, lut, postRunnable);
|
||||
menus::show_process_panel(
|
||||
engine, converter, L"Converting world..."
|
||||
);
|
||||
},
|
||||
L"",
|
||||
langs::get(L"Cancel")
|
||||
);
|
||||
}
|
||||
|
||||
static void show_content_missing(
|
||||
Engine* engine,
|
||||
const std::shared_ptr<ContentLUT>& lut
|
||||
Engine* engine, const std::shared_ptr<ContentLUT>& lut
|
||||
) {
|
||||
using namespace dynamic;
|
||||
auto root = create_map();
|
||||
@@ -97,11 +113,13 @@ static void loadWorld(Engine* engine, const fs::path& folder) {
|
||||
auto& settings = engine->getSettings();
|
||||
|
||||
auto level = World::load(folder, settings, content, packs);
|
||||
engine->setScreen(std::make_shared<LevelScreen>(engine, std::move(level)));
|
||||
engine->setScreen(
|
||||
std::make_shared<LevelScreen>(engine, std::move(level))
|
||||
);
|
||||
} catch (const world_load_error& error) {
|
||||
guiutil::alert(
|
||||
engine->getGUI(), langs::get(L"Error")+L": "+
|
||||
util::str2wstr_utf8(error.what())
|
||||
engine->getGUI(),
|
||||
langs::get(L"Error") + L": " + util::str2wstr_utf8(error.what())
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -109,25 +127,33 @@ static void loadWorld(Engine* engine, const fs::path& folder) {
|
||||
|
||||
void EngineController::openWorld(const std::string& name, bool confirmConvert) {
|
||||
auto paths = engine->getPaths();
|
||||
auto folder = paths->getWorldsFolder()/fs::u8path(name);
|
||||
auto folder = paths->getWorldsFolder() / fs::u8path(name);
|
||||
if (!loadWorldContent(engine, folder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* content = engine->getContent();
|
||||
|
||||
std::shared_ptr<ContentLUT> lut (World::checkIndices(folder, content));
|
||||
std::shared_ptr<ContentLUT> lut(World::checkIndices(folder, content));
|
||||
if (lut) {
|
||||
if (lut->hasMissingContent()) {
|
||||
engine->setScreen(std::make_shared<MenuScreen>(engine));
|
||||
show_content_missing(engine, lut);
|
||||
} else {
|
||||
if (confirmConvert) {
|
||||
menus::show_process_panel(engine, create_converter(engine, folder, content, lut, [=]() {
|
||||
openWorld(name, false);
|
||||
}), L"Converting world...");
|
||||
menus::show_process_panel(
|
||||
engine,
|
||||
create_converter(
|
||||
engine,
|
||||
folder,
|
||||
content,
|
||||
lut,
|
||||
[=]() { openWorld(name, false); }
|
||||
),
|
||||
L"Converting world..."
|
||||
);
|
||||
} else {
|
||||
show_convert_request(engine, content, lut, folder, [=](){
|
||||
show_convert_request(engine, content, lut, folder, [=]() {
|
||||
openWorld(name, false);
|
||||
});
|
||||
}
|
||||
@@ -152,24 +178,27 @@ inline uint64_t str2seed(const std::string& seedstr) {
|
||||
}
|
||||
|
||||
void EngineController::createWorld(
|
||||
const std::string& name,
|
||||
const std::string& name,
|
||||
const std::string& seedstr,
|
||||
const std::string& generatorID
|
||||
) {
|
||||
uint64_t seed = str2seed(seedstr);
|
||||
|
||||
EnginePaths* paths = engine->getPaths();
|
||||
auto folder = paths->getWorldsFolder()/fs::u8path(name);
|
||||
auto folder = paths->getWorldsFolder() / fs::u8path(name);
|
||||
|
||||
if (!menus::call(engine, [this, paths, folder]() {
|
||||
engine->loadContent();
|
||||
paths->setWorldFolder(folder);
|
||||
})) {
|
||||
engine->loadContent();
|
||||
paths->setWorldFolder(folder);
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
auto level = World::create(
|
||||
name, generatorID, folder, seed,
|
||||
engine->getSettings(),
|
||||
name,
|
||||
generatorID,
|
||||
folder,
|
||||
seed,
|
||||
engine->getSettings(),
|
||||
engine->getContent(),
|
||||
engine->getContentPacks()
|
||||
);
|
||||
@@ -208,7 +237,8 @@ void EngineController::reconfigPacks(
|
||||
try {
|
||||
auto manager = engine->createPacksManager(fs::path(""));
|
||||
manager.scan();
|
||||
std::vector<std::string> names = PacksManager::getNames(engine->getContentPacks());
|
||||
std::vector<std::string> names =
|
||||
PacksManager::getNames(engine->getContentPacks());
|
||||
for (const auto& id : packsToAdd) {
|
||||
names.push_back(id);
|
||||
}
|
||||
@@ -219,7 +249,9 @@ void EngineController::reconfigPacks(
|
||||
names = manager.assembly(names);
|
||||
engine->getContentPacks() = manager.getAll(names);
|
||||
} catch (const contentpack_error& err) {
|
||||
throw std::runtime_error(std::string(err.what())+" ["+err.getPackId()+"]");
|
||||
throw std::runtime_error(
|
||||
std::string(err.what()) + " [" + err.getPackId() + "]"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
auto world = controller->getLevel()->getWorld();
|
||||
@@ -244,10 +276,10 @@ void EngineController::reconfigPacks(
|
||||
|
||||
if (hasIndices) {
|
||||
guiutil::confirm(
|
||||
engine->getGUI(),
|
||||
langs::get(L"remove-confirm", L"pack")+
|
||||
L" ("+util::str2wstr_utf8(ss.str())+L")",
|
||||
[=]() {removeFunc();}
|
||||
engine->getGUI(),
|
||||
langs::get(L"remove-confirm", L"pack") + L" (" +
|
||||
util::str2wstr_utf8(ss.str()) + L")",
|
||||
[=]() { removeFunc(); }
|
||||
);
|
||||
} else {
|
||||
removeFunc();
|
||||
|
||||
Reference in New Issue
Block a user