use of org.spongepowered.api.registry.CatalogRegistryModule in project SpongeCommon by SpongePowered.
the class SpongeGameRegistry method preRegistryInit.
public void preRegistryInit() {
CommonModuleRegistry.getInstance().registerDefaultModules();
final DirectedGraph<Class<? extends RegistryModule>> graph = new DirectedGraph<>();
for (RegistryModule module : this.registryModules) {
this.classMap.put(module.getClass(), module);
addToGraph(module, graph);
}
// Now we need ot do the catalog ones
for (CatalogRegistryModule<?> module : this.catalogRegistryMap.values()) {
this.classMap.put(module.getClass(), module);
addToGraph(module, graph);
}
try {
this.orderedModules.addAll(TopologicalOrder.createOrderedLoad(graph));
} catch (CyclicGraphException e) {
StringBuilder msg = new StringBuilder();
msg.append("Registry module dependencies are cyclical!\n");
msg.append("Dependency loops are:\n");
for (DataNode<?>[] cycle : e.getCycles()) {
msg.append("[");
for (DataNode<?> node : cycle) {
msg.append(node.getData().toString()).append(" ");
}
msg.append("]\n");
}
SpongeImpl.getLogger().fatal(msg.toString());
throw new RuntimeException("Registry modules dependencies error.");
}
registerModulePhase();
SpongeVillagerRegistry.registerVanillaTrades();
DataRegistrar.setupSerialization();
final List<Tuple<Class<? extends CatalogType>, CatalogRegistryModule<?>>> modules = new ArrayList<>();
for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : this.catalogRegistryMap.entrySet()) {
modules.add(new Tuple<>(entry.getKey(), entry.getValue()));
}
modules.sort(Comparator.comparing(tuple -> tuple.getFirst().getSimpleName()));
if (PRINT_CATALOG_TYPES) {
// Lol... this gets spammy really fast.... Probably at some point should be put to file.
final PrettyPrinter printer = new PrettyPrinter(100).add("Printing all Catalogs and their ID's").centre().hr().addWrapped("This is a test to print out all registered catalogs during initialization for their mapping, id's, and objects themselves.");
for (Tuple<Class<? extends CatalogType>, CatalogRegistryModule<?>> module : modules) {
printer.add(" %s : %s", "CatalogType", module.getFirst().getSimpleName());
final Collection<? extends CatalogType> all = module.getSecond().getAll();
final List<CatalogType> catalogTypes = new ArrayList<>(all);
catalogTypes.sort(Comparator.comparing(CatalogType::getId));
for (CatalogType catalogType : catalogTypes) {
printer.add(" -%s", catalogType.getId());
}
printer.hr();
}
printer.trace(System.err, SpongeImpl.getLogger(), Level.DEBUG);
}
}
use of org.spongepowered.api.registry.CatalogRegistryModule in project LanternServer by LanternPowered.
the class LanternGameRegistry method syncModules.
private void syncModules() {
if (this.modulesSynced) {
return;
}
final DirectedGraph<Class<? extends RegistryModule>> graph = new DirectedGraph<>();
for (RegistryModule aModule : this.registryModules) {
if (!this.classMap.containsKey(aModule.getClass())) {
this.classMap.put(aModule.getClass(), aModule);
}
addToGraph(aModule, graph);
}
// Now we need ot do the catalog ones
for (CatalogRegistryModule<?> aModule : this.catalogRegistryMap.values()) {
if (!this.classMap.containsKey(aModule.getClass())) {
this.classMap.put(aModule.getClass(), aModule);
}
addToGraph(aModule, graph);
}
this.orderedModules.clear();
try {
this.orderedModules.addAll(TopologicalOrder.createOrderedLoad(graph));
} catch (CyclicGraphException e) {
final StringBuilder msg = new StringBuilder();
msg.append("Registry module dependencies are cyclical!\n");
msg.append("Dependency loops are:\n");
for (DirectedGraph.DataNode<?>[] cycle : e.getCycles()) {
msg.append("[");
for (DirectedGraph.DataNode<?> node : cycle) {
msg.append(node.getData().toString()).append(" ");
}
msg.append("]\n");
}
this.game.getLog4jLogger().fatal(msg.toString());
throw new RuntimeException("Registry modules dependencies error.");
}
this.modulesSynced = true;
}
use of org.spongepowered.api.registry.CatalogRegistryModule in project SpongeCommon by SpongePowered.
the class RegistryTestUtil method generateCatalogContainerTestObjects.
static Iterable<Object[]> generateCatalogContainerTestObjects() {
final SpongeGameRegistry registry = (SpongeGameRegistry) Sponge.getGame().getRegistry();
final ArrayList<Object[]> objects = new ArrayList<>();
for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : registry.catalogRegistryMap.entrySet()) {
final Class<? extends CatalogType> key = entry.getKey();
final CatalogedBy catalogedBy = key.getAnnotation(CatalogedBy.class);
if (catalogedBy != null) {
for (Class<?> containerClass : catalogedBy.value()) {
for (Field field : containerClass.getFields()) {
if (Modifier.isStatic(field.getModifiers())) {
objects.add(new Object[] { field.getName(), entry.getKey(), containerClass, entry.getValue(), field });
}
}
}
}
}
return objects;
}
use of org.spongepowered.api.registry.CatalogRegistryModule in project SpongeCommon by SpongePowered.
the class RegistryTestUtil method generateRegistryTestObjects.
static Iterable<Object[]> generateRegistryTestObjects() {
final SpongeGameRegistry registry = (SpongeGameRegistry) Sponge.getGame().getRegistry();
final ArrayList<Object[]> array = new ArrayList<>();
for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : registry.catalogRegistryMap.entrySet()) {
for (CatalogType catalogType : entry.getValue().getAll()) {
array.add(new Object[] { entry.getKey().getSimpleName(), entry.getKey(), entry.getValue(), catalogType, catalogType.getId() });
}
}
return array;
}
use of org.spongepowered.api.registry.CatalogRegistryModule in project SpongeCommon by SpongePowered.
the class RegistryTestUtil method generateCatalogTypeMethodTestObjects.
static Iterable<Object[]> generateCatalogTypeMethodTestObjects() {
final SpongeGameRegistry registry = (SpongeGameRegistry) Sponge.getGame().getRegistry();
final ArrayList<Object[]> array = new ArrayList<>();
for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : registry.catalogRegistryMap.entrySet()) {
for (CatalogType catalogType : entry.getValue().getAll()) {
for (Method method : getTestableApiMethods(getApplicableApiCatalogTypeInterfaces(catalogType))) {
array.add(new Object[] { entry.getKey().getSimpleName(), entry.getKey(), catalogType, catalogType.getId(), method, method.getDeclaringClass().getSimpleName() + "#" + method.getName() + "()", catalogType.getClass().getName() });
}
}
}
return array;
}
Aggregations