Skip to content

Commit

Permalink
Various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Oct 26, 2022
1 parent 75d9cae commit 643c6b0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.crschnick.pdxu.model.vic3.Vic3Tag;
import javafx.scene.image.Image;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -96,7 +95,8 @@ public static Node getCoatOfArmsNode() {
return Optional.of(content);
}).flatMap(Optional::stream).toList());
cache.coatOfArmsNode = all;
} catch (IOException e) {
} catch (Throwable throwable) {
ErrorHandler.handleException(throwable);
cache.coatOfArmsNode = ArrayNode.array(List.of());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,13 @@ public void writeModAndDlcLoadFile(GameInstallation installation, List<GameMod>
}

public List<GameMod> loadMods(GameInstallation installation) throws IOException {
var directory = installation.getDist().getWorkshopDir().orElseThrow();
if (!Files.isDirectory(directory)) {
var directory = installation.getDist().getWorkshopDir();
if (directory.isEmpty() || !Files.isDirectory(directory.get())) {
return List.of();
}

var mods = new ArrayList<GameMod>();
try (var list = Files.list(directory)) {
try (var list = Files.list(directory.get())) {
list.forEach(f -> {
GameMod.fromVictoria3Directory(f).ifPresent(m -> {
mods.add(m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public SavegameStorage(
GameDateType dateType,
SavegameType type,
Class<I> infoClass) {
this.infoFactory = (node, melted) -> {
var created = (I) infoClass.getDeclaredConstructors()[1].newInstance(node);
this.infoFactory = (content, melted) -> {
var created = (I) infoClass.getDeclaredConstructor(SavegameContent.class).newInstance(content);
created.getData().setBinary(melted);
return created;
};
Expand Down
20 changes: 16 additions & 4 deletions pdxu-app/src/main/java/com/crschnick/pdxu/app/util/JsonHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ public static <T> T readObject(Class<T> clazz, Path in) throws IOException {

public static void writeObject(Object obj, Path out) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.setVisibility(mapper
.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
mapper.enable(SerializationFeature.INDENT_OUTPUT);

JsonFactory f = new JsonFactory();
Expand All @@ -39,8 +45,14 @@ public static void writeObject(Object obj, Path out) throws IOException {

public static JsonNode read(Path in) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.setVisibility(mapper
.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
return mapper.readTree(in.toFile());
}

Expand Down
1 change: 1 addition & 0 deletions pdxu-io/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

requires org.apache.commons.lang;
requires org.graalvm.sdk;
requires org.graalvm.truffle;
requires static lombok;
}
12 changes: 12 additions & 0 deletions pdxu-model/src/main/java/com/crschnick/pdxu/model/GameVersion.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package com.crschnick.pdxu.model;


import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
@JsonSubTypes(
{
@JsonSubTypes.Type(value = GameNamedVersion.class)
}
)
public class GameVersion implements Comparable<GameVersion> {

private int first;
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.11.2-SNAPSHOT
2.11.2-pre

0 comments on commit 643c6b0

Please sign in to comment.