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,64 +139,61 @@ 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);
|
||||||
|
|
||||||
m_settings->registerOverride(globalSettings->getSetting("JavaPath"), javaOrLocation);
|
if (auto globalSettings = m_global_settings.lock()) {
|
||||||
m_settings->registerOverride(globalSettings->getSetting("JvmArgs"), javaOrArgs);
|
m_settings->registerOverride(globalSettings->getSetting("JavaPath"), javaOrLocation);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("IgnoreJavaCompatibility"), javaOrLocation);
|
m_settings->registerOverride(globalSettings->getSetting("JvmArgs"), javaOrArgs);
|
||||||
|
m_settings->registerOverride(globalSettings->getSetting("IgnoreJavaCompatibility"), javaOrLocation);
|
||||||
|
|
||||||
// special!
|
// special!
|
||||||
m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), javaOrLocation);
|
m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), javaOrLocation);
|
||||||
m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), javaOrLocation);
|
m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), javaOrLocation);
|
||||||
m_settings->registerPassthrough(globalSettings->getSetting("JavaArchitecture"), javaOrLocation);
|
m_settings->registerPassthrough(globalSettings->getSetting("JavaArchitecture"), javaOrLocation);
|
||||||
|
|
||||||
// Window Size
|
// Window Size
|
||||||
auto windowSetting = m_settings->registerSetting("OverrideWindow", false);
|
auto windowSetting = m_settings->registerSetting("OverrideWindow", false);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("LaunchMaximized"), windowSetting);
|
m_settings->registerOverride(globalSettings->getSetting("LaunchMaximized"), windowSetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("MinecraftWinWidth"), windowSetting);
|
m_settings->registerOverride(globalSettings->getSetting("MinecraftWinWidth"), windowSetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("MinecraftWinHeight"), windowSetting);
|
m_settings->registerOverride(globalSettings->getSetting("MinecraftWinHeight"), windowSetting);
|
||||||
|
|
||||||
// Memory
|
// Memory
|
||||||
auto memorySetting = m_settings->registerSetting("OverrideMemory", false);
|
auto memorySetting = m_settings->registerSetting("OverrideMemory", false);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("MinMemAlloc"), memorySetting);
|
m_settings->registerOverride(globalSettings->getSetting("MinMemAlloc"), memorySetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("MaxMemAlloc"), memorySetting);
|
m_settings->registerOverride(globalSettings->getSetting("MaxMemAlloc"), memorySetting);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("PermGen"), memorySetting);
|
m_settings->registerOverride(globalSettings->getSetting("PermGen"), memorySetting);
|
||||||
|
|
||||||
// Minecraft launch method
|
// Minecraft launch method
|
||||||
auto launchMethodOverride = m_settings->registerSetting("OverrideMCLaunchMethod", false);
|
auto launchMethodOverride = m_settings->registerSetting("OverrideMCLaunchMethod", false);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("MCLaunchMethod"), launchMethodOverride);
|
m_settings->registerOverride(globalSettings->getSetting("MCLaunchMethod"), launchMethodOverride);
|
||||||
|
|
||||||
// Native library workarounds
|
// Native library workarounds
|
||||||
auto nativeLibraryWorkaroundsOverride = m_settings->registerSetting("OverrideNativeWorkarounds", false);
|
auto nativeLibraryWorkaroundsOverride = m_settings->registerSetting("OverrideNativeWorkarounds", false);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride);
|
m_settings->registerOverride(globalSettings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride);
|
m_settings->registerOverride(globalSettings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride);
|
||||||
|
|
||||||
// Peformance related options
|
// Peformance related options
|
||||||
auto performanceOverride = m_settings->registerSetting("OverridePerformance", false);
|
auto performanceOverride = m_settings->registerSetting("OverridePerformance", false);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("EnableFeralGamemode"), performanceOverride);
|
m_settings->registerOverride(globalSettings->getSetting("EnableFeralGamemode"), performanceOverride);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("EnableMangoHud"), performanceOverride);
|
m_settings->registerOverride(globalSettings->getSetting("EnableMangoHud"), performanceOverride);
|
||||||
m_settings->registerOverride(globalSettings->getSetting("UseDiscreteGpu"), performanceOverride);
|
m_settings->registerOverride(globalSettings->getSetting("UseDiscreteGpu"), performanceOverride);
|
||||||
|
|
||||||
// Game time
|
// Game time
|
||||||
auto gameTimeOverride = m_settings->registerSetting("OverrideGameTime", false);
|
auto gameTimeOverride = m_settings->registerSetting("OverrideGameTime", false);
|
||||||
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);
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
}
|
||||||
|
|
||||||
// Join server on launch, this does not have a global override
|
// Join server on launch, this does not have a global override
|
||||||
m_settings->registerSetting("JoinServerOnLaunch", false);
|
m_settings->registerSetting("JoinServerOnLaunch", false);
|
||||||
m_settings->registerSetting("JoinServerOnLaunchAddress", "");
|
m_settings->registerSetting("JoinServerOnLaunchAddress", "");
|
||||||
|
|
||||||
// Miscellaneous
|
m_settings_loaded = true;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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