mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
packDirectory -> rootPath
This commit is contained in:
parent
5c7441241c
commit
4ba71e9c27
@ -41,7 +41,7 @@ public class YamlAddon implements AddonInitializer {
|
|||||||
.register(addon, ConfigurationDiscoveryEvent.class)
|
.register(addon, ConfigurationDiscoveryEvent.class)
|
||||||
.then(event -> {
|
.then(event -> {
|
||||||
try {
|
try {
|
||||||
FileUtil.filesWithExtension(event.getPack().getPackDirectory(), ".yml")
|
FileUtil.filesWithExtension(event.getPack().getRootPath(), ".yml")
|
||||||
.forEach((key, value) -> {
|
.forEach((key, value) -> {
|
||||||
LOGGER.debug("Discovered config {}", key);
|
LOGGER.debug("Discovered config {}", key);
|
||||||
try {
|
try {
|
||||||
|
@ -29,7 +29,7 @@ record ImageCache(LoadingCache<String, Image> cache) implements Properties {
|
|||||||
if(!pack.getContext().has(ImageCache.class)) {
|
if(!pack.getContext().has(ImageCache.class)) {
|
||||||
var cacheBuilder = Caffeine.newBuilder();
|
var cacheBuilder = Caffeine.newBuilder();
|
||||||
if(config.unloadOnTimeout()) cacheBuilder.expireAfterAccess(config.getCacheTimeout(), TimeUnit.SECONDS);
|
if(config.unloadOnTimeout()) cacheBuilder.expireAfterAccess(config.getCacheTimeout(), TimeUnit.SECONDS);
|
||||||
images = new ImageCache(cacheBuilder.build(s -> loadImage(s, pack.getPackDirectory())));
|
images = new ImageCache(cacheBuilder.build(s -> loadImage(s, pack.getRootPath())));
|
||||||
pack.getContext().put(images);
|
pack.getContext().put(images);
|
||||||
} else images = pack.getContext().get(ImageCache.class);
|
} else images = pack.getContext().get(ImageCache.class);
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class SpongeSchematicAddon implements AddonInitializer {
|
|||||||
.then(event -> {
|
.then(event -> {
|
||||||
CheckedRegistry<Structure> structureRegistry = event.getPack().getOrCreateRegistry(Structure.class);
|
CheckedRegistry<Structure> structureRegistry = event.getPack().getOrCreateRegistry(Structure.class);
|
||||||
try {
|
try {
|
||||||
FileUtil.filesWithExtension(event.getPack().getPackDirectory(), ".schem")
|
FileUtil.filesWithExtension(event.getPack().getRootPath(), ".schem")
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.map(entry -> {
|
.map(entry -> {
|
||||||
|
@ -41,7 +41,7 @@ public class TerraScriptAddon implements AddonInitializer {
|
|||||||
CheckedRegistry<Structure> structureRegistry = event.getPack().getOrCreateRegistry(Structure.class);
|
CheckedRegistry<Structure> structureRegistry = event.getPack().getOrCreateRegistry(Structure.class);
|
||||||
CheckedRegistry<LootTable> lootRegistry = event.getPack().getOrCreateRegistry(LootTable.class);
|
CheckedRegistry<LootTable> lootRegistry = event.getPack().getOrCreateRegistry(LootTable.class);
|
||||||
try {
|
try {
|
||||||
FileUtil.filesWithExtension(event.getPack().getPackDirectory(), ".tesf")
|
FileUtil.filesWithExtension(event.getPack().getRootPath(), ".tesf")
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.parallel()
|
.parallel()
|
||||||
|
@ -44,7 +44,7 @@ public interface ConfigPack extends LoaderRegistrar,
|
|||||||
|
|
||||||
List<GenerationStage> getStages();
|
List<GenerationStage> getStages();
|
||||||
|
|
||||||
Path getPackDirectory();
|
Path getRootPath();
|
||||||
|
|
||||||
String getAuthor();
|
String getAuthor();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class BufferedImageLoader implements TypeLoader<BufferedImage> {
|
|||||||
throws LoadException {
|
throws LoadException {
|
||||||
return pack.getContext().get(ImageCache.class).map.computeIfAbsent((String) c, s -> {
|
return pack.getContext().get(ImageCache.class).map.computeIfAbsent((String) c, s -> {
|
||||||
try {
|
try {
|
||||||
return ImageIO.read(Files.newInputStream(pack.getPackDirectory().resolve(s)));
|
return ImageIO.read(Files.newInputStream(pack.getRootPath().resolve(s)));
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new LoadException("Unable to load image", e, depthTracker);
|
throw new LoadException("Unable to load image", e, depthTracker);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
private final AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
|
private final AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
|
||||||
private final ConfigLoader selfLoader = new ConfigLoader();
|
private final ConfigLoader selfLoader = new ConfigLoader();
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
private final Path packDirectory;
|
private final Path rootPath;
|
||||||
|
|
||||||
private final Map<BaseAddon, VersionRange> addons;
|
private final Map<BaseAddon, VersionRange> addons;
|
||||||
|
|
||||||
@ -108,19 +108,22 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
public ConfigPackImpl(Path path, Platform platform) throws IOException {
|
public ConfigPackImpl(Path path, Platform platform) throws IOException {
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
|
|
||||||
if(Files.notExists(path)) throw new FileNotFoundException("Could not create config pack, " + path + " does not exist");
|
if(Files.notExists(path)) throw new FileNotFoundException("Could not load config pack, " + path + " does not exist");
|
||||||
|
|
||||||
if(Files.isDirectory(path)) {
|
if(Files.isDirectory(path)) {
|
||||||
this.packDirectory = path;
|
this.rootPath = path;
|
||||||
} else if(Files.isRegularFile(path) && path.getFileName().toString().endsWith(".zip")) {
|
} else if(Files.isRegularFile(path)) {
|
||||||
|
if(!path.getFileName().toString().endsWith(".zip")) {
|
||||||
|
throw new IOException("Could not load config pack, file " + path + " is not a zip");
|
||||||
|
}
|
||||||
FileSystem zipfs = FileSystems.newFileSystem(path);
|
FileSystem zipfs = FileSystems.newFileSystem(path);
|
||||||
this.packDirectory = zipfs.getPath("/");
|
this.rootPath = zipfs.getPath("/");
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Could not load config pack from " + path + ", not a directory or zip file");
|
throw new IOException("Could not load config pack from " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Path packManifestPath = packDirectory.resolve("pack.yml");
|
Path packManifestPath = rootPath.resolve("pack.yml");
|
||||||
if(Files.notExists(packManifestPath)) throw new FileNotFoundException("No pack.yml found in " + path);
|
if(Files.notExists(packManifestPath)) throw new IOException("No pack.yml found in " + path);
|
||||||
Configuration packManifest = new YamlConfiguration(Files.newInputStream(packManifestPath), packManifestPath.getFileName().toString());
|
Configuration packManifest = new YamlConfiguration(Files.newInputStream(packManifestPath), packManifestPath.getFileName().toString());
|
||||||
|
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
@ -277,7 +280,6 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
return seededBiomeProvider;
|
return seededBiomeProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public <T> CheckedRegistry<T> getOrCreateRegistry(TypeKey<T> typeKey) {
|
public <T> CheckedRegistry<T> getOrCreateRegistry(TypeKey<T> typeKey) {
|
||||||
return (CheckedRegistry<T>) registryMap.computeIfAbsent(typeKey.getType(), c -> {
|
return (CheckedRegistry<T>) registryMap.computeIfAbsent(typeKey.getType(), c -> {
|
||||||
@ -316,8 +318,8 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getPackDirectory() {
|
public Path getRootPath() {
|
||||||
return packDirectory;
|
return rootPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -330,7 +332,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
return template.getVersion();
|
return template.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked,rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public <T> ConfigPack registerShortcut(TypeKey<T> clazz, String shortcut, ShortcutLoader<T> loader) {
|
public <T> ConfigPack registerShortcut(TypeKey<T> clazz, String shortcut, ShortcutLoader<T> loader) {
|
||||||
ShortcutHolder<?> holder = shortcuts
|
ShortcutHolder<?> holder = shortcuts
|
||||||
@ -374,12 +376,10 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> CheckedRegistry<T> getRegistry(Type type) {
|
public <T> CheckedRegistry<T> getRegistry(Type type) {
|
||||||
return (CheckedRegistry<T>) registryMap.get(type);
|
return (CheckedRegistry<T>) registryMap.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public <T> CheckedRegistry<T> getCheckedRegistry(Type type) throws IllegalStateException {
|
public <T> CheckedRegistry<T> getCheckedRegistry(Type type) throws IllegalStateException {
|
||||||
return (CheckedRegistry<T>) registryMap.get(type);
|
return (CheckedRegistry<T>) registryMap.get(type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user