Added optional mod minimum game version
This commit is contained in:
@@ -206,6 +206,7 @@ public class Mods implements Loadable{
|
||||
}
|
||||
|
||||
resolveDependencies();
|
||||
|
||||
//sort mods to make sure servers handle them properly.
|
||||
loaded.sort(Structs.comparing(m -> m.name));
|
||||
|
||||
@@ -213,6 +214,10 @@ public class Mods implements Loadable{
|
||||
}
|
||||
|
||||
private void resolveDependencies(){
|
||||
Array<LoadedMod> incompatible = loaded.select(m -> !m.isSupported());
|
||||
loaded.removeAll(incompatible);
|
||||
disabled.addAll(incompatible);
|
||||
|
||||
for(LoadedMod mod : Array.<LoadedMod>withArrays(loaded, disabled)){
|
||||
updateDependencies(mod);
|
||||
}
|
||||
@@ -572,6 +577,18 @@ public class Mods implements Loadable{
|
||||
return !missingDependencies.isEmpty();
|
||||
}
|
||||
|
||||
/** @return whether this mod is supported by the game verison */
|
||||
public boolean isSupported(){
|
||||
if(Version.build <= 0 || meta.minGameVersion == null) return true;
|
||||
if(meta.minGameVersion.contains(".")){
|
||||
String[] split = meta.minGameVersion.split("\\.");
|
||||
if(split.length == 2){
|
||||
return Version.build >= Strings.parseInt(split[0], 0) && Version.revision >= Strings.parseInt(split[1], 0);
|
||||
}
|
||||
}
|
||||
return Version.build >= Strings.parseInt(meta.minGameVersion, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSteamID(){
|
||||
return Core.settings.getString(name + "-steamid", null);
|
||||
@@ -641,7 +658,7 @@ public class Mods implements Loadable{
|
||||
|
||||
/** Plugin metadata information.*/
|
||||
public static class ModMeta{
|
||||
public String name, author, description, version, main;
|
||||
public String name, author, description, version, main, minGameVersion;
|
||||
public Array<String> dependencies = Array.with();
|
||||
/** Hidden mods are only server-side or client-side, and do not support adding new content. */
|
||||
public boolean hidden;
|
||||
|
||||
@@ -132,7 +132,7 @@ public class ModsDialog extends FloatingDialog{
|
||||
title.addImageTextButton(mod.enabled() ? "$mod.disable" : "$mod.enable", mod.enabled() ? Icon.arrowDownSmall : Icon.arrowUpSmall, Styles.cleart, () -> {
|
||||
mods.setEnabled(mod, !mod.enabled());
|
||||
setup();
|
||||
}).height(50f).margin(8f).width(130f);
|
||||
}).height(50f).margin(8f).width(130f).disabled(!mod.isSupported());
|
||||
|
||||
if(steam && !mod.hasSteamID()){
|
||||
title.addImageButton(Icon.loadMapSmall, Styles.cleari, () -> {
|
||||
@@ -161,7 +161,10 @@ public class ModsDialog extends FloatingDialog{
|
||||
t.labelWrap("[lightgray]" + mod.meta.description).growX();
|
||||
t.row();
|
||||
}
|
||||
if(mod.hasUnmetDependencies()){
|
||||
if(!mod.isSupported()){
|
||||
t.labelWrap(Core.bundle.format("mod.requiresversion", mod.meta.minGameVersion)).growX();
|
||||
t.row();
|
||||
}else if(mod.hasUnmetDependencies()){
|
||||
t.labelWrap(Core.bundle.format("mod.missingdependencies", mod.missingDependencies.toString(", "))).growX();
|
||||
t.row();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user