diff --git a/server/src/core/settings.cpp b/server/src/core/settings.cpp index d88116b5..edbf985e 100644 --- a/server/src/core/settings.cpp +++ b/server/src/core/settings.cpp @@ -49,7 +49,8 @@ Settings::Settings(const std::filesystem::path& path) : localhostOnly{this, "localhost_only", true, PropertyFlags::ReadWrite, [this](const bool&){ save(); }}, port{this, "port", defaultPort, PropertyFlags::ReadWrite, [this](const uint16_t&){ save(); }}, discoverable{this, "discoverable", true, PropertyFlags::ReadWrite, [this](const bool&){ save(); }}, - defaultWorld{this, "default_world", "", PropertyFlags::ReadWrite, [this](const std::string&){ save(); }}, + lastWorld{this, "last_world", "", PropertyFlags::ReadWrite | PropertyFlags::Internal, [this](const std::string&){ save(); }}, + loadLastWorldOnStartup{this, "load_last_world_on_startup", true, PropertyFlags::ReadWrite, [this](const bool&){ save(); }}, autoSaveWorldOnExit{this, "auto_save_world_on_exit", false, PropertyFlags::ReadWrite, [this](const bool&){ save(); }}, saveWorldUncompressed{this, "save_world_uncompressed", false, PropertyFlags::ReadWrite, [this](const bool&){ save(); }}, allowClientServerRestart{this, "allow_client_server_restart", false, PropertyFlags::ReadWrite, [this](const bool&){ save(); }}, @@ -57,7 +58,8 @@ Settings::Settings(const std::filesystem::path& path) : , memoryLoggerSize{this, Name::memoryLoggerSize, Default::memoryLoggerSize, PropertyFlags::ReadWrite, [this](const uint32_t&){ save(); }} , enableFileLogger{this, Name::enableFileLogger, Default::enableFileLogger, PropertyFlags::ReadWrite, [this](const bool&){ save(); }} { - m_interfaceItems.add(defaultWorld); + m_interfaceItems.add(lastWorld); + m_interfaceItems.add(loadLastWorldOnStartup); m_interfaceItems.add(autoSaveWorldOnExit); Attributes::addCategory(localhostOnly, Category::network); diff --git a/server/src/core/settings.hpp b/server/src/core/settings.hpp index 9766828c..13071015 100644 --- a/server/src/core/settings.hpp +++ b/server/src/core/settings.hpp @@ -66,7 +66,8 @@ class Settings : public Object Property localhostOnly; Property port; Property discoverable; - Property defaultWorld; + Property lastWorld; + Property loadLastWorldOnStartup; Property autoSaveWorldOnExit; Property saveWorldUncompressed; Property allowClientServerRestart; diff --git a/server/src/core/traintastic.cpp b/server/src/core/traintastic.cpp index bc9d8c7c..c95917ef 100644 --- a/server/src/core/traintastic.cpp +++ b/server/src/core/traintastic.cpp @@ -58,6 +58,7 @@ Traintastic::Traintastic(const std::filesystem::path& dataDir) : world = World::create(); Log::log(*this, LogMessage::N1002_CREATED_NEW_WORLD); world->edit = true; + settings->lastWorld = ""; }}, loadWorld{*this, "load_world", [this](const std::string& _uuid) @@ -119,10 +120,10 @@ Traintastic::RunStatus Traintastic::run() Attributes::setEnabled(restart, settings->allowClientServerRestart); Attributes::setEnabled(shutdown, settings->allowClientServerShutdown); - worldList = std::make_shared(m_dataDir / "world"); + worldList = std::make_shared(worldDir()); - if(!settings->defaultWorld.value().empty()) - loadWorld(settings->defaultWorld.value()); + if(settings->loadLastWorldOnStartup && !settings->lastWorld.value().empty()) + loadWorld(settings->lastWorld.value()); if(!start()) return ExitFailure; @@ -251,6 +252,7 @@ void Traintastic::load(const std::filesystem::path& path) try { world = WorldLoader(path).world(); + settings->lastWorld = world->uuid.value(); } catch(const std::exception& e) { diff --git a/server/src/world/world.cpp b/server/src/world/world.cpp index 31a98392..ce95f91b 100644 --- a/server/src/world/world.cpp +++ b/server/src/world/world.cpp @@ -223,6 +223,9 @@ World::World(Private) : WorldSaver saver(*this, savePath); + if(Traintastic::instance) + Traintastic::instance->settings->lastWorld = uuid.value(); + Log::log(*this, LogMessage::N1022_SAVED_WORLD_X, name.value()); } catch(const std::exception& e)