mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Фикс зависимостей и возможность взаимоисключения для опциональных модов (#663)
* [FEATURE] Mutually exclusive optional mods (XOR logic) * [FIX] Bug with missing forgotten dependency/conflict * [FIX] ArrayIndexOutOfBoundsException if xorConfict is empty * [STYLE] Rename "xorConflict" to "group"
This commit is contained in:
parent
680244e5d1
commit
d4ca612bff
3 changed files with 56 additions and 0 deletions
|
@ -254,6 +254,12 @@ public void updateOptionalGraph() {
|
||||||
file.conflict[i] = getOptionalFile(file.conflictFile[i].name);
|
file.conflict[i] = getOptionalFile(file.conflictFile[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(file.groupFile != null) {
|
||||||
|
file.group = new OptionalFile[file.groupFile.length];
|
||||||
|
for(int i = 0; i < file.groupFile.length; ++i) {
|
||||||
|
file.group[i] = getOptionalFile(file.groupFile[i].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,6 +375,11 @@ public void verify() {
|
||||||
if (s == null)
|
if (s == null)
|
||||||
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name));
|
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name));
|
||||||
}
|
}
|
||||||
|
if(f.groupFile != null)
|
||||||
|
for (OptionalDepend s : f.groupFile) {
|
||||||
|
if (s == null)
|
||||||
|
throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.groupFile", f.name));
|
||||||
|
}
|
||||||
if (f.triggersList != null) {
|
if (f.triggersList != null) {
|
||||||
for (OptionalTrigger trigger : f.triggersList) {
|
for (OptionalTrigger trigger : f.triggersList) {
|
||||||
if (trigger == null)
|
if (trigger == null)
|
||||||
|
|
|
@ -24,10 +24,14 @@ public class OptionalFile {
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
public OptionalDepend[] conflictFile;
|
public OptionalDepend[] conflictFile;
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
|
public OptionalDepend[] groupFile;
|
||||||
|
@LauncherNetworkAPI
|
||||||
public transient OptionalFile[] dependencies;
|
public transient OptionalFile[] dependencies;
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
public transient OptionalFile[] conflict;
|
public transient OptionalFile[] conflict;
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
|
public transient OptionalFile[] group;
|
||||||
|
@LauncherNetworkAPI
|
||||||
public int subTreeLevel = 1;
|
public int subTreeLevel = 1;
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
public boolean isPreset;
|
public boolean isPreset;
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class OptionalView {
|
public class OptionalView {
|
||||||
public Set<OptionalFile> enabled = new HashSet<>();
|
public Set<OptionalFile> enabled = new HashSet<>();
|
||||||
|
@ -25,6 +27,7 @@ public OptionalView(OptionalView view) {
|
||||||
this.enabled = new HashSet<>(view.enabled);
|
this.enabled = new HashSet<>(view.enabled);
|
||||||
this.installInfo = new HashMap<>(view.installInfo);
|
this.installInfo = new HashMap<>(view.installInfo);
|
||||||
this.all = view.all;
|
this.all = view.all;
|
||||||
|
fixDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OptionalView(ClientProfile profile, OptionalView old) {
|
public OptionalView(ClientProfile profile, OptionalView old) {
|
||||||
|
@ -40,6 +43,7 @@ public OptionalView(ClientProfile profile, OptionalView old) {
|
||||||
disable(newFile, (file, status) -> {});
|
disable(newFile, (file, status) -> {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fixDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -80,6 +84,33 @@ public Set<OptionalAction> getEnabledActions() {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Needed if dependency/conflict was added after mod declaring it and clients have their profiles with this mod enabled
|
||||||
|
public void fixDependencies() {
|
||||||
|
Set<OptionalFile> disabled = all.stream().filter(t -> !isEnabled(t)).collect(Collectors.toSet());
|
||||||
|
for (OptionalFile file : disabled) {
|
||||||
|
if (file.group != null && Arrays.stream(file.group).noneMatch(this::isEnabled)) {
|
||||||
|
enable(file.group[0], false, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (OptionalFile file : enabled) {
|
||||||
|
if (file.dependencies != null) {
|
||||||
|
for (OptionalFile dep : file.dependencies) {
|
||||||
|
enable(dep, false, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.conflict != null) {
|
||||||
|
for (OptionalFile conflict : file.conflict) {
|
||||||
|
disable(conflict, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.group != null) {
|
||||||
|
for (OptionalFile member : file.group) {
|
||||||
|
disable(member, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Set<OptionalAction> getDisabledActions() {
|
public Set<OptionalAction> getDisabledActions() {
|
||||||
Set<OptionalAction> results = new HashSet<>();
|
Set<OptionalAction> results = new HashSet<>();
|
||||||
for (OptionalFile e : all) {
|
for (OptionalFile e : all) {
|
||||||
|
@ -111,6 +142,11 @@ public void enable(OptionalFile file, boolean manual, BiConsumer<OptionalFile, B
|
||||||
disable(conflict, callback);
|
disable(conflict, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(file.group != null) {
|
||||||
|
for(OptionalFile member : file.group) {
|
||||||
|
disable(member, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable(OptionalFile file, BiConsumer<OptionalFile, Boolean> callback) {
|
public void disable(OptionalFile file, BiConsumer<OptionalFile, Boolean> callback) {
|
||||||
|
@ -129,6 +165,11 @@ public void disable(OptionalFile file, BiConsumer<OptionalFile, Boolean> callbac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (file.group != null && file.group.length != 0) {
|
||||||
|
if (Arrays.stream(file.group).noneMatch(this::isEnabled)) {
|
||||||
|
enable(file.group[0], false, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean contains(OptionalFile file, OptionalFile[] array) {
|
private boolean contains(OptionalFile file, OptionalFile[] array) {
|
||||||
|
|
Loading…
Reference in a new issue