add test.close_world(bool)
This commit is contained in:
parent
9b4dd8f65e
commit
d3f74b56fa
@ -1,2 +1,4 @@
|
||||
test.new_world("demo", "2019", "core:default")
|
||||
print(world.get_generator())
|
||||
assert(world.get_generator() == "core:default")
|
||||
test.close_world(true)
|
||||
assert(not world.is_open())
|
||||
|
||||
@ -13,6 +13,7 @@ if test then
|
||||
test.sleep = sleep
|
||||
test.name = __VC_TEST_NAME
|
||||
test.new_world = core.new_world
|
||||
test.close_world = core.close_world
|
||||
end
|
||||
|
||||
------------------------------------------------
|
||||
|
||||
@ -16,7 +16,14 @@ void Mainloop::run() {
|
||||
auto& time = engine.getTime();
|
||||
|
||||
engine.setLevelConsumer([this](auto level) {
|
||||
engine.setScreen(std::make_shared<LevelScreen>(&engine, std::move(level)));
|
||||
if (level == nullptr) {
|
||||
// destroy LevelScreen and run quit callbacks
|
||||
engine.setScreen(nullptr);
|
||||
// create and go to menu screen
|
||||
engine.setScreen(std::make_shared<MenuScreen>(&engine));
|
||||
} else {
|
||||
engine.setScreen(std::make_shared<LevelScreen>(&engine, std::move(level)));
|
||||
}
|
||||
});
|
||||
|
||||
logger.info() << "starting menu screen";
|
||||
|
||||
@ -38,5 +38,11 @@ void TestMainloop::run() {
|
||||
}
|
||||
|
||||
void TestMainloop::setLevel(std::unique_ptr<Level> level) {
|
||||
this->controller = std::make_unique<LevelController>(&engine, std::move(level));
|
||||
if (level == nullptr) {
|
||||
controller->onWorldQuit();
|
||||
engine.getPaths()->setCurrentWorldFolder(fs::path());
|
||||
controller = nullptr;
|
||||
} else {
|
||||
controller = std::make_unique<LevelController>(&engine, std::move(level));
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,8 +18,6 @@
|
||||
#include "frontend/locale.hpp"
|
||||
#include "frontend/menu.hpp"
|
||||
#include "frontend/screens/Screen.hpp"
|
||||
#include "frontend/screens/MenuScreen.hpp"
|
||||
#include "frontend/screens/LevelScreen.hpp"
|
||||
#include "graphics/render/ModelsGenerator.hpp"
|
||||
#include "graphics/core/DrawContext.hpp"
|
||||
#include "graphics/core/ImageData.hpp"
|
||||
@ -454,9 +452,15 @@ void Engine::setLanguage(std::string locale) {
|
||||
}
|
||||
|
||||
void Engine::onWorldOpen(std::unique_ptr<Level> level) {
|
||||
logger.info() << "world open";
|
||||
levelConsumer(std::move(level));
|
||||
}
|
||||
|
||||
void Engine::onWorldClosed() {
|
||||
logger.info() << "world closed";
|
||||
levelConsumer(nullptr);
|
||||
}
|
||||
|
||||
gui::GUI* Engine::getGUI() {
|
||||
return gui.get();
|
||||
}
|
||||
|
||||
@ -135,6 +135,7 @@ public:
|
||||
ResPaths* getResPaths();
|
||||
|
||||
void onWorldOpen(std::unique_ptr<Level> level);
|
||||
void onWorldClosed();
|
||||
|
||||
/// @brief Get current Content instance
|
||||
const Content* getContent() const;
|
||||
|
||||
@ -54,8 +54,9 @@ void LevelController::update(float delta, bool input, bool pause) {
|
||||
}
|
||||
|
||||
void LevelController::saveWorld() {
|
||||
level->getWorld()->wfile->createDirectories();
|
||||
logger.info() << "writing world";
|
||||
auto world = level->getWorld();
|
||||
logger.info() << "writing world '" << world->getName() << "'";
|
||||
world->wfile->createDirectories();
|
||||
scripting::on_world_save();
|
||||
level->onSave();
|
||||
level->getWorld()->write(level.get());
|
||||
|
||||
@ -69,10 +69,7 @@ static int l_close_world(lua::State* L) {
|
||||
if (save_world) {
|
||||
controller->saveWorld();
|
||||
}
|
||||
// destroy LevelScreen and run quit callbacks
|
||||
engine->setScreen(nullptr);
|
||||
// create and go to menu screen
|
||||
engine->setScreen(std::make_shared<MenuScreen>(engine));
|
||||
engine->onWorldClosed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user