change: put settings initialization in a separate function

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-07-06 15:56:03 -03:00
parent f1902a4471
commit f432cfd73a
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
6 changed files with 75 additions and 46 deletions

View File

@ -52,6 +52,7 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
: QObject()
{
m_settings = settings;
m_global_settings = globalSettings;
m_rootDir = rootDir;
m_settings->registerSetting("name", "Unnamed Instance");

View File

@ -174,6 +174,11 @@ public:
*/
virtual SettingsObjectPtr settings() const;
/*!
* \brief Loads instance settings if they're not already loaded.
*/
virtual void loadSettingsIfNeeded() = 0;
/// returns a valid update task
virtual Task::Ptr createUpdateTask(Net::Mode mode) = 0;
@ -285,7 +290,11 @@ protected slots:
protected: /* data */
QString m_rootDir;
SettingsObjectPtr m_settings;
SettingsObjectWeakPtr m_global_settings;
bool m_settings_loaded = false;
// InstanceFlags m_flags;
bool m_isRunning = false;
shared_qobject_ptr<LaunchTask> m_launchProcess;

View File

@ -15,6 +15,10 @@ public:
void saveNow() override
{
}
void loadSettingsIfNeeded() override
{
m_settings_loaded = true;
}
QString getStatusbarDescription() override
{
return tr("Unknown instance type");

View File

@ -115,6 +115,21 @@ private:
MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: BaseInstance(globalSettings, settings, rootDir)
{
loadSettingsIfNeeded();
m_components.reset(new PackProfile(this));
}
void MinecraftInstance::saveNow()
{
m_components->saveNow();
}
void MinecraftInstance::loadSettingsIfNeeded()
{
if (m_settings_loaded)
return;
// Java Settings
auto javaOverride = m_settings->registerSetting("OverrideJava", false);
auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", false);
@ -124,6 +139,7 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO
auto javaOrLocation = std::make_shared<OrSetting>("JavaOrLocationOverride", javaOverride, locationOverride);
auto javaOrArgs = std::make_shared<OrSetting>("JavaOrArgsOverride", javaOverride, argsOverride);
if (auto globalSettings = m_global_settings.lock()) {
m_settings->registerOverride(globalSettings->getSetting("JavaPath"), javaOrLocation);
m_settings->registerOverride(globalSettings->getSetting("JvmArgs"), javaOrArgs);
m_settings->registerOverride(globalSettings->getSetting("IgnoreJavaCompatibility"), javaOrLocation);
@ -165,23 +181,19 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO
m_settings->registerOverride(globalSettings->getSetting("ShowGameTime"), gameTimeOverride);
m_settings->registerOverride(globalSettings->getSetting("RecordGameTime"), gameTimeOverride);
// Join server on launch, this does not have a global override
m_settings->registerSetting("JoinServerOnLaunch", false);
m_settings->registerSetting("JoinServerOnLaunchAddress", "");
// Miscellaneous
auto miscellaneousOverride = m_settings->registerSetting("OverrideMiscellaneous", false);
m_settings->registerOverride(globalSettings->getSetting("CloseAfterLaunch"), miscellaneousOverride);
m_settings->registerOverride(globalSettings->getSetting("QuitAfterGameStop"), miscellaneousOverride);
m_settings->set("InstanceType", "OneSix");
m_components.reset(new PackProfile(this));
}
void MinecraftInstance::saveNow()
{
m_components->saveNow();
// Join server on launch, this does not have a global override
m_settings->registerSetting("JoinServerOnLaunch", false);
m_settings->registerSetting("JoinServerOnLaunchAddress", "");
m_settings_loaded = true;
}
QString MinecraftInstance::typeName() const

View File

@ -20,6 +20,8 @@ public:
virtual ~MinecraftInstance() {};
virtual void saveNow() override;
void loadSettingsIfNeeded() override;
// FIXME: remove
QString typeName() const override;
// FIXME: remove

View File

@ -25,6 +25,7 @@ class Setting;
class SettingsObject;
typedef std::shared_ptr<SettingsObject> SettingsObjectPtr;
typedef std::weak_ptr<SettingsObject> SettingsObjectWeakPtr;
/*!
* \brief The SettingsObject handles communicating settings between the application and a