Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Schnick committed Dec 9, 2020
1 parent 400c637 commit 64bd523
Show file tree
Hide file tree
Showing 58 changed files with 378 additions and 387 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id 'org.beryx.jlink' version '2.22.3'
}

setVersion '2.0-beta6'
setVersion '2.0-beta7'

if (!file("${projectDir}/pdxu.properties").exists()) {
file("${projectDir}/pdxu.properties").write(file("${projectDir}/pdxu.properties.default").getText())
Expand Down
30 changes: 16 additions & 14 deletions app/src/main/java/com/crschnick/pdx_unlimiter/app/PdxuApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,34 @@

import com.crschnick.pdx_unlimiter.app.achievement.AchievementManager;
import com.crschnick.pdx_unlimiter.app.game.GameAppManager;
import com.crschnick.pdx_unlimiter.app.game.GameInstallation;
import com.crschnick.pdx_unlimiter.app.game.GameIntegration;
import com.crschnick.pdx_unlimiter.app.gui.*;
import com.crschnick.pdx_unlimiter.app.gui.GameImage;
import com.crschnick.pdx_unlimiter.app.gui.GuiLayout;
import com.crschnick.pdx_unlimiter.app.gui.GuiSettings;
import com.crschnick.pdx_unlimiter.app.gui.GuiStyle;
import com.crschnick.pdx_unlimiter.app.installation.ErrorHandler;
import com.crschnick.pdx_unlimiter.app.installation.LogManager;
import com.crschnick.pdx_unlimiter.app.installation.PdxuInstallation;
import com.crschnick.pdx_unlimiter.app.installation.Settings;
import com.crschnick.pdx_unlimiter.app.savegame.FileImportTarget;
import com.crschnick.pdx_unlimiter.app.savegame.FileImporter;
import com.crschnick.pdx_unlimiter.app.savegame.SavegameCache;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import org.jnativehook.GlobalScreen;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PdxuApp extends Application {

Expand All @@ -45,10 +42,6 @@ public static PdxuApp getApp() {
return APP;
}

public StackPane getLayout() {
return layout;
}

public static void main(String[] args) {
try {
launch(args);
Expand All @@ -57,6 +50,10 @@ public static void main(String[] args) {
}
}

public StackPane getLayout() {
return layout;
}

public Scene getScene() {
return layout.getScene();
}
Expand All @@ -79,7 +76,12 @@ private void setup() throws Exception {
ErrorHandler.init();

LoggerFactory.getLogger(PdxuApp.class).info("Running pdxu with arguments: " + getParameters().getRaw());
FileImporter.addToImportQueue(getParameters().getRaw().stream().map(Path::of).collect(Collectors.toList()));
getParameters().getRaw().stream()
.map(Path::of)
.map(p -> FileImportTarget.createTargets(p).stream())
.flatMap(Stream::distinct)
.forEach(FileImporter::importTarget);

if (!PdxuInstallation.shouldStart()) {
System.exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public static Achievement fromFile(Path file, AchievementContent content, boolea
return a;
}

public <T,I extends SavegameInfo<T>, S extends Savegame> Optional<AchievementMatcher> match(GameCampaignEntry<T,I> entry) {
Optional<S> loaded = (Optional<S>) GameIntegration.<T,I>current().getSavegameCache().loadDataForEntry(entry);
public <T, I extends SavegameInfo<T>, S extends Savegame> Optional<AchievementMatcher> match(GameCampaignEntry<T, I> entry) {
Optional<S> loaded = (Optional<S>) GameIntegration.<T, I>current().getSavegameCache().loadDataForEntry(entry);
if (loaded.isEmpty()) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private String calculateChecksum() throws IOException {
return c.toString();
}

public <S extends Savegame> Optional<AchievementMatcher> validateSavegame(Achievement a, GameCampaignEntry<?,?> entry) {
public <S extends Savegame> Optional<AchievementMatcher> validateSavegame(Achievement a, GameCampaignEntry<?, ?> entry) {
try {
if (!validateChecksum()) {
throw new IOException("Wrong achievement checksum");
Expand All @@ -137,7 +137,7 @@ public boolean validateChecksum() throws IOException {
return checksum.equals(calculateChecksum());
}

public List<Achievement> getSuitableAchievements(GameCampaignEntry<?,?> entry, boolean onlyOfficial, boolean onlyElgible) {
public List<Achievement> getSuitableAchievements(GameCampaignEntry<?, ?> entry, boolean onlyOfficial, boolean onlyElgible) {
return achievements.stream()
.filter(a -> !onlyOfficial || a.isOfficial())
.filter(a -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.crschnick.pdx_unlimiter.app.game;

import com.crschnick.pdx_unlimiter.app.installation.ErrorHandler;
import com.crschnick.pdx_unlimiter.app.installation.Settings;
import com.crschnick.pdx_unlimiter.app.util.JsonHelper;
import com.crschnick.pdx_unlimiter.core.data.GameVersion;
Expand All @@ -9,14 +8,14 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.*;
import java.util.Date;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.crschnick.pdx_unlimiter.app.achievement.AchievementManager;
import com.crschnick.pdx_unlimiter.app.gui.Ck3GuiFactory;
import com.crschnick.pdx_unlimiter.app.gui.GameGuiFactory;
import com.crschnick.pdx_unlimiter.app.savegame.SavegameCache;
import com.crschnick.pdx_unlimiter.core.data.Ck3Tag;
import com.crschnick.pdx_unlimiter.core.savegame.Ck3SavegameInfo;
Expand All @@ -29,7 +28,7 @@ public Ck3GuiFactory getGuiFactory() {
}

@Override
public SavegameCache<?,?,Ck3Tag, Ck3SavegameInfo> getSavegameCache() {
public SavegameCache<?, ?, Ck3Tag, Ck3SavegameInfo> getSavegameCache() {
return SavegameCache.CK3_CACHE;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.crschnick.pdx_unlimiter.app.game;

import com.crschnick.pdx_unlimiter.app.installation.ErrorHandler;
import com.crschnick.pdx_unlimiter.app.installation.Settings;
import com.crschnick.pdx_unlimiter.app.util.SteamHelper;
import org.apache.commons.lang3.SystemUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.Optional;
import java.util.regex.Matcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.crschnick.pdx_unlimiter.app.game;

import com.crschnick.pdx_unlimiter.app.installation.PdxuInstallation;
import com.crschnick.pdx_unlimiter.app.installation.Settings;
import org.jnativehook.GlobalScreen;
import org.jnativehook.keyboard.NativeKeyListener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class GameCampaign<T,I extends SavegameInfo<T>> {
public final class GameCampaign<T, I extends SavegameInfo<T>> {


private volatile ObjectProperty<Instant> lastPlayed;
private volatile StringProperty name;
private UUID campaignId;
private volatile ObservableSet<GameCampaignEntry<T,I>> savegames =
private volatile ObservableSet<GameCampaignEntry<T, I>> savegames =
FXCollections.synchronizedObservableSet(FXCollections.observableSet(new HashSet<>()));
private volatile ObjectProperty<GameDate> date;
private ObjectProperty<T> tag;
Expand All @@ -41,7 +41,7 @@ public ObjectProperty<T> tagProperty() {
return tag;
}

public void add(GameCampaignEntry<T,I> e) {
public void add(GameCampaignEntry<T, I> e) {
this.savegames.add(e);
}

Expand All @@ -57,20 +57,20 @@ public UUID getCampaignId() {
return campaignId;
}

public GameCampaignEntry<T,I> getLatestEntry() {
public GameCampaignEntry<T, I> getLatestEntry() {
return entryStream().findFirst().get();
}

public ObservableSet<GameCampaignEntry<T,I>> getEntries() {
public ObservableSet<GameCampaignEntry<T, I>> getEntries() {
return savegames;
}

public int indexOf(GameCampaignEntry<T,I> e) {
public int indexOf(GameCampaignEntry<T, I> e) {
return entryStream().collect(Collectors.toList()).indexOf(e);
}

public Stream<GameCampaignEntry<T,I>> entryStream() {
var list = new ArrayList<GameCampaignEntry<T,I>>(getEntries());
public Stream<GameCampaignEntry<T, I>> entryStream() {
var list = new ArrayList<GameCampaignEntry<T, I>>(getEntries());
list.sort(Comparator.comparing(GameCampaignEntry::getDate));
Collections.reverse(list);
return list.stream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.UUID;

public final class GameCampaignEntry<T,I extends SavegameInfo> implements Comparable<GameCampaignEntry<T,I>> {
public final class GameCampaignEntry<T, I extends SavegameInfo> implements Comparable<GameCampaignEntry<T, I>> {

private StringProperty name;
private UUID uuid;
Expand All @@ -31,7 +31,7 @@ public GameCampaignEntry(String name, UUID uuid, I info,
}

@Override
public int compareTo(GameCampaignEntry<T,I> o) {
public int compareTo(GameCampaignEntry<T, I> o) {
return o.getDate().compareTo(getDate());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -31,13 +36,12 @@ public abstract class GameInstallation {

protected ObjectProperty<List<FileImportTarget>> savegames = new SimpleObjectProperty<>();
protected DistributionType distType;
private Path path;
private Path executable;
protected Path userDir;

private List<GameDlc> dlcs = new ArrayList<>();
protected List<GameMod> mods = new ArrayList<>();
protected GameVersion version;
private Path path;
private Path executable;
private List<GameDlc> dlcs = new ArrayList<>();

public GameInstallation(Path path, Path executable) {
this.path = path;
Expand Down Expand Up @@ -132,7 +136,7 @@ public void startDirect() {
}

public <T, I extends SavegameInfo<T>> Path getExportTarget(
SavegameCache<?,?,T,I> cache, GameCampaignEntry<T, I> e) {
SavegameCache<?, ?, T, I> cache, GameCampaignEntry<T, I> e) {
Path file = getSavegamesPath().resolve(cache.getFileName(e));
return file;
}
Expand Down Expand Up @@ -172,7 +176,7 @@ private void loadMods() throws IOException {
GameMod.fromFile(f).ifPresent(m -> {
if (Files.exists(m.getPath())) mods.add(m);
LoggerFactory.getLogger(getClass()).debug("Found mod " + m.getName() +
" at " + m.getModFile().toString()+ ". Content exists: " + Files.exists(m.getPath()));
" at " + m.getModFile().toString() + ". Content exists: " + Files.exists(m.getPath()));
});
} catch (Exception e) {
ErrorHandler.handleException(e);
Expand Down
Loading

0 comments on commit 64bd523

Please sign in to comment.