server: added setting to auto load last used world on startup, enabled by default

Dieser Commit ist enthalten in:
Reinder Feenstra 2022-01-03 10:52:18 +01:00
Ursprung dd3997b0d3
Commit cab2e8a130
4 geänderte Dateien mit 14 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -66,7 +66,8 @@ class Settings : public Object
Property<bool> localhostOnly;
Property<uint16_t> port;
Property<bool> discoverable;
Property<std::string> defaultWorld;
Property<std::string> lastWorld;
Property<bool> loadLastWorldOnStartup;
Property<bool> autoSaveWorldOnExit;
Property<bool> saveWorldUncompressed;
Property<bool> allowClientServerRestart;

Datei anzeigen

@ -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<WorldList>(m_dataDir / "world");
worldList = std::make_shared<WorldList>(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)
{

Datei anzeigen

@ -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)