Search in sources :

Example 1 with DefaultListFacade

use of pcgen.facade.util.DefaultListFacade in project pcgen by PCGen.

the class DataSet method initLists.

private void initLists() {
    List<Race> raceList = new ArrayList<>(context.getReferenceContext().getConstructedCDOMObjects(Race.class));
    raceList.sort(new RaceComparator());
    for (Race race : raceList) {
        if (race.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            races.addElement(race);
        }
    }
    List<PCClass> classList = new ArrayList<>(context.getReferenceContext().getConstructedCDOMObjects(PCClass.class));
    classList.sort(new PCClassComparator());
    for (PCClass pcClass : classList) {
        if (pcClass.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            classes.addElement(pcClass);
        }
    }
    for (Skill skill : context.getReferenceContext().getConstructedCDOMObjects(Skill.class)) {
        if (skill.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            skills.addElement(skill);
        }
    }
    for (Deity deity : context.getReferenceContext().getConstructedCDOMObjects(Deity.class)) {
        deities.addElement(deity);
    }
    for (PCTemplate template : context.getReferenceContext().getConstructedCDOMObjects(PCTemplate.class)) {
        if (template.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            templates.addElement(template);
        }
    }
    for (Kit kit : context.getReferenceContext().getConstructedCDOMObjects(Kit.class)) {
        kits.addElement(kit);
    }
    for (PCAlignment alignment : context.getReferenceContext().getOrderSortedCDOMObjects(PCAlignment.class)) {
        alignments.addElement(alignment);
    }
    for (PCStat stat : context.getReferenceContext().getOrderSortedCDOMObjects(PCStat.class)) {
        stats.addElement(stat);
    }
    //			new AbilityCategoryComparator());
    for (AbilityCategory category : gameMode.getAllAbilityCategories()) {
        if (category.isVisibleTo(View.VISIBLE_DISPLAY)) {
            //				categories.addElement(category);
            List<Ability> abList = new ArrayList<>(Globals.getContext().getReferenceContext().getManufacturer(Ability.class, category).getAllObjects());
            Globals.sortPObjectListByName(abList);
            DefaultListFacade<AbilityFacade> abilityList = new DefaultListFacade<>(abList);
            for (Iterator<AbilityFacade> iterator = abilityList.iterator(); iterator.hasNext(); ) {
                AbilityFacade facade = iterator.next();
                if (facade instanceof Ability) {
                    Ability ability = (Ability) facade;
                    if (!(ability.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY))) {
                        iterator.remove();
                    }
                }
            }
            abilityMap.put(category, abilityList);
        }
    }
    Map<String, BodyStructure> structMap = new HashMap<>(SystemCollections.getUnmodifiableBodyStructureList().size() + 3);
    for (String name : SystemCollections.getUnmodifiableBodyStructureList()) {
        // TODO i18n the display name and correct the DataSetTest
        String displayName = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
        final BodyStructure bodyStructure = new BodyStructure(displayName);
        bodyStructures.addElement(bodyStructure);
        structMap.put(name, bodyStructure);
    }
    Set<Type> typesWithDesignatedSlots = buildSlottedTypeList();
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_EQUIPPED, true, typesWithDesignatedSlots));
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_CARRIED, true));
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_NOTCARRIED, true));
    for (EquipSlot es : SystemCollections.getUnmodifiableEquipSlotList()) {
        if (structMap.containsKey(es.getBodyStructureName())) {
            structMap.get(es.getBodyStructureName()).addEquipSlot(es);
        }
    }
    for (Equipment eq : context.getReferenceContext().getConstructedCDOMObjects(Equipment.class)) {
        if (eq.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            equipment.addElement(eq);
        }
    }
    for (String xpTableName : gameMode.getXPTableNames()) {
        xpTableNames.addElement(xpTableName);
    }
    for (String characterType : gameMode.getCharacterTypeList()) {
        characterTypes.addElement(characterType);
    }
    for (SizeAdjustment size : context.getReferenceContext().getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER)) {
        sizes.addElement(size);
    }
    createGearBuySellSchemes();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EquipSlot(pcgen.core.character.EquipSlot) Type(pcgen.cdom.enumeration.Type) AbilityFacade(pcgen.facade.core.AbilityFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 2 with DefaultListFacade

use of pcgen.facade.util.DefaultListFacade in project pcgen by PCGen.

the class FacadeFactory method initCampaigns.

private static void initCampaigns() {
    for (final CampaignFacade campaign : campaigns) {
        campaignMap.put(campaign.getName(), campaign);
        ListFacade<GameModeFacade> gameModeList = campaign.getGameModes();
        for (GameModeFacade gameModeFacade : gameModeList) {
            if (!campaignListMap.containsKey(gameModeFacade)) {
                campaignListMap.put(gameModeFacade, new DefaultListFacade<>());
            }
            DefaultListFacade<CampaignFacade> campaignList = campaignListMap.get(gameModeFacade);
            if (campaignList.containsElement(campaign)) {
                String sourceUri = ((CDOMObject) campaign).getSourceURI().toString();
                Logging.errorPrint("Campaign " + sourceUri + " lists GAMEMODE:" + gameModeFacade + " multiple times.");
            } else {
                campaignList.addElement(campaign);
            }
        }
        if (campaign.showInMenu() && !gameModeList.isEmpty()) {
            GameModeFacade game = gameModeList.getElementAt(0);
            ListFacade<CampaignFacade> list = new DefaultListFacade<>(Collections.singleton(campaign));
            quickSources.addElement(new BasicSourceSelectionFacade(campaign.getName(), list, game));
        }
    }
}
Also used : GameModeFacade(pcgen.facade.core.GameModeFacade) CampaignFacade(pcgen.facade.core.CampaignFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 3 with DefaultListFacade

use of pcgen.facade.util.DefaultListFacade in project pcgen by PCGen.

the class CompanionSupportFacadeImplTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    uiDelegate = new MockUIDelegate();
    todoManager = new TodoManager();
    ListFacade<CampaignFacade> campaigns = new DefaultListFacade<>();
    dataSetFacade = new DataSet(Globals.getContext(), SettingsHandler.getGame(), campaigns);
    masterRace = TestHelper.makeRace("Wood Elf");
    companionRace = TestHelper.makeRace("Weasel");
    CDOMReference<Race> race = new CDOMDirectSingleRef<>(companionRace);
    CDOMSingleRef<CompanionList> ref = new CDOMSimpleSingleRef<>(CompanionList.class, companionList.getKeyName());
    FollowerOption option = new FollowerOption(race, ref);
    masterRace.addToListFor(ListKey.COMPANIONLIST, option);
}
Also used : CDOMDirectSingleRef(pcgen.cdom.reference.CDOMDirectSingleRef) DataSet(pcgen.core.DataSet) FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) CDOMSimpleSingleRef(pcgen.cdom.reference.CDOMSimpleSingleRef) CampaignFacade(pcgen.facade.core.CampaignFacade) Race(pcgen.core.Race) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 4 with DefaultListFacade

