add manifest versioning

This commit is contained in:
moehreag 2024-05-26 01:30:04 +02:00
parent 8487df905b
commit 1b4b1d0d93
5 changed files with 55 additions and 24 deletions

View file

@ -1,4 +1,7 @@
[frog] [frog]
manifest_version = "1.0.0"
[frog.mod]
id = "example_mod" id = "example_mod"
name = "Example Mod" name = "Example Mod"
version = "1.0.0" version = "1.0.0"

View file

@ -7,13 +7,14 @@ import java.nio.file.FileSystem;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import com.electronwill.nightconfig.core.CommentedConfig; import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.UnmodifiableConfig; import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.file.FileNotFoundAction; import com.electronwill.nightconfig.core.file.FileNotFoundAction;
import com.electronwill.nightconfig.toml.TomlParser; import com.electronwill.nightconfig.toml.TomlParser;
import lombok.AllArgsConstructor;
import org.ecorous.esnesnon.nonsense.loader.api.mod.*; import org.ecorous.esnesnon.nonsense.loader.api.mod.*;
import org.ecorous.esnesnon.nonsense.loader.impl.SemVerParseException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -43,12 +44,24 @@ public class ModPropertiesReader {
} }
private static ModProperties readProperties(UnmodifiableConfig config) { private static ModProperties readProperties(UnmodifiableConfig config) {
String id = config.get("frog.id"); String manifestVer = config.get("frog.manifest_version");
String name = config.get("frog.name");
String version = config.get("frog.version");
String license = config.get("frog.license");
List<UnmodifiableConfig> creditsList = config.get("frog.credits"); try {
return ManifestVersion.get(manifestVer).parse(config);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
@AllArgsConstructor
private enum ManifestVersion {
V1_0_0("1.0.0", config -> {
String id = config.get("frog.mod.id");
String name = config.get("frog.mod.name");
String version = config.get("frog.mod.version");
String license = config.get("frog.mod.license");
List<UnmodifiableConfig> creditsList = config.get("frog.mod.credits");
Map<String, Collection<String>> credits = new HashMap<>(); Map<String, Collection<String>> credits = new HashMap<>();
if (creditsList != null) { if (creditsList != null) {
creditsList.forEach(c -> credits.put(c.get("name"), c.get("roles"))); creditsList.forEach(c -> credits.put(c.get("name"), c.get("roles")));
@ -63,10 +76,22 @@ public class ModPropertiesReader {
if (extensionsConfig != null) { if (extensionsConfig != null) {
extensionsConfig.entrySet().forEach(entry -> extensions.put(entry.getKey(), entry.getValue())); extensionsConfig.entrySet().forEach(entry -> extensions.put(entry.getKey(), entry.getValue()));
} }
try {
return new ModPropertiesImpl(id, name, SemVerImpl.parse(version), License.fromId(license), ModCredits.of(credits), new ModDependencies(depends, breaks, suggests), ModExtensions.of(extensions)); return new ModPropertiesImpl(id, name, SemVerImpl.parse(version), License.fromId(license), ModCredits.of(credits), new ModDependencies(depends, breaks, suggests), ModExtensions.of(extensions));
} catch (SemVerParseException e) { });
throw new UncheckedIOException(e);
private final String version;
private final Parser parser;
private static final Map<String, Parser> versions = Arrays.stream(values()).collect(Collectors.toMap(v -> v.version, v -> v.parser));
public static Parser get(String version){
return versions.get(version);
}
@FunctionalInterface
public interface Parser {
ModProperties parse(UnmodifiableConfig config) throws IOException;
} }
} }
} }

View file

@ -18,7 +18,7 @@ public interface NonsensePlugin extends Runnable {
return false; return false;
} }
default void init(LoaderImpl loader) { default void init(LoaderImpl loader) throws Exception {
} }
Collection<ModProperties> getMods(); Collection<ModProperties> getMods();

View file

@ -44,7 +44,7 @@ public class Minecraft implements NonsensePlugin {
} }
@Override @Override
public void init(LoaderImpl loader) { public void init(LoaderImpl loader) throws Exception {
Path remappedGamePath = loader.getGameDir().resolve(".nonsense/remappedJars").resolve(version).resolve("game-" + version + "-remapped.jar"); Path remappedGamePath = loader.getGameDir().resolve(".nonsense/remappedJars").resolve(version).resolve("game-" + version + "-remapped.jar");
if (!Files.exists(remappedGamePath)){ if (!Files.exists(remappedGamePath)){

View file

@ -1,4 +1,7 @@
[frog] [frog]
manifest_version = "1.0.0"
[frog.mod]
id = "frogloader" id = "frogloader"
name = "Nonsense Loader" name = "Nonsense Loader"
version = "${version}" version = "${version}"