Search in sources :

Example 6 with EquipNode

use of pcgen.facade.core.EquipmentSetFacade.EquipNode in project pcgen by PCGen.

the class EquipmentSetFacadeImplTest method testEmptyInit.

/**
	 * Check that EquipmentSetFacadeImpl can be initialised with an empty dataset.  
	 */
public void testEmptyInit() {
    EquipSet es = new EquipSet("0.1", "Unit Test Equip");
    EquipmentSetFacadeImpl esfi = new EquipmentSetFacadeImpl(uiDelegate, getCharacter(), es, dataset, equipmentList, todoManager, null);
    ListFacade<EquipNode> nodeList = esfi.getNodes();
    assertFalse("Expected a non empty node set", nodeList.isEmpty());
    assertEquals("Incorrect name of base node", Constants.EQUIP_LOCATION_EQUIPPED, nodeList.getElementAt(0).toString());
    assertEquals("Incorrect nunber of nodes found", NUM_BASE_NODES, nodeList.getSize());
}
Also used : EquipSet(pcgen.core.character.EquipSet) EquipNode(pcgen.facade.core.EquipmentSetFacade.EquipNode)

Example 7 with EquipNode

use of pcgen.facade.core.EquipmentSetFacade.EquipNode in project pcgen by PCGen.

the class EquipmentSetFacadeImplTest method testInitWithEquipment.

/**
	 * Check that EquipmentSetFacadeImpl can be initialised with a dataset 
	 * containing equipment.  
	 */
public void testInitWithEquipment() {
    PlayerCharacter pc = getCharacter();
    EquipSet es = new EquipSet("0.1", "Unit Test Equip");
    Equipment item = new Equipment();
    item.setName(SATCHEL);
    Equipment item2 = new Equipment();
    item2.setName(BOOK);
    Equipment item3 = new Equipment();
    item3.setName(QUARTERSTAFF);
    item3.put(IntegerKey.SLOTS, 2);
    EquipSet satchelEs = addEquipToEquipSet(pc, es, item, 1.0f);
    addEquipToEquipSet(pc, satchelEs, item2, 1.0f);
    addEquipToEquipSet(pc, es, item3, 1.0f, LOC_BOTH_HANDS);
    int adjustedBaseNodes = NUM_BASE_NODES - 4;
    EquipmentSetFacadeImpl esfi = new EquipmentSetFacadeImpl(uiDelegate, pc, es, dataset, equipmentList, todoManager, null);
    ListFacade<EquipNode> nodeList = esfi.getNodes();
    assertFalse("Expected a non empty path set", nodeList.isEmpty());
    EquipNodeImpl node = (EquipNodeImpl) nodeList.getElementAt(0);
    assertEquals("Incorrect body struct name", Constants.EQUIP_LOCATION_EQUIPPED, node.toString());
    assertEquals("Incorrect body struct type", NodeType.BODY_SLOT, node.getNodeType());
    assertEquals("Incorrect sort key", "00", node.getSortKey());
    assertEquals("Incorrect parent", null, node.getParent());
    node = (EquipNodeImpl) nodeList.getElementAt(adjustedBaseNodes);
    assertEquals("Incorrect container name", item.getName(), node.toString());
    assertEquals("Incorrect container type", NodeType.EQUIPMENT, node.getNodeType());
    assertEquals("Incorrect sort key", "00|" + item.getName(), node.getSortKey());
    assertEquals("Incorrect parent", nodeList.getElementAt(0), node.getParent());
    node = (EquipNodeImpl) nodeList.getElementAt(adjustedBaseNodes + 2);
    assertEquals("Incorrect item name", item2.getName(), node.toString());
    assertEquals("Incorrect item type", NodeType.EQUIPMENT, node.getNodeType());
    assertEquals("Incorrect sort key", "00|" + item.getName() + "|" + item2.getName(), node.getSortKey());
    assertEquals("Incorrect parent", nodeList.getElementAt(adjustedBaseNodes), node.getParent());
    node = (EquipNodeImpl) nodeList.getElementAt(adjustedBaseNodes + 1);
    assertEquals("Incorrect item name", item3.getName(), node.toString());
    assertEquals("Incorrect item type", NodeType.EQUIPMENT, node.getNodeType());
    assertEquals("Incorrect sort key", "01|" + item3.getName(), node.getSortKey());
    assertEquals("Incorrect parent", LOC_HANDS, node.getParent().toString());
    node = (EquipNodeImpl) nodeList.getElementAt(adjustedBaseNodes + 2);
    EquipNode parent = node.getParent();
    assertEquals("Root incorrect", Constants.EQUIP_LOCATION_EQUIPPED, parent.getParent().toString());
    assertEquals("Leaf incorrect", item.getName(), parent.toString());
    assertEquals("Incorrect nuber of paths found", adjustedBaseNodes + 3, nodeList.getSize());
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) EquipNodeImpl(pcgen.gui2.facade.EquipmentSetFacadeImpl.EquipNodeImpl) EquipSet(pcgen.core.character.EquipSet) EquipNode(pcgen.facade.core.EquipmentSetFacade.EquipNode)

