Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import com.github.rcd47.x2data.lib.unreal.mappings.UnrealName;
import com.github.rcd47.x2data.lib.unreal.mappings.base.XComGameStateHistory;

public class HistoryFile {
Expand All @@ -10,13 +11,17 @@ public class HistoryFile {
private final List<HistoryFrame> frames;
private final List<HistorySingletonObject> singletons;
private final List<HistoryFileProblem> problems;
private final List<UnrealName> contextTypes;
private final List<UnrealName> objectTypes;

public HistoryFile(XComGameStateHistory history, List<HistoryFrame> frames, List<HistorySingletonObject> singletons,
List<HistoryFileProblem> problems) {
List<HistoryFileProblem> problems, List<UnrealName> contextTypes, List<UnrealName> objectTypes) {
this.history = history;
this.frames = frames;
this.singletons = singletons;
this.problems = problems;
this.contextTypes = contextTypes;
this.objectTypes = objectTypes;
}

public XComGameStateHistory getHistory() {
Expand All @@ -34,5 +39,13 @@ public List<HistorySingletonObject> getSingletons() {
public List<HistoryFileProblem> getProblems() {
return problems;
}

public List<UnrealName> getContextTypes() {
return contextTypes;
}

public List<UnrealName> getObjectTypes() {
return objectTypes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.DoubleConsumer;

Expand Down Expand Up @@ -81,6 +82,8 @@ public HistoryFile read(FileChannel in, DoubleConsumer progressPercentCallback,
Map<Integer, GameStateObject> stateObjects = new HashMap<>();
Map<X2HistoryIndexEntry, Integer> singletonStates = new HashMap<>();
List<HistoryFileProblem> problemsDetected = new ArrayList<>();
Set<UnrealName> contextTypes = new HashSet<>();
Set<UnrealName> objectTypes = new HashSet<>();
var contextSummarizer = ScriptPreferences.CONTEXT_SUMMARY.getExecutable();
var objectSummarizer = ScriptPreferences.STATE_OBJECT_SUMMARY.getExecutable();
for (int i = 0; i < numFrames; i++) {
Expand All @@ -89,6 +92,7 @@ public HistoryFile read(FileChannel in, DoubleConsumer progressPercentCallback,
progressTextCallback.accept("Parsing objects for history frame " + rawFrame.HistoryIndex);

var contextEntry = historyIndex.getEntry(rawFrame.StateChangeContext.index());
contextTypes.add(contextEntry.getType());
var contextVisitor = new GenericObjectVisitor(null);
historyIndex.parseObject(contextEntry, contextVisitor);
var parsedContext = new GameStateContext(
Expand All @@ -101,6 +105,7 @@ public HistoryFile read(FileChannel in, DoubleConsumer progressPercentCallback,
continue;
}

objectTypes.add(stateObjectEntry.getType());
var previousVersionIndex = stateObjectEntry.getPreviousVersionIndex();
var previousVersion = previousVersionIndex == -1 ? null : parsedObjects.get(previousVersionIndex);
var stateObjectVisitor = new GenericObjectVisitor(previousVersion);
Expand Down Expand Up @@ -151,7 +156,13 @@ public HistoryFile read(FileChannel in, DoubleConsumer progressPercentCallback,
.thenComparingInt(s -> s.getFirstFrame()))
.toList();

return new HistoryFile(history, List.copyOf(frames.values()), singletons, problemsDetected);
return new HistoryFile(
history,
List.copyOf(frames.values()),
singletons,
problemsDetected,
contextTypes.stream().sorted().toList(),
objectTypes.stream().sorted().toList());
}
} finally {
Files.deleteIfExists(decompressedFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public HistoryFramesTable(HistoryFile history) {

var toolbar = new ToolBar(colSelector);

var contextTypes = history.getFrames().stream().map(f -> f.getContext().getType()).distinct().sorted().toList();
var contextTypes = history.getContextTypes();

var contextTypeSelector = new MultiSelectMenu<>("context types", contextTypes, n -> n.getOriginal(), s -> {
filters.setFilter(0, s.size() == contextTypes.size() ? null : f -> s.contains(f.getContext().getType()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,7 @@ public HistoryObjectsTable(HistoryFile history, TableView<HistoryFrame> framesTa

var prefs = GeneralPreferences.getEffective();

var types = history
.getFrames()
.stream()
.flatMap(f -> f.getObjects().values().stream())
.map(o -> o.getType())
.distinct()
.sorted()
.toList();
var types = history.getObjectTypes();

var colSelector = new MultiSelectMenu<>(
"columns",
Expand Down