[FEATURE] Mutually exclusive optional mods (XOR logic)

This commit is contained in:
Sevastjan 2023-07-12 01:00:52 +03:00
parent 0c23b59749
commit ca87e0c726
No known key found for this signature in database
GPG key ID: A18133AD7A67B8AB
3 changed files with 25 additions and 0 deletions

View file

@ -254,6 +254,12 @@ public void updateOptionalGraph() {
file.conflict[i] = getOptionalFile(file.conflictFile[i].name);
}
}
if(file.xorConflictFile != null) {
file.xorConflict = new OptionalFile[file.xorConflictFile.length];
for(int i = 0; i < file.xorConflictFile.length; ++i) {
file.xorConflict[i] = getOptionalFile(file.xorConflictFile[i].name);
}
}
}
}
@ -369,6 +375,10 @@ public void verify() {
if (s == null)
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name));
}
if(f.xorConflictFile != null) for (OptionalDepend s : f.xorConflictFile) {
if (s == null)
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.xorConflictFile", f.name));
}
if (f.triggersList != null) {
for (OptionalTrigger trigger : f.triggersList) {
if (trigger == null)

View file

@ -24,10 +24,14 @@ public class OptionalFile {
@LauncherNetworkAPI
public OptionalDepend[] conflictFile;
@LauncherNetworkAPI
public OptionalDepend[] xorConflictFile;
@LauncherNetworkAPI
public transient OptionalFile[] dependencies;
@LauncherNetworkAPI
public transient OptionalFile[] conflict;
@LauncherNetworkAPI
public transient OptionalFile[] xorConflict;
@LauncherNetworkAPI
public int subTreeLevel = 1;
@LauncherNetworkAPI
public boolean isPreset;

View file

@ -7,6 +7,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Arrays;
import java.util.function.BiConsumer;
public class OptionalView {
@ -111,6 +112,11 @@ public void enable(OptionalFile file, boolean manual, BiConsumer<OptionalFile, B
disable(conflict, callback);
}
}
if(file.xorConflict != null) {
for(OptionalFile xorConflict : file.xorConflict) {
disable(xorConflict, callback);
}
}
}
public void disable(OptionalFile file, BiConsumer<OptionalFile, Boolean> callback) {
@ -129,6 +135,11 @@ public void disable(OptionalFile file, BiConsumer<OptionalFile, Boolean> callbac
}
}
}
if (file.xorConflict != null) {
if (Arrays.stream(file.xorConflict).noneMatch(this::isEnabled)) {
enable(file.xorConflict[0], false, callback);
}
}
}
private boolean contains(OptionalFile file, OptionalFile[] array) {