add setting for quickplay singleplayer

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2024-08-08 16:53:26 +03:00
parent 0308710211
commit c9809fff6d
29 changed files with 253 additions and 128 deletions

View File

@ -236,6 +236,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
{ { { "d", "dir" }, "Use a custom path as application root (use '.' for current directory)", "directory" },
{ { "l", "launch" }, "Launch the specified instance (by instance ID)", "instance" },
{ { "s", "server" }, "Join the specified server on launch (only valid in combination with --launch)", "address" },
{ { "w", "world" }, "Join the specified world on launch (only valid in combination with --launch)", "world" },
{ { "a", "profile" }, "Use the account specified by its profile name (only valid in combination with --launch)", "profile" },
{ "alive", "Write a small '" + liveCheckFile + "' file after the launcher starts" },
{ { "I", "import" }, "Import instance or resource from specified local path or URL", "url" },
@ -249,7 +250,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
parser.process(arguments());
m_instanceIdToLaunch = parser.value("launch");
m_serverToJoin = parser.value("server");
m_server_to_join = parser.value("server");
m_world_to_join = parser.value("world");
m_profileToUse = parser.value("profile");
m_liveCheck = parser.isSet("alive");
@ -265,7 +267,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
}
// error if --launch is missing with --server or --profile
if ((!m_serverToJoin.isEmpty() || !m_profileToUse.isEmpty()) && m_instanceIdToLaunch.isEmpty()) {
if (((!m_server_to_join.isEmpty() || !m_world_to_join.isEmpty()) || !m_profileToUse.isEmpty()) && m_instanceIdToLaunch.isEmpty()) {
std::cerr << "--server and --profile can only be used in combination with --launch!" << std::endl;
m_status = Application::Failed;
return;
@ -383,8 +385,10 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
launch.command = "launch";
launch.args["id"] = m_instanceIdToLaunch;
if (!m_serverToJoin.isEmpty()) {
launch.args["server"] = m_serverToJoin;
if (!m_server_to_join.isEmpty()) {
launch.args["server"] = m_server_to_join;
} else if (!m_world_to_join.isEmpty()) {
launch.args["world"] = m_world_to_join;
}
if (!m_profileToUse.isEmpty()) {
launch.args["profile"] = m_profileToUse;
@ -521,8 +525,10 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
if (!m_instanceIdToLaunch.isEmpty()) {
qDebug() << "ID of instance to launch : " << m_instanceIdToLaunch;
}
if (!m_serverToJoin.isEmpty()) {
qDebug() << "Address of server to join :" << m_serverToJoin;
if (!m_server_to_join.isEmpty()) {
qDebug() << "Address of server to join :" << m_server_to_join;
} else if (!m_world_to_join.isEmpty()) {
qDebug() << "Name of the world to join :" << m_world_to_join;
}
qDebug() << "<> Paths set.";
}
@ -1157,14 +1163,17 @@ void Application::performMainStartupAction()
if (!m_instanceIdToLaunch.isEmpty()) {
auto inst = instances()->getInstanceById(m_instanceIdToLaunch);
if (inst) {
MinecraftServerTargetPtr serverToJoin = nullptr;
MinecraftTarget::Ptr targetToJoin = nullptr;
MinecraftAccountPtr accountToUse = nullptr;
qDebug() << "<> Instance" << m_instanceIdToLaunch << "launching";
if (!m_serverToJoin.isEmpty()) {
if (!m_server_to_join.isEmpty()) {
// FIXME: validate the server string
serverToJoin.reset(new MinecraftServerTarget(MinecraftServerTarget::parse(m_serverToJoin)));
qDebug() << " Launching with server" << m_serverToJoin;
targetToJoin.reset(new MinecraftTarget(MinecraftTarget::parse(m_server_to_join, false)));
qDebug() << " Launching with server" << m_server_to_join;
} else if (!m_world_to_join.isEmpty()) {
targetToJoin.reset(new MinecraftTarget(MinecraftTarget::parse(m_world_to_join, true)));
qDebug() << " Launching with world" << m_world_to_join;
}
if (!m_profileToUse.isEmpty()) {
@ -1175,7 +1184,7 @@ void Application::performMainStartupAction()
qDebug() << " Launching with account" << m_profileToUse;
}
launch(inst, true, false, serverToJoin, accountToUse);
launch(inst, true, false, targetToJoin, accountToUse);
return;
}
}
@ -1265,6 +1274,7 @@ void Application::messageReceived(const QByteArray& message)
} else if (command == "launch") {
QString id = received.args["id"];
QString server = received.args["server"];
QString world = received.args["world"];
QString profile = received.args["profile"];
InstancePtr instance;
@ -1279,11 +1289,12 @@ void Application::messageReceived(const QByteArray& message)
return;
}
MinecraftServerTargetPtr serverObject = nullptr;
MinecraftTarget::Ptr serverObject = nullptr;
if (!server.isEmpty()) {
serverObject = std::make_shared<MinecraftServerTarget>(MinecraftServerTarget::parse(server));
serverObject = std::make_shared<MinecraftTarget>(MinecraftTarget::parse(server, false));
} else if (!world.isEmpty()) {
serverObject = std::make_shared<MinecraftTarget>(MinecraftTarget::parse(world, true));
}
MinecraftAccountPtr accountObject;
if (!profile.isEmpty()) {
accountObject = accounts()->getAccountByProfileName(profile);
@ -1332,11 +1343,7 @@ bool Application::openJsonEditor(const QString& filename)
}
}
bool Application::launch(InstancePtr instance,
bool online,
bool demo,
MinecraftServerTargetPtr serverToJoin,
MinecraftAccountPtr accountToUse)
bool Application::launch(InstancePtr instance, bool online, bool demo, MinecraftTarget::Ptr targetToJoin, MinecraftAccountPtr accountToUse)
{
if (m_updateRunning) {
qDebug() << "Cannot launch instances while an update is running. Please try again when updates are completed.";
@ -1354,7 +1361,7 @@ bool Application::launch(InstancePtr instance,
controller->setOnline(online);
controller->setDemo(demo);
controller->setProfiler(profilers().value(instance->settings()->get("Profiler").toString(), nullptr).get());
controller->setServerToJoin(serverToJoin);
controller->setTargetToJoin(targetToJoin);
controller->setAccountToUse(accountToUse);
if (window) {
controller->setParentWidget(window);