use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class RegisterMods method step.
@Override
public boolean step() {
if (applyModulesThread != null) {
if (!applyModulesThread.isAlive()) {
if (oldEnvironment != null) {
oldEnvironment.close();
}
return true;
}
return false;
} else {
ModuleManager moduleManager = context.get(ModuleManager.class);
List<Name> moduleIds = gameManifest.getModules().stream().map(NameVersion::getName).collect(Collectors.toCollection(ArrayList::new));
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(moduleIds);
if (result.isSuccess()) {
oldEnvironment = moduleManager.getEnvironment();
ModuleEnvironment env = moduleManager.loadEnvironment(result.getModules(), true);
for (Module moduleInfo : env.getModulesOrderedByDependencies()) {
logger.info("Activating module: {}:{}", moduleInfo.getId(), moduleInfo.getVersion());
}
EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
applyModulesThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
applyModulesThread.start();
return false;
} else {
logger.warn("Missing at least one required module (or dependency) from the following list: {}", moduleIds);
context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
return true;
}
}
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class FontFormat method parsePage.
private void parsePage(FontDataBuilder builder, Name moduleName, String pageInfo) throws IOException {
Matcher pageMatcher = pagePattern.matcher(pageInfo);
if (pageMatcher.matches()) {
int pageId = Integer.parseInt(pageMatcher.group(1));
Name textureName = new Name(pageMatcher.group(2).substring(0, pageMatcher.group(2).lastIndexOf('.')));
Optional<Material> material = assetManager.getAsset(new ResourceUrn(moduleName, new Name("font"), textureName), Material.class);
if (!material.isPresent()) {
throw new IOException("Failed to load font - unable to resolve font page '" + textureName + "'");
} else {
builder.addPage(pageId, assetManager.getAsset(new ResourceUrn(moduleName, textureName), Texture.class).get(), material.get());
}
} else {
throw new IOException("Failed to load font - invalid page line '" + pageInfo + "'");
}
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class NoiseTextureProducer method getAssetData.
@Override
public Optional<TextureData> getAssetData(ResourceUrn urn) throws IOException {
if (TerasologyConstants.ENGINE_MODULE.equals(urn.getModuleName()) && TextureUtil.NOISE_RESOURCE_NAME.equals(urn.getResourceName())) {
Name fragmentName = urn.getFragmentName();
if (!fragmentName.isEmpty()) {
String[] parts = fragmentName.toLowerCase().split("\\.");
if (parts.length == 5) {
String type = parts[0];
int size = Integer.parseInt(parts[1]);
long seed = Long.parseLong(parts[2]);
int min = Integer.parseInt(parts[3]);
int max = Integer.parseInt(parts[4]);
switch(type) {
case "white":
return Optional.of(TextureDataFactory.createWhiteNoiseTexture(size, seed, min, max));
}
}
}
}
return Optional.empty();
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class ReflectionUtil method getTypeUri.
public static String getTypeUri(Type type, ModuleEnvironment moduleEnvironment) {
String typeSimpleName = typeToString(type, true);
if (getRawType(type).getClassLoader() == null) {
return typeSimpleName;
}
Name moduleProvidingType = moduleEnvironment.getModuleProviding(getRawType(type));
if (moduleProvidingType == null) {
return typeSimpleName;
}
return new SimpleUri(moduleProvidingType, typeSimpleName).toString();
}
use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.
the class ReflectionUtil method getFullyQualifiedSimpleUriFor.
/**
* Returns the fully qualified {@link SimpleUri} for a type belonging to the {@link ModuleEnvironment}.
* If the type does not belong to the module environment, null is returned.
*/
public static SimpleUri getFullyQualifiedSimpleUriFor(Type type, ModuleEnvironment environment) {
Class<?> clazz = getRawType(type);
if (clazz.getClassLoader() == null) {
// Loaded with the bootstrap class loader, definitely not part of a module
return null;
}
Name moduleProviding = environment.getModuleProviding(clazz);
if (moduleProviding == null) {
return null;
}
return new SimpleUri(moduleProviding, clazz.getTypeName());
}
Aggregations