use of pcgen.facade.util.DefaultListFacade in project pcgen by PCGen.

the class CharacterAbilities method rebuildAbilityLists.

/**
	 * Rebuild the ability lists for the character to include the character's 
	 * current abilities.
	 */
synchronized void rebuildAbilityLists() {
    Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap = new LinkedHashMap<>();
    DefaultListFacade<AbilityCategoryFacade> workingActiveCategories = new DefaultListFacade<>();
    for (AbilityCategoryFacade category : dataSetFacade.getAbilities().getKeys()) {
        AbilityCategory cat = (AbilityCategory) category;
        for (CNAbility cna : theCharacter.getPoolAbilities(cat)) {
            addCategorisedAbility(cna, workingAbilityListMap);
        }
        // deal with visibility
        boolean visible = cat.isVisibleTo(theCharacter, View.VISIBLE_DISPLAY);
        if (visible && !workingActiveCategories.containsElement(cat)) {
            int index = getCatIndex(cat, workingActiveCategories);
            workingActiveCategories.addElement(index, cat);
        }
        if (!visible && workingActiveCategories.containsElement(cat)) {
            workingActiveCategories.removeElement(cat);
        //				updateAbilityCategoryTodo(cat);
        }
        if (visible) {
            adviseSelectionChangeLater(cat);
        }
    }
    // Update map contents
    for (AbilityCategoryFacade category : workingAbilityListMap.keySet()) {
        DefaultListFacade<AbilityFacade> workingListFacade = workingAbilityListMap.get(category);
        DefaultListFacade<AbilityFacade> masterListFacade = abilityListMap.get(category);
        if (masterListFacade == null) {
            abilityListMap.put(category, workingListFacade);
        } else {
            masterListFacade.updateContentsNoOrder(workingListFacade.getContents());
        }
        updateAbilityCategoryTodo((AbilityCategory) category);
    }
    Set<AbilityCategoryFacade> origCats = new HashSet<>(abilityListMap.keySet());
    for (AbilityCategoryFacade category : origCats) {
        if (!workingAbilityListMap.containsKey(category)) {
            if (workingActiveCategories.containsElement(category)) {
                abilityListMap.get(category).clearContents();
            } else {
                abilityListMap.remove(category);
            }
            updateAbilityCategoryTodo((AbilityCategory) category);
        }
    }
    activeCategories.updateContents(workingActiveCategories.getContents());
}
Also used : AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) LinkedHashMap(java.util.LinkedHashMap) CNAbility(pcgen.cdom.content.CNAbility) AbilityFacade(pcgen.facade.core.AbilityFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade) AbilityCategory(pcgen.core.AbilityCategory) HashSet(java.util.HashSet)

Example 5 with DefaultListFacade

use of pcgen.facade.util.DefaultListFacade in project pcgen by PCGen.

the class CharacterFacadeImpl method deleteCustomEquipment.

@Override
public void deleteCustomEquipment(EquipmentFacade eqFacade) {
    if (eqFacade == null || !(eqFacade instanceof Equipment)) {
        return;
    }
    Equipment itemToBeDeleted = (Equipment) eqFacade;
    if (!itemToBeDeleted.isType(Constants.TYPE_CUSTOM)) {
        return;
    }
    if (!delegate.showWarningConfirm(LanguageBundle.getString(//$NON-NLS-1$
    "in_igDeleteCustomWarnTitle"), //$NON-NLS-1$
    LanguageBundle.getFormattedString(//$NON-NLS-1$
    "in_igDeleteCustomWarning", itemToBeDeleted))) {
        return;
    }
    removePurchasedEquipment(itemToBeDeleted, Integer.MAX_VALUE, false);
    Globals.getContext().getReferenceContext().forget(itemToBeDeleted);
    if (dataSet.getEquipment() instanceof DefaultListFacade<?>) {
        ((DefaultListFacade<EquipmentFacade>) dataSet.getEquipment()).removeElement(itemToBeDeleted);
    }
}
Also used : Equipment(pcgen.core.Equipment) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Aggregations

DefaultListFacade (pcgen.facade.util.DefaultListFacade)8 CampaignFacade (pcgen.facade.core.CampaignFacade)4 ArrayList (java.util.ArrayList)2 CNAbility (pcgen.cdom.content.CNAbility)2 Campaign (pcgen.core.Campaign)2 DataSet (pcgen.core.DataSet)2 AbilityFacade (pcgen.facade.core.AbilityFacade)2 URI (java.net.URI)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Type (pcgen.cdom.enumeration.Type)1 CompanionList (pcgen.cdom.list.CompanionList)1 CDOMDirectSingleRef (pcgen.cdom.reference.CDOMDirectSingleRef)1 CDOMSimpleSingleRef (pcgen.cdom.reference.CDOMSimpleSingleRef)1 AbilityCategory (pcgen.core.AbilityCategory)1 Equipment (pcgen.core.Equipment)1 FollowerOption (pcgen.core.FollowerOption)1 GameMode (pcgen.core.GameMode)1 Race (pcgen.core.Race)1