Merge pull request 'add manifest versioning' (#9) from owlsys/add-manifest-version into main
Reviewed-on: https://git-esnesnon.ecorous.org/esnesnon/nonsense-loader/pulls/9 Reviewed-by: Ecorous <ecorous@outlook.com>
This commit is contained in:
commit
44378d47cc
|
@ -1,4 +1,7 @@
|
|||
[frog]
|
||||
format_version = "1.0.0"
|
||||
|
||||
[frog.mod]
|
||||
id = "example_mod"
|
||||
name = "Example Mod"
|
||||
version = "1.0.0"
|
||||
|
|
|
@ -7,13 +7,14 @@ import java.nio.file.FileSystem;
|
|||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import com.electronwill.nightconfig.core.file.FileNotFoundAction;
|
||||
import com.electronwill.nightconfig.toml.TomlParser;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.ecorous.esnesnon.nonsense.loader.api.mod.*;
|
||||
import org.ecorous.esnesnon.nonsense.loader.impl.SemVerParseException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -43,12 +44,24 @@ public class ModPropertiesReader {
|
|||
}
|
||||
|
||||
private static ModProperties readProperties(UnmodifiableConfig config) {
|
||||
String id = config.get("frog.id");
|
||||
String name = config.get("frog.name");
|
||||
String version = config.get("frog.version");
|
||||
String license = config.get("frog.license");
|
||||
String manifestVer = config.get("frog.format_version");
|
||||
|
||||
List<UnmodifiableConfig> creditsList = config.get("frog.credits");
|
||||
try {
|
||||
return FormatVersion.get(manifestVer).parse(config);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private enum FormatVersion {
|
||||
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<>();
|
||||
if (creditsList != null) {
|
||||
creditsList.forEach(c -> credits.put(c.get("name"), c.get("roles")));
|
||||
|
@ -63,10 +76,22 @@ public class ModPropertiesReader {
|
|||
if (extensionsConfig != null) {
|
||||
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));
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public interface NonsensePlugin extends Runnable {
|
|||
return false;
|
||||
}
|
||||
|
||||
default void init(LoaderImpl loader) {
|
||||
default void init(LoaderImpl loader) throws Exception {
|
||||
}
|
||||
|
||||
Collection<ModProperties> getMods();
|
||||
|
|
|
@ -44,7 +44,7 @@ public class Minecraft implements NonsensePlugin {
|
|||
}
|
||||
|
||||
@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");
|
||||
|
||||
if (!Files.exists(remappedGamePath)){
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
[frog]
|
||||
format_version = "1.0.0"
|
||||
|
||||
[frog.mod]
|
||||
id = "frogloader"
|
||||
name = "Nonsense Loader"
|
||||
version = "${version}"
|
||||
|
|
Loading…
Reference in a new issue