Example 8 with EquipNode

use of pcgen.facade.core.EquipmentSetFacade.EquipNode in project pcgen by PCGen.

the class EquipmentTreeTableModel method elementRemoved.

@Override
public void elementRemoved(ListEvent<EquipNode> e) {
    EquipNode child = e.getElement();
    EquipNode parent = child.getParent();
    List<EquipNode> children = pathMap.get(parent);
    int index = children.indexOf(child);
    pathMap.remove(parent, index);
    fireTreeNodesRemoved(this, getPathToRoot(parent), new int[] { index }, new Object[] { child });
}
Also used : EquipNode(pcgen.facade.core.EquipmentSetFacade.EquipNode)

Example 9 with EquipNode

use of pcgen.facade.core.EquipmentSetFacade.EquipNode in project pcgen by PCGen.

the class EquipmentTreeTableModel method quantityChanged.

@Override
public void quantityChanged(EquipmentTreeEvent e) {
    EquipNode child = e.getNode();
    EquipNode parent = child.getParent();
    List<EquipNode> children = pathMap.get(parent);
    int index = Collections.binarySearch(children, child, pathComparator);
    fireTreeNodesChanged(this, getPathToRoot(parent), new int[] { index }, new Object[] { child });
}
Also used : EquipNode(pcgen.facade.core.EquipmentSetFacade.EquipNode)

Example 10 with EquipNode

use of pcgen.facade.core.EquipmentSetFacade.EquipNode in project pcgen by PCGen.

the class EquipmentModels method getSelectedEquipmentSetNodes.

private List<EquipNode> getSelectedEquipmentSetNodes() {
    int[] rows = equipmentSetTable.getSelectedRows();
    List<EquipNode> paths = new ArrayList<>();
    for (int row : rows) {
        EquipNode path = (EquipNode) equipmentSetTable.getValueAt(row, 0);
        if (path.getNodeType() == NodeType.EQUIPMENT) {
            paths.add(path);
        }
    }
    return paths;
}
Also used : ArrayList(java.util.ArrayList) EquipNode(pcgen.facade.core.EquipmentSetFacade.EquipNode)

Aggregations

EquipNode (pcgen.facade.core.EquipmentSetFacade.EquipNode)14 EquipSet (pcgen.core.character.EquipSet)7 Equipment (pcgen.core.Equipment)4 HashMap (java.util.HashMap)3 PlayerCharacter (pcgen.core.PlayerCharacter)3 EquipNodeImpl (pcgen.gui2.facade.EquipmentSetFacadeImpl.EquipNodeImpl)3 ArrayList (java.util.ArrayList)1 PCTemplate (pcgen.core.PCTemplate)1