use of pcgen.facade.core.CoreViewNodeFacade in project pcgen by PCGen.
the class CoreUtils method buildCoreDebugList.
static <T> List<CoreViewNodeFacade> buildCoreDebugList(PlayerCharacter pc, CorePerspective pers) {
CharID id = pc.getCharID();
List<CoreViewNodeFacade> coreViewList = new ArrayList<>();
Collection<Object> locations = CorePerspectiveDB.getLocations(pers);
MapToList<Object, FacetView<T>> sources = new HashMapToList<>();
Map<FacetView<T>, CoreViewNodeBase> facetToNode = new HashMap<>();
/*
* Create the nodes that are part of this perspective.
*/
for (Object location : locations) {
//Create (w/ identifier)
FacetView<T> view = CorePerspectiveDB.getView(pers, location);
CoreViewNodeBase node = new LocationCoreViewNode<>(location);
facetToNode.put(view, node);
coreViewList.add(node);
//Store what facets listen to my content (for use later)
for (Object listener : view.getChildren()) {
Object lView = CorePerspectiveDB.getViewOfFacet(listener);
Object src = (lView == null) ? listener : lView;
sources.addToListFor(src, view);
}
Collection<Object> parents = CorePerspectiveDB.getVirtualParents(view);
if (parents != null) {
for (Object parent : parents) {
FacetView<T> parentView = CorePerspectiveDB.getViewOfFacet(parent);
if (parentView == null) {
Logging.errorPrint("Expected " + parent + " to be a registered Facet in Perspective " + pers);
}
sources.addToListFor(view, parentView);
}
}
}
for (Object location : locations) {
FacetView<T> view = CorePerspectiveDB.getView(pers, location);
CoreViewNodeBase node = facetToNode.get(view);
/*
* Check the source of each child to identify if:
*
* (a) The source is a Loadable that can thus be identified as such
*
* (b) The source is a known facet (and thus is identified as such)
*
* (c) the source is not something recognized
*/
for (T obj : view.getSet(id)) {
List<String> sourceDesc = new ArrayList<>();
for (Object src : view.getSources(id, obj)) {
if (src instanceof Identified) {
sourceDesc.add(getLoadID(src));
} else {
FacetView<Object> srcView = CorePerspectiveDB.getViewOfFacet(src);
if (srcView == null) {
//Not a recognized view
sourceDesc.add("Orphaned [" + src.getClass().getSimpleName() + "]");
} else if (facetToNode.get(srcView) == null) {
//A View, but not part of this perspective
sourceDesc.add("Other Perspective [" + CorePerspectiveDB.getPerspectiveOfFacet(src) + ": " + srcView.getDescription() + "]");
}
}
}
//Insert the contents of the facet as children of this node
ObjectCoreViewNode<T> sourceNode = new ObjectCoreViewNode<>(pc, obj, sourceDesc);
sourceNode.addGrantedByNode(node);
coreViewList.add(sourceNode);
}
}
/*
* For each location, put sources as children in the tree
*/
for (Object location : locations) {
FacetView<T> view = CorePerspectiveDB.getView(pers, location);
CoreViewNodeBase node = facetToNode.get(view);
List<FacetView<T>> facetInputs = sources.getListFor(view);
if (facetInputs != null) {
for (FacetView<T> facet : facetInputs) {
facetToNode.get(facet).addGrantedByNode(node);
}
}
}
return coreViewList;
}
Aggregations