-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the mod manager part of duskers mod manager
- Loading branch information
1 parent
e5f7c07
commit baf7f71
Showing
20 changed files
with
772 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 15 additions & 41 deletions
56
src/main/java/com/juanmuscaria/dmm/ModManagerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,27 @@ | ||
package com.juanmuscaria.dmm; | ||
|
||
import com.juanmuscaria.dmm.util.DialogHelper; | ||
import com.juanmuscaria.dmm.util.DuskersHelper; | ||
import com.juanmuscaria.dmm.event.FXEvent; | ||
import io.micronaut.context.ApplicationContext; | ||
import io.micronaut.context.event.ApplicationEventPublisher; | ||
import jakarta.inject.Singleton; | ||
import javafx.application.Application; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Stage; | ||
|
||
import atlantafx.base.theme.CupertinoLight; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
|
||
@Singleton | ||
public class ModManagerApplication extends Application { | ||
private static final Logger logger = LoggerFactory.getLogger(ModManagerApplication.class); | ||
@Override | ||
public void start(Stage stage) { | ||
setUserAgentStylesheet(new CupertinoLight().getUserAgentStylesheet()); | ||
try { | ||
Scene scene; | ||
if (DuskersHelper.isInstalled(Path.of(".")) || Boolean.getBoolean("dmm.forceLauncher")) { | ||
scene = new Scene(FXMLLoader.load( | ||
Objects.requireNonNull(getClass().getResource("/ui/duskers_launcher.fxml"), | ||
"Unable to load JavaFX resources"))); | ||
stage.setTitle("Duskers Mod Manager"); | ||
} else { | ||
scene = new Scene(FXMLLoader.load( | ||
Objects.requireNonNull(getClass().getResource("/ui/installer.fxml"), | ||
"Unable to load JavaFX resources"))); | ||
stage.setTitle("Duskers Mod Manager Installer"); | ||
} | ||
stage.setScene(scene); | ||
stage.show(); | ||
stage.setMinWidth(stage.getWidth()); | ||
stage.setMinHeight(stage.getHeight()); | ||
} catch (Throwable e) { | ||
logger.error("Unable to start GUI", e); | ||
DialogHelper.reportAndExit(e); | ||
} | ||
static ApplicationContext context; | ||
|
||
public ModManagerApplication() { | ||
} | ||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
@Override | ||
public void init() { | ||
context.registerSingleton(this); | ||
context.getEventPublisher(FXEvent.FXInit.class).publishEvent(new FXEvent.FXInit(this)); | ||
} | ||
|
||
public static Path getSelfPath() { | ||
return Path.of(ModManagerApplication.class.getProtectionDomain() | ||
.getCodeSource().getLocation().getPath()).toAbsolutePath(); | ||
@Override | ||
public void start(Stage primaryStage) { | ||
context.getEventPublisher(FXEvent.FXStart.class).publishEvent(new FXEvent.FXStart(this, primaryStage)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.juanmuscaria.dmm.data; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.micronaut.core.annotation.ReflectiveAccess; | ||
import lombok.*; | ||
import lombok.EqualsAndHashCode.Exclude; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
import java.nio.file.Path; | ||
|
||
@JsonSerialize | ||
@AllArgsConstructor | ||
@Builder | ||
@Jacksonized | ||
@Getter | ||
@Setter | ||
@EqualsAndHashCode | ||
@ToString | ||
@ReflectiveAccess | ||
public class ModEntry implements Comparable<ModEntry> { | ||
@ReflectiveAccess | ||
private final String modPath; | ||
@Exclude | ||
@ReflectiveAccess | ||
private final ModMetadata metadata; | ||
@Exclude // We don't want to compare state | ||
@ReflectiveAccess | ||
private boolean enabled; | ||
|
||
@Override | ||
public int compareTo(ModEntry other) { | ||
return this.getModPath().compareTo(other.getModPath()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.juanmuscaria.dmm.data; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.micronaut.core.annotation.ReflectiveAccess; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableSet; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.concurrent.ConcurrentSkipListSet; | ||
|
||
@JsonSerialize | ||
@ToString | ||
@ReflectiveAccess | ||
public class ModList { | ||
/** | ||
* This will be the actual backing set that will be written to disk, it must be both thread safe and sorted | ||
*/ | ||
@JsonProperty("mods") | ||
@ReflectiveAccess | ||
private ConcurrentSkipListSet<ModEntry> backend; | ||
|
||
/** | ||
* Observable wrapper to be used with javafx, changes must be done on the platform thread | ||
*/ | ||
@JsonIgnore | ||
@Getter | ||
private ObservableSet<ModEntry> mods; | ||
|
||
public ModList() { | ||
this(new ConcurrentSkipListSet<>()); | ||
} | ||
|
||
public ModList(ConcurrentSkipListSet<ModEntry> mods) { | ||
this.backend = mods; | ||
this.mods = FXCollections.observableSet(backend); | ||
} | ||
|
||
/** | ||
* Will be called by jackson | ||
*/ | ||
protected void setBackend(ConcurrentSkipListSet<ModEntry> backend) { | ||
this.backend = backend; | ||
this.mods = FXCollections.observableSet(backend); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.juanmuscaria.dmm.data; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.micronaut.core.annotation.ReflectiveAccess; | ||
|
||
@JsonSerialize | ||
@ReflectiveAccess | ||
public record ModMetadata(String name, String id, String version) { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.juanmuscaria.dmm.event; | ||
|
||
import io.micronaut.context.event.ApplicationEvent; | ||
import io.micronaut.core.annotation.NonNull; | ||
import javafx.stage.Stage; | ||
import lombok.Getter; | ||
|
||
public class FXEvent extends ApplicationEvent { | ||
public FXEvent(Object source) { | ||
super(source); | ||
} | ||
|
||
public static class FXInit extends FXEvent { | ||
public FXInit(Object source) { | ||
super(source); | ||
} | ||
} | ||
|
||
@Getter | ||
public static class FXStart extends @NonNull FXEvent { | ||
private final Stage primaryStage; | ||
|
||
public FXStart(Object source, Stage primaryStage) { | ||
super(source); | ||
this.primaryStage = primaryStage; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/juanmuscaria/dmm/service/FXMLLoaderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.juanmuscaria.dmm.service; | ||
|
||
import io.micronaut.context.ApplicationContext; | ||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.context.annotation.Prototype; | ||
import jakarta.inject.Inject; | ||
import javafx.fxml.FXMLLoader; | ||
|
||
@Factory | ||
class FXMLLoaderFactory { | ||
@Inject | ||
protected ApplicationContext context; | ||
|
||
@Prototype | ||
public FXMLLoader getLoader() { | ||
var loader = new FXMLLoader(); | ||
loader.setControllerFactory(context::getBean); | ||
return loader; | ||
} | ||
} |
Oops, something went wrong.