Search in sources :

Example 1 with CoreViewNodeBase

use of pcgen.cdom.meta.CoreViewNodeBase 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;
}
Also used : Identified(pcgen.cdom.base.Identified) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FacetView(pcgen.cdom.meta.FacetView) CharID(pcgen.cdom.enumeration.CharID) CoreViewNodeFacade(pcgen.facade.core.CoreViewNodeFacade) HashMapToList(pcgen.base.util.HashMapToList) PrereqObject(pcgen.cdom.base.PrereqObject) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject) CoreViewNodeBase(pcgen.cdom.meta.CoreViewNodeBase)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashMapToList (pcgen.base.util.HashMapToList)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 Identified (pcgen.cdom.base.Identified)1 PrereqObject (pcgen.cdom.base.PrereqObject)1 CharID (pcgen.cdom.enumeration.CharID)1 CoreViewNodeBase (pcgen.cdom.meta.CoreViewNodeBase)1 FacetView (pcgen.cdom.meta.FacetView)1 QualifiedObject (pcgen.core.QualifiedObject)1 CoreViewNodeFacade (pcgen.facade.core.CoreViewNodeFacade)1