*opinionated change* Remove LauncherFactory

Factories in OOP are a classic example of over-enginneering. When you only have two launchers I personally think that it's not very useful.

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2022-11-03 17:50:54 +00:00
parent fb677a7489
commit 1da834f650
7 changed files with 15 additions and 145 deletions

View File

@ -9,8 +9,6 @@ set(CMAKE_JAVA_COMPILE_FLAGS -target 7 -source 7 -Xlint:deprecation -Xlint:unche
set(SRC
org/prismlauncher/EntryPoint.java
org/prismlauncher/launcher/Launcher.java
org/prismlauncher/launcher/LauncherFactory.java
org/prismlauncher/launcher/LauncherProvider.java
org/prismlauncher/launcher/impl/legacy/LegacyFrame.java
org/prismlauncher/launcher/impl/legacy/LegacyLauncher.java
org/prismlauncher/launcher/impl/AbstractLauncher.java

View File

@ -57,7 +57,8 @@ package org.prismlauncher;
import org.prismlauncher.exception.ParseException;
import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.launcher.LauncherFactory;
import org.prismlauncher.launcher.impl.StandardLauncher;
import org.prismlauncher.launcher.impl.legacy.LegacyLauncher;
import org.prismlauncher.utils.Parameters;
import org.prismlauncher.utils.StringUtils;
@ -137,7 +138,19 @@ public final class EntryPoint {
}
try {
Launcher launcher = LauncherFactory.createLauncher(parameters);
Launcher launcher;
String type = parameters.getString("launcher");
switch (type) {
case "standard":
launcher = new StandardLauncher(parameters);
break;
case "legacy":
launcher = new LegacyLauncher(parameters);
break;
default:
throw new IllegalArgumentException("Invalid launcher type: " + type);
}
launcher.launch();

View File

@ -1,76 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher
*
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2022 Samisafool <thenerdiestguy@gmail.com>
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Linking this library statically or dynamically with other modules is
* making a combined work based on this library. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* As a special exception, the copyright holders of this library give
* you permission to link this library with independent modules to
* produce an executable, regardless of the license terms of these
* independent modules, and to copy and distribute the resulting
* executable under terms of your choice, provided that you also meet,
* for each linked independent module, the terms and conditions of the
* license of that module. An independent module is a module which is
* not derived from or based on this library. If you modify this
* library, you may extend this exception to your version of the
* library, but you are not obliged to do so. If you do not wish to do
* so, delete this exception statement from your version.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.prismlauncher.launcher;
import org.prismlauncher.launcher.impl.StandardLauncher;
import org.prismlauncher.launcher.impl.legacy.LegacyLauncher;
import org.prismlauncher.utils.Parameters;
public final class LauncherFactory {
private LauncherFactory()
{}
public static Launcher createLauncher(String launcherType, Parameters parameters)
{ return createLauncher(LauncherType.valueOf(launcherType.toUpperCase()), parameters); }
public static Launcher createLauncher(LauncherType launcherType, Parameters parameters)
{
LauncherProvider launcherProvider = launcherType.getLauncherProvider();
return launcherProvider.provide(parameters);
}
public static Launcher createLauncher(Parameters parameters)
{ return createLauncher(parameters.getString("launcher"), parameters); }
public enum LauncherType {
STANDARD(StandardLauncher.getProvider()), LEGACY(LegacyLauncher.getProvider());
private final LauncherProvider launcherProvider;
LauncherType(LauncherProvider launcherProvider) { this.launcherProvider = launcherProvider; }
public LauncherProvider getLauncherProvider() { return launcherProvider; }
}
}

View File

@ -1,46 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher
*
* Copyright (C) 2022 icelimetea <fr3shtea@outlook.com>
* Copyright (C) 2022 solonovamax <solonovamax@12oclockpoint.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Linking this library statically or dynamically with other modules is
* making a combined work based on this library. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* As a special exception, the copyright holders of this library give
* you permission to link this library with independent modules to
* produce an executable, regardless of the license terms of these
* independent modules, and to copy and distribute the resulting
* executable under terms of your choice, provided that you also meet,
* for each linked independent module, the terms and conditions of the
* license of that module. An independent module is a module which is
* not derived from or based on this library. If you modify this
* library, you may extend this exception to your version of the
* library, but you are not obliged to do so. If you do not wish to do
* so, delete this exception statement from your version.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.prismlauncher.launcher;
import org.prismlauncher.utils.Parameters;
public interface LauncherProvider {
Launcher provide(Parameters parameters);
}

View File

@ -55,8 +55,6 @@
package org.prismlauncher.launcher.impl;
import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.launcher.LauncherProvider;
import org.prismlauncher.utils.Parameters;
import org.prismlauncher.utils.ReflectionUtils;
@ -66,8 +64,6 @@ public final class StandardLauncher extends AbstractLauncher {
public StandardLauncher(Parameters params) { super(params); }
public static LauncherProvider getProvider() { return new StandardLauncherProvider(); }
@Override
public void launch() throws Throwable
{
@ -95,9 +91,4 @@ public final class StandardLauncher extends AbstractLauncher {
method.invokeExact(mcParams.toArray(new String[0]));
}
private static class StandardLauncherProvider implements LauncherProvider {
@Override
public Launcher provide(Parameters parameters) { return new StandardLauncher(parameters); }
}
}

View File

@ -64,7 +64,6 @@ import javax.swing.JFrame;
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

View File

@ -56,8 +56,6 @@
package org.prismlauncher.launcher.impl.legacy;
import org.prismlauncher.launcher.Launcher;
import org.prismlauncher.launcher.LauncherProvider;
import org.prismlauncher.launcher.impl.AbstractLauncher;
import org.prismlauncher.utils.Parameters;
import org.prismlauncher.utils.ReflectionUtils;
@ -98,8 +96,6 @@ public final class LegacyLauncher extends AbstractLauncher {
cwd = System.getProperty("user.dir");
}
public static LauncherProvider getProvider() { return new LegacyLauncherProvider(); }
@Override
public void launch() throws Throwable
{
@ -132,9 +128,4 @@ public final class LegacyLauncher extends AbstractLauncher {
method.invokeExact(mcParams.toArray(new String[0]));
}
private static class LegacyLauncherProvider implements LauncherProvider {
@Override
public Launcher provide(Parameters parameters) { return new LegacyLauncher(parameters); }
}
}