use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleManager method loadModulesFromClassPath.
private void loadModulesFromClassPath() {
ClasspathCompromisingModuleFactory ccModuleFactory = (ClasspathCompromisingModuleFactory) this.moduleFactory;
for (String metadataName : ccModuleFactory.getModuleMetadataLoaderMap().keySet()) {
Enumeration<URL> urls;
try {
urls = ClassLoader.getSystemResources(metadataName);
} catch (IOException e) {
throw new RuntimeException(e);
}
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
logger.debug("Probably a module in U:{}", url);
Path path = ccModuleFactory.canonicalModuleLocation(metadataName, url);
Module module;
try {
module = ccModuleFactory.createModule(path.toFile());
} catch (IOException e) {
logger.warn("Failed to create module from {}", path, e);
continue;
}
if (registry.add(module)) {
logger.info("Loaded {} from {}", module.getId(), path);
} else {
logger.info("Module {} from {} was a duplicate; not registering this copy.", module.getId(), path);
}
}
}
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ComponentSystemManager method loadSystems.
public void loadSystems(ModuleEnvironment environment, NetworkMode netMode) {
DisplayDevice display = context.get(DisplayDevice.class);
boolean isHeadless = display.isHeadless();
ListMultimap<Name, Class<?>> systemsByModule = ArrayListMultimap.create();
for (Class<?> type : environment.getTypesAnnotatedWith(RegisterSystem.class)) {
if (!ComponentSystem.class.isAssignableFrom(type)) {
logger.error("Cannot load {}, must be a subclass of ComponentSystem", type.getSimpleName());
continue;
}
Name moduleId = environment.getModuleProviding(type);
RegisterSystem registerInfo = type.getAnnotation(RegisterSystem.class);
if (registerInfo.value().isValidFor(netMode.isAuthority(), isHeadless) && areOptionalRequirementsContained(registerInfo, environment)) {
systemsByModule.put(moduleId, type);
}
}
for (Module module : environment.getModulesOrderedByDependencies()) {
for (Class<?> system : systemsByModule.get(module.getId())) {
String id = module.getId() + ":" + system.getSimpleName();
logger.debug("Registering system {}", id);
if (checkOptionalDependenciesPresent(system)) {
tryToLoadSystem(system, id);
} else {
logger.warn("Skip system {} for loading - possibly missing optional dependencies", id);
}
}
}
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class GameDetailsScreen method setUpGameModules.
private void setUpGameModules() {
gameModules.subscribeSelection((widget, moduleSelectionInfo) -> {
if (moduleSelectionInfo == null) {
return;
}
descriptionTitle.setText(translationSystem.translate("${engine:menu#game-details-module-description}"));
description.setText(getModuleDescription(moduleSelectionInfo));
gameWorlds.setSelection(null);
blocks.setSelection(null);
});
gameModules.setItemRenderer(new AbstractItemRenderer<ModuleSelectionInfo>() {
String getString(ModuleSelectionInfo value) {
if (value.getMetadata() != null) {
return value.getMetadata().getDisplayName().toString();
} else if (value.isUnavailableVersion()) {
return value.getUnavailableModuleName();
}
return "";
}
@Override
public void draw(ModuleSelectionInfo value, Canvas canvas) {
if (value.isStrictVersion()) {
canvas.setMode("strict");
} else if (value.isLatestVersion()) {
canvas.setMode("latest");
} else {
canvas.setMode("invalid");
}
canvas.drawText(getString(value), canvas.getRegion());
}
@Override
public Vector2i getPreferredSize(ModuleSelectionInfo value, Canvas canvas) {
String text = getString(value);
return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
}
});
gameModules.subscribe(((widget, item) -> openModuleDetailsScreen()));
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class GameDetailsScreen method loadGameModules.
private void loadGameModules() {
final List<ModuleSelectionInfo> sortedGameModules = gameInfo.getManifest().getModules().stream().sorted(Comparator.comparing(NameVersion::getName)).map(nameVersion -> {
Module module = moduleManager.getRegistry().getModule(nameVersion.getName(), nameVersion.getVersion());
if (module != null) {
return ModuleSelectionInfo.strictVersion(module);
} else {
logger.warn("Can't find module in your classpath - {}:{}", nameVersion.getName(), nameVersion.getVersion());
module = moduleManager.getRegistry().getLatestModuleVersion(nameVersion.getName());
if (module != null) {
logger.debug("Get the latest available version of module {} in your classpath", nameVersion.getName());
errors.add(String.format("Can't find module %s:%s in your classpath; " + "loaded description for the latest available version.", nameVersion.getName(), nameVersion.getVersion()));
return ModuleSelectionInfo.latestVersion(module);
}
logger.error("Can't find any versions of module {} in your classpath!", nameVersion.getName());
errors.add(String.format("Can't find any versions of module %s in your classpath!", nameVersion.getName()));
return ModuleSelectionInfo.unavailableVersion(nameVersion.getName().toString(), nameVersion.getVersion().toString());
}
}).filter(Objects::nonNull).collect(Collectors.toList());
gameModules.setList(sortedGameModules);
gameModules.select(0);
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleDetailsScreen method setUpModules.
private void setUpModules() {
modules.subscribeSelection(((widget, item) -> {
if (item != null) {
dependencies.setList(getSortedDependencies(item));
dependencies.setSelection(null);
dependencies.select(0);
this.updateOpenInBrowserButton();
}
}));
modules.setItemRenderer(new StringTextRenderer<Module>() {
@Override
public String getString(Module value) {
if (value != null) {
return value.getMetadata().getDisplayName().toString();
}
return "";
}
@Override
public void draw(Module value, Canvas canvas) {
if (!validateModuleDependencies(value.getId())) {
canvas.setMode(("invalid"));
} else {
canvas.setMode("available");
}
canvas.drawText(getString(value), canvas.getRegion());
}
@Override
public Vector2i getPreferredSize(Module value, Canvas canvas) {
String text = getString(value);
return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
}
});
}
Aggregations