mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
Полноценный граф зависимостей опциональных модов на Java
This commit is contained in:
parent
005507a3a3
commit
4792e0453e
3 changed files with 94 additions and 78 deletions
|
@ -290,6 +290,7 @@ function updateProfilesList(profiles) {
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
serverList.getChildren().add(serverBtn);
|
serverList.getChildren().add(serverBtn);
|
||||||
|
if(profile.getOptional() != null) profile.updateOptionalGraph();
|
||||||
index++;
|
index++;
|
||||||
});
|
});
|
||||||
LogHelper.debug("Load selected %d profile",settings.profile);
|
LogHelper.debug("Load selected %d profile",settings.profile);
|
||||||
|
|
|
@ -122,13 +122,11 @@ var options = {
|
||||||
{
|
{
|
||||||
profile.markOptional(modFile.file);
|
profile.markOptional(modFile.file);
|
||||||
LogHelper.debug("Selected mod %s", modFile.file);
|
LogHelper.debug("Selected mod %s", modFile.file);
|
||||||
options.treeToggle(true, modFile.file);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
profile.unmarkOptional(modFile.file);
|
profile.unmarkOptional(modFile.file);
|
||||||
LogHelper.debug("Unselected mod %s", modFile.file);
|
LogHelper.debug("Unselected mod %s", modFile.file);
|
||||||
options.treeToggle(false, modFile.file);
|
|
||||||
}
|
}
|
||||||
options.update();
|
options.update();
|
||||||
});
|
});
|
||||||
|
@ -155,73 +153,6 @@ var options = {
|
||||||
});
|
});
|
||||||
holder.getChildren().clear();
|
holder.getChildren().clear();
|
||||||
holder.getChildren().addAll(checkBoxList);
|
holder.getChildren().addAll(checkBoxList);
|
||||||
},
|
|
||||||
treeToggle: function(enable, ImodFile) {
|
|
||||||
var profile = profilesList[serverHolder.old];
|
|
||||||
var modInfo = profile.getOptionalFile(ImodFile);
|
|
||||||
var modList = profile.getOptional();
|
|
||||||
|
|
||||||
if(modInfo.subTreeLevel != null) {
|
|
||||||
|
|
||||||
if(modInfo.subTreeLevel >= 1){//Отключение core-модификации
|
|
||||||
var stop = false;
|
|
||||||
modList.forEach(function(elem, id) {
|
|
||||||
if(elem != null && elem.subTreeLevel != null) {
|
|
||||||
if( elem.subTreeLevel > modInfo.subTreeLevel && enable == false && stop == false) {
|
|
||||||
if(options.modExists(elem.file)){
|
|
||||||
profile.unmarkOptional(elem.file);
|
|
||||||
LogHelper.debug("Unselected subMod %s", elem.file);
|
|
||||||
}
|
|
||||||
} else if(elem.subTreeLevel <= modInfo.subTreeLevel && stop == false) {
|
|
||||||
//LogHelper.debug("STOP disable!! " + key);
|
|
||||||
stop = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(modInfo.onlyOne == true){//Включение onlyOne-модификации (Все onlyOne-модификации с той же группой будут отключены. К примеру 2 миникарты)
|
|
||||||
modList.forEach(function(elem, id) {
|
|
||||||
if(elem != null && elem.onlyOneGroup != null) {
|
|
||||||
if(elem.onlyOneGroup == modInfo.onlyOneGroup && elem.onlyOne == true && enable == true && key != ImodFile) {
|
|
||||||
if(options.modExists(elem.file)) {
|
|
||||||
profile.unmarkOptional(elem.file);
|
|
||||||
LogHelper.debug("Unselected Mod (onlyOne toggle) %s", elem.file);
|
|
||||||
}
|
|
||||||
options.treeToggle(false, elem.file); //И все его подмодификации канут в Лету..
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(modInfo.subTreeLevel > 1){//Включение суб-модификации (Без core суб-моды работать не будут, так что его нужно включать) (Включаем всю ветку зависимости)
|
|
||||||
var tsl = modInfo.subTreeLevel-1;
|
|
||||||
modList.forEach(function(elem, id) {
|
|
||||||
if(elem != null && elem.subTreeLevel != null) {
|
|
||||||
if(elem.subTreeLevel == tsl && enable == true) {
|
|
||||||
if(options.modExists(elem)) {
|
|
||||||
profile.markOptional(elem.file);
|
|
||||||
LogHelper.debug("Selected coreMod %s", key);
|
|
||||||
}
|
|
||||||
options.treeToggle(true, key); //Для срабатывания onlyOne-модификаций.
|
|
||||||
tsl--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modExists: function(key){
|
|
||||||
var profile = profilesList[serverHolder.old];
|
|
||||||
var list = profile.getOptional();
|
|
||||||
var result = false;
|
|
||||||
list.forEach(function(modFile) {
|
|
||||||
if(modFile.file === key) {
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -104,11 +104,17 @@ public static class OptionalFile {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public String info;
|
public String info;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public int sunTreeLevel = 1;
|
public String[] dependenciesFile;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public boolean onlyOne = false;
|
public String[] conflictFile;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public int onlyOneGroup = 1;
|
public transient OptionalFile[] dependencies;
|
||||||
|
@LauncherAPI
|
||||||
|
public transient OptionalFile[] conflict;
|
||||||
|
@LauncherAPI
|
||||||
|
public int subTreeLevel = 1;
|
||||||
|
@LauncherAPI
|
||||||
|
public transient Set<OptionalFile> dependenciesCount;
|
||||||
|
|
||||||
public OptionalFile(String file, boolean mark) {
|
public OptionalFile(String file, boolean mark) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
@ -234,6 +240,31 @@ public String getServerAddress() {
|
||||||
public Set<OptionalFile> getOptional() {
|
public Set<OptionalFile> getOptional() {
|
||||||
return updateOptional;
|
return updateOptional;
|
||||||
}
|
}
|
||||||
|
@LauncherAPI
|
||||||
|
public void updateOptionalGraph()
|
||||||
|
{
|
||||||
|
for(OptionalFile file : updateOptional)
|
||||||
|
{
|
||||||
|
if(file.dependenciesFile != null)
|
||||||
|
{
|
||||||
|
file.dependencies = new OptionalFile[file.dependenciesFile.length];
|
||||||
|
for(int i=0;i<file.dependenciesFile.length;++i)
|
||||||
|
{
|
||||||
|
file.dependencies[i] = getOptionalFile(file.dependenciesFile[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(file.conflictFile != null)
|
||||||
|
{
|
||||||
|
file.conflict = new OptionalFile[file.conflictFile.length];
|
||||||
|
for(int i=0;i<file.conflictFile.length;++i)
|
||||||
|
{
|
||||||
|
file.conflict[i] = getOptionalFile(file.conflictFile[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public OptionalFile getOptionalFile(String file)
|
public OptionalFile getOptionalFile(String file)
|
||||||
{
|
{
|
||||||
|
@ -251,18 +282,71 @@ public Collection<String> getShared() {
|
||||||
public void markOptional(String opt) {
|
public void markOptional(String opt) {
|
||||||
if (!updateOptional.contains(new OptionalFile(opt)))
|
if (!updateOptional.contains(new OptionalFile(opt)))
|
||||||
throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt));
|
throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt));
|
||||||
updateOptional.forEach(e -> {
|
OptionalFile file = getOptionalFile(opt);
|
||||||
if (e.file.equals(opt)) e.mark = true;
|
markOptional(file);
|
||||||
});
|
}
|
||||||
|
@LauncherAPI
|
||||||
|
public void markOptional(OptionalFile file)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(file.mark) return;
|
||||||
|
file.mark = true;
|
||||||
|
if(file.dependencies != null)
|
||||||
|
{
|
||||||
|
for(OptionalFile dep : file.dependencies)
|
||||||
|
{
|
||||||
|
if(dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>();
|
||||||
|
dep.dependenciesCount.add(file);
|
||||||
|
markOptional(dep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(file.conflict != null)
|
||||||
|
{
|
||||||
|
for(OptionalFile conflict : file.conflict)
|
||||||
|
{
|
||||||
|
unmarkOptional(conflict);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public void unmarkOptional(String opt) {
|
public void unmarkOptional(String opt) {
|
||||||
if (!updateOptional.contains(new OptionalFile(opt)))
|
if (!updateOptional.contains(new OptionalFile(opt)))
|
||||||
throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt));
|
throw new SecurityException(String.format("Optional mod %s not found in optionalList", opt));
|
||||||
updateOptional.forEach(e -> {
|
OptionalFile file = getOptionalFile(opt);
|
||||||
if (e.file.equals(opt)) e.mark = false;
|
unmarkOptional(file);
|
||||||
});
|
}
|
||||||
|
@LauncherAPI
|
||||||
|
public void unmarkOptional(OptionalFile file)
|
||||||
|
{
|
||||||
|
if(!file.mark) return;
|
||||||
|
file.mark = false;
|
||||||
|
if(file.dependenciesCount != null)
|
||||||
|
{
|
||||||
|
for(OptionalFile f : file.dependenciesCount)
|
||||||
|
{
|
||||||
|
unmarkOptional(f);
|
||||||
|
}
|
||||||
|
file.dependenciesCount.clear();
|
||||||
|
file.dependenciesCount = null;
|
||||||
|
}
|
||||||
|
if(file.dependencies != null)
|
||||||
|
{
|
||||||
|
for(OptionalFile f : file.dependencies)
|
||||||
|
{
|
||||||
|
if(!f.mark) continue;
|
||||||
|
if(f.dependenciesCount == null)
|
||||||
|
{
|
||||||
|
unmarkOptional(f);
|
||||||
|
}
|
||||||
|
else if(f.dependenciesCount.size() <= 1)
|
||||||
|
{
|
||||||
|
f.dependenciesCount.clear();
|
||||||
|
f.dependenciesCount = null;
|
||||||
|
unmarkOptional(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushOptional(HashedDir dir, boolean digest) throws IOException {
|
public void pushOptional(HashedDir dir, boolean digest) throws IOException {
|
||||||
|
|
Loading…
Reference in a new issue