change: put settings initialization in a separate function
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
f1902a4471
commit
f432cfd73a
@ -52,6 +52,7 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
|
|||||||
: QObject()
|
: QObject()
|
||||||
{
|
{
|
||||||
m_settings = settings;
|
m_settings = settings;
|
||||||
|
m_global_settings = globalSettings;
|
||||||
m_rootDir = rootDir;
|
m_rootDir = rootDir;
|
||||||
|
|
||||||
m_settings->registerSetting("name", "Unnamed Instance");
|
m_settings->registerSetting("name", "Unnamed Instance");
|
||||||
|
@ -174,6 +174,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual SettingsObjectPtr settings() const;
|
virtual SettingsObjectPtr settings() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Loads instance settings if they're not already loaded.
|
||||||
|
*/
|
||||||
|
virtual void loadSettingsIfNeeded() = 0;
|
||||||
|
|
||||||
/// returns a valid update task
|
/// returns a valid update task
|
||||||
virtual Task::Ptr createUpdateTask(Net::Mode mode) = 0;
|
virtual Task::Ptr createUpdateTask(Net::Mode mode) = 0;
|
||||||
|
|
||||||
@ -285,7 +290,11 @@ protected slots:
|
|||||||
|
|
||||||
protected: /* data */
|
protected: /* data */
|
||||||
QString m_rootDir;
|
QString m_rootDir;
|
||||||
|
|
||||||
SettingsObjectPtr m_settings;
|
SettingsObjectPtr m_settings;
|
||||||
|
SettingsObjectWeakPtr m_global_settings;
|
||||||
|
bool m_settings_loaded = false;
|
||||||
|
|
||||||
// InstanceFlags m_flags;
|
// InstanceFlags m_flags;
|
||||||
bool m_isRunning = false;
|
bool m_isRunning = false;
|
||||||
shared_qobject_ptr<LaunchTask> m_launchProcess;
|
shared_qobject_ptr<LaunchTask> m_launchProcess;
|
||||||
|
@ -15,6 +15,10 @@ public:
|
|||||||
void saveNow() override
|
void saveNow() override
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
void loadSettingsIfNeeded() override
|
||||||
|
{
|
||||||
|
m_settings_loaded = true;
|
||||||
|
}
|
||||||
QString getStatusbarDescription() override
|
QString getStatusbarDescription() override
|
||||||
{
|
{
|
||||||
return tr("Unknown instance type");
|
return tr("Unknown instance type");
|
||||||
|
@ -115,6 +115,21 @@ private:
|
|||||||
MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
|
MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
|
||||||
: BaseInstance(globalSettings, settings, 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
|
// Java Settings
|
||||||
auto javaOverride = m_settings->registerSetting("OverrideJava", false);
|
auto javaOverride = m_settings->registerSetting("OverrideJava", false);
|
||||||
auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", 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 javaOrLocation = std::make_shared<OrSetting>("JavaOrLocationOverride", javaOverride, locationOverride);
|
||||||
auto javaOrArgs = std::make_shared<OrSetting>("JavaOrArgsOverride", javaOverride, argsOverride);
|
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("JavaPath"), javaOrLocation);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("JvmArgs"), javaOrArgs);
|
m_settings->registerOverride(globalSettings->getSetting("JvmArgs"), javaOrArgs);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("IgnoreJavaCompatibility"), javaOrLocation);
|
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("ShowGameTime"), gameTimeOverride);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("RecordGameTime"), 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
|
// Miscellaneous
|
||||||
auto miscellaneousOverride = m_settings->registerSetting("OverrideMiscellaneous", false);
|
auto miscellaneousOverride = m_settings->registerSetting("OverrideMiscellaneous", false);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("CloseAfterLaunch"), miscellaneousOverride);
|
m_settings->registerOverride(globalSettings->getSetting("CloseAfterLaunch"), miscellaneousOverride);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("QuitAfterGameStop"), miscellaneousOverride);
|
m_settings->registerOverride(globalSettings->getSetting("QuitAfterGameStop"), miscellaneousOverride);
|
||||||
|
|
||||||
m_settings->set("InstanceType", "OneSix");
|
m_settings->set("InstanceType", "OneSix");
|
||||||
|
}
|
||||||
|
|
||||||
m_components.reset(new PackProfile(this));
|
// Join server on launch, this does not have a global override
|
||||||
}
|
m_settings->registerSetting("JoinServerOnLaunch", false);
|
||||||
|
m_settings->registerSetting("JoinServerOnLaunchAddress", "");
|
||||||
|
|
||||||
void MinecraftInstance::saveNow()
|
m_settings_loaded = true;
|
||||||
{
|
|
||||||
m_components->saveNow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MinecraftInstance::typeName() const
|
QString MinecraftInstance::typeName() const
|
||||||
|
@ -20,6 +20,8 @@ public:
|
|||||||
virtual ~MinecraftInstance() {};
|
virtual ~MinecraftInstance() {};
|
||||||
virtual void saveNow() override;
|
virtual void saveNow() override;
|
||||||
|
|
||||||
|
void loadSettingsIfNeeded() override;
|
||||||
|
|
||||||
// FIXME: remove
|
// FIXME: remove
|
||||||
QString typeName() const override;
|
QString typeName() const override;
|
||||||
// FIXME: remove
|
// FIXME: remove
|
||||||
|
@ -25,6 +25,7 @@ class Setting;
|
|||||||
class SettingsObject;
|
class SettingsObject;
|
||||||
|
|
||||||
typedef std::shared_ptr<SettingsObject> SettingsObjectPtr;
|
typedef std::shared_ptr<SettingsObject> SettingsObjectPtr;
|
||||||
|
typedef std::weak_ptr<SettingsObject> SettingsObjectWeakPtr;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief The SettingsObject handles communicating settings between the application and a
|
* \brief The SettingsObject handles communicating settings between the application and a
|
||||||
|
Loading…
Reference in New Issue
Block a user