fix app.* functions & update 'world' test
This commit is contained in:
parent
4a6689104a
commit
30a8ddf2d3
@ -1,4 +1,4 @@
|
|||||||
local util = require("core:tests_util")
|
local util = require "core:tests_util"
|
||||||
util.create_demo_world()
|
util.create_demo_world()
|
||||||
|
|
||||||
app.set_setting("chunks.load-distance", 3)
|
app.set_setting("chunks.load-distance", 3)
|
||||||
@ -27,3 +27,4 @@ end
|
|||||||
player.delete(pid2)
|
player.delete(pid2)
|
||||||
|
|
||||||
app.close_world(true)
|
app.close_world(true)
|
||||||
|
app.delete_world("demo")
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
-- Create/close/open/close world
|
-- Create/close/open/close world
|
||||||
|
|
||||||
-- Open
|
-- Open
|
||||||
|
app.reconfig_packs({"base"}, {})
|
||||||
app.new_world("demo", "2019", "core:default")
|
app.new_world("demo", "2019", "core:default")
|
||||||
assert(world.is_open())
|
assert(world.is_open())
|
||||||
assert(world.get_generator() == "core:default")
|
assert(world.get_generator() == "core:default")
|
||||||
@ -18,6 +19,9 @@ assert(world.is_open())
|
|||||||
assert(world.get_total_time() > 0.0)
|
assert(world.get_total_time() > 0.0)
|
||||||
assert(world.get_seed() == 2019)
|
assert(world.get_seed() == 2019)
|
||||||
app.tick()
|
app.tick()
|
||||||
|
app.reconfig_packs({}, {"base"})
|
||||||
|
app.tick()
|
||||||
|
|
||||||
-- Close
|
-- Close
|
||||||
app.close_world(true)
|
app.close_world(true)
|
||||||
|
app.delete_world("demo")
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "coders/commons.hpp"
|
#include "coders/commons.hpp"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
|
#include "coders/json.hpp"
|
||||||
#include "content/ContentReport.hpp"
|
#include "content/ContentReport.hpp"
|
||||||
#include "files/WorldConverter.hpp"
|
#include "files/WorldConverter.hpp"
|
||||||
#include "files/WorldFiles.hpp"
|
#include "files/WorldFiles.hpp"
|
||||||
@ -32,14 +33,21 @@ EngineController::EngineController(Engine& engine) : engine(engine) {
|
|||||||
|
|
||||||
void EngineController::deleteWorld(const std::string& name) {
|
void EngineController::deleteWorld(const std::string& name) {
|
||||||
fs::path folder = engine.getPaths().getWorldFolderByName(name);
|
fs::path folder = engine.getPaths().getWorldFolderByName(name);
|
||||||
|
|
||||||
|
auto deletion = [&]() {
|
||||||
|
logger.info() << "deleting " << folder;
|
||||||
|
fs::remove_all(folder);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (engine.isHeadless()) {
|
||||||
|
deletion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
guiutil::confirm(
|
guiutil::confirm(
|
||||||
engine.getGUI()->getMenu(),
|
engine.getGUI()->getMenu(),
|
||||||
langs::get(L"delete-confirm", L"world") + L" (" +
|
langs::get(L"delete-confirm", L"world") + L" (" +
|
||||||
util::str2wstr_utf8(folder.u8string()) + L")",
|
util::str2wstr_utf8(folder.u8string()) + L")",
|
||||||
[=]() {
|
deletion
|
||||||
logger.info() << "deleting " << folder.u8string();
|
|
||||||
fs::remove_all(folder);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +71,10 @@ std::shared_ptr<Task> create_converter(
|
|||||||
content,
|
content,
|
||||||
report,
|
report,
|
||||||
[&engine, postRunnable]() {
|
[&engine, postRunnable]() {
|
||||||
auto menu = engine.getGUI()->getMenu();
|
//auto menu = engine.getGUI()->getMenu();
|
||||||
menu->reset();
|
//menu->reset();
|
||||||
menu->setPage("main", false);
|
//menu->setPage("main", false);
|
||||||
engine.getGUI()->postRunnable([=]() { postRunnable(); });
|
engine.postRunnable([=]() { postRunnable(); });
|
||||||
},
|
},
|
||||||
mode,
|
mode,
|
||||||
true
|
true
|
||||||
@ -119,20 +127,6 @@ static void show_convert_request(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_content_missing(
|
|
||||||
Engine& engine, const std::shared_ptr<ContentReport>& report
|
|
||||||
) {
|
|
||||||
auto root = dv::object();
|
|
||||||
auto& contentEntries = root.list("content");
|
|
||||||
for (auto& entry : report->getMissingContent()) {
|
|
||||||
std::string contentName = ContentType_name(entry.type);
|
|
||||||
auto& contentEntry = contentEntries.object();
|
|
||||||
contentEntry["type"] = contentName;
|
|
||||||
contentEntry["name"] = entry.name;
|
|
||||||
}
|
|
||||||
menus::show(engine, "reports/missing_content", {std::move(root)});
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool load_world_content(Engine& engine, const fs::path& folder) {
|
static bool load_world_content(Engine& engine, const fs::path& folder) {
|
||||||
if (engine.isHeadless()) {
|
if (engine.isHeadless()) {
|
||||||
engine.loadWorldContent(folder);
|
engine.loadWorldContent(folder);
|
||||||
@ -163,6 +157,36 @@ static void load_world(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static dv::value create_missing_content_report(
|
||||||
|
const std::shared_ptr<ContentReport>& report
|
||||||
|
) {
|
||||||
|
auto root = dv::object();
|
||||||
|
auto& contentEntries = root.list("content");
|
||||||
|
for (auto& entry : report->getMissingContent()) {
|
||||||
|
std::string contentName = ContentType_name(entry.type);
|
||||||
|
auto& contentEntry = contentEntries.object();
|
||||||
|
contentEntry["type"] = contentName;
|
||||||
|
contentEntry["name"] = entry.name;
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EngineController::onMissingContent(const std::shared_ptr<ContentReport>& report) {
|
||||||
|
if (engine.isHeadless()) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
"missing content: " +
|
||||||
|
json::stringify(create_missing_content_report(report), true)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
||||||
|
menus::show(
|
||||||
|
engine,
|
||||||
|
"reports/missing_content",
|
||||||
|
{create_missing_content_report(report)}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EngineController::openWorld(const std::string& name, bool confirmConvert) {
|
void EngineController::openWorld(const std::string& name, bool confirmConvert) {
|
||||||
const auto& paths = engine.getPaths();
|
const auto& paths = engine.getPaths();
|
||||||
auto folder = paths.getWorldsFolder() / fs::u8path(name);
|
auto folder = paths.getWorldsFolder() / fs::u8path(name);
|
||||||
@ -180,21 +204,23 @@ void EngineController::openWorld(const std::string& name, bool confirmConvert) {
|
|||||||
folder, engine.getSettings().debug);
|
folder, engine.getSettings().debug);
|
||||||
if (auto report = World::checkIndices(worldFiles, content)) {
|
if (auto report = World::checkIndices(worldFiles, content)) {
|
||||||
if (report->hasMissingContent()) {
|
if (report->hasMissingContent()) {
|
||||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
onMissingContent(report);
|
||||||
show_content_missing(engine, report);
|
|
||||||
} else {
|
} else {
|
||||||
if (confirmConvert) {
|
if (confirmConvert) {
|
||||||
menus::show_process_panel(
|
auto task = create_converter(
|
||||||
engine,
|
engine,
|
||||||
create_converter(
|
worldFiles,
|
||||||
engine,
|
content,
|
||||||
worldFiles,
|
report,
|
||||||
content,
|
[=]() { openWorld(name, false); }
|
||||||
report,
|
|
||||||
[=]() { openWorld(name, false); }
|
|
||||||
),
|
|
||||||
L"Converting world..."
|
|
||||||
);
|
);
|
||||||
|
if (engine.isHeadless()) {
|
||||||
|
task->waitForEnd();
|
||||||
|
} else {
|
||||||
|
menus::show_process_panel(
|
||||||
|
engine, task, L"Converting world..."
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
show_convert_request(engine, content, report, std::move(worldFiles), [=]() {
|
show_convert_request(engine, content, report, std::move(worldFiles), [=]() {
|
||||||
openWorld(name, false);
|
openWorld(name, false);
|
||||||
@ -255,10 +281,9 @@ void EngineController::createWorld(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EngineController::reopenWorld(World* world) {
|
void EngineController::reopenWorld(World* world) {
|
||||||
std::string wname = world->wfile->getFolder().filename().u8string();
|
std::string name = world->wfile->getFolder().filename().u8string();
|
||||||
engine.setScreen(nullptr);
|
engine.onWorldClosed();
|
||||||
engine.setScreen(std::make_shared<MenuScreen>(engine));
|
openWorld(name, true);
|
||||||
openWorld(wname, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineController::reconfigPacks(
|
void EngineController::reconfigPacks(
|
||||||
@ -316,7 +341,13 @@ void EngineController::reconfigPacks(
|
|||||||
}
|
}
|
||||||
for (const auto& id : packsToRemove) {
|
for (const auto& id : packsToRemove) {
|
||||||
manager.exclude(id);
|
manager.exclude(id);
|
||||||
names.erase(std::find(names.begin(), names.end(), id));
|
const auto& found = std::find(names.begin(), names.end(), id);
|
||||||
|
if (found != names.end()) {
|
||||||
|
names.erase(found);
|
||||||
|
} else {
|
||||||
|
logger.warning()
|
||||||
|
<< "attempt to remove non-installed pack: " << id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wfile.removeIndices(packsToRemove);
|
wfile.removeIndices(packsToRemove);
|
||||||
wfile.writePacks(manager.getAll(names));
|
wfile.writePacks(manager.getAll(names));
|
||||||
@ -324,7 +355,7 @@ void EngineController::reconfigPacks(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (hasIndices) {
|
if (hasIndices && !engine.isHeadless()) {
|
||||||
guiutil::confirm(
|
guiutil::confirm(
|
||||||
engine.getGUI()->getMenu(),
|
engine.getGUI()->getMenu(),
|
||||||
langs::get(L"remove-confirm", L"pack") + L" (" +
|
langs::get(L"remove-confirm", L"pack") + L" (" +
|
||||||
|
|||||||
@ -2,13 +2,17 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class Engine;
|
class Engine;
|
||||||
class World;
|
class World;
|
||||||
|
class ContentReport;
|
||||||
class LevelController;
|
class LevelController;
|
||||||
|
|
||||||
class EngineController {
|
class EngineController {
|
||||||
Engine& engine;
|
Engine& engine;
|
||||||
|
|
||||||
|
void onMissingContent(const std::shared_ptr<ContentReport>& report);
|
||||||
public:
|
public:
|
||||||
EngineController(Engine& engine);
|
EngineController(Engine& engine);
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ int main(int argc, char** argv) {
|
|||||||
} catch (const initialize_error& err) {
|
} catch (const initialize_error& err) {
|
||||||
logger.error() << "could not to initialize engine\n" << err.what();
|
logger.error() << "could not to initialize engine\n" << err.what();
|
||||||
}
|
}
|
||||||
#ifdef NDEBUG
|
#if defined(NDEBUG) and defined(_WIN32)
|
||||||
catch (const std::exception& err) {
|
catch (const std::exception& err) {
|
||||||
logger.error() << "uncaught exception: " << err.what();
|
logger.error() << "uncaught exception: " << err.what();
|
||||||
debug::Logger::flush();
|
debug::Logger::flush();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user