use of megamek.common.annotations.Nullable in project megameklab by MegaMek.
the class BayWeaponCriticalTree method addToBay.
/**
* Adds an equipment mount to a bay. Changes the equipment mount's location and updates the bay's
* weapon or ammo list if necessary.
*
* @param bay
* @param eq
*/
public void addToBay(@Nullable Mounted bay, Mounted eq) {
// Check that we have a bay
if ((null == bay) || !canTakeEquipment(bay, eq)) {
if (eq.getType() instanceof WeaponType) {
EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
addToNewBay(bayType, eq);
} else {
addToLocation(eq);
}
return;
} else if (eq.getType() instanceof MiscType) {
if (eq.getType().hasFlag(MiscType.F_ARTEMIS) || eq.getType().hasFlag(MiscType.F_ARTEMIS_PROTO) || eq.getType().hasFlag(MiscType.F_ARTEMIS_V)) {
for (Integer eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
final WeaponType wtype = (WeaponType) weapon.getType();
if ((weapon.getLinkedBy() == null) && ((wtype.getAmmoType() == AmmoType.T_LRM) || (wtype.getAmmoType() == AmmoType.T_SRM) || (wtype.getAmmoType() == AmmoType.T_MML) || (wtype.getAmmoType() == AmmoType.T_NLRM))) {
moveToArc(eq);
eq.setLinked(weapon);
break;
}
}
} else if (eq.getType().hasFlag(MiscType.F_APOLLO) || eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR)) {
for (Integer eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
if (weapon.getLinkedBy() == null) {
moveToArc(eq);
eq.setLinked(weapon);
break;
}
}
}
} else {
// there.
if (eq.getType() instanceof AmmoType) {
Optional<Mounted> addMount = bay.getBayAmmo().stream().map(n -> eSource.getEntity().getEquipment(n)).filter(m -> m.getType() == eq.getType()).findFirst();
if (addMount.isPresent()) {
addMount.get().setShotsLeft(addMount.get().getBaseShotsLeft() + eq.getBaseShotsLeft());
UnitUtil.removeMounted(eSource.getEntity(), eq);
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
return;
}
}
EquipmentNode bayNode = null;
for (Enumeration<?> e = ((TreeNode) model.getRoot()).children(); e.hasMoreElements(); ) {
final EquipmentNode node = (EquipmentNode) e.nextElement();
if (node.getMounted() == bay) {
bayNode = node;
break;
}
}
if (null != bayNode) {
moveToArc(eq);
EquipmentNode eqNode = new EquipmentNode(eq);
model.insertNodeInto(eqNode, bayNode, bayNode.getChildCount());
eqNode.setParent(bayNode);
if (eq.getType() instanceof WeaponType) {
bay.addWeaponToBay(eSource.getEntity().getEquipmentNum(eq));
if (eq.getLinkedBy() != null) {
moveToArc(eq.getLinkedBy());
}
} else if (eq.getType() instanceof AmmoType) {
bay.addAmmoToBay(eSource.getEntity().getEquipmentNum(eq));
}
} else {
// $NON-NLS-1$
MegaMekLab.getLogger().log(// $NON-NLS-1$
BayWeaponCriticalTree.class, // $NON-NLS-1$
"addToBay(Mounted,Mounted)", LogLevel.DEBUG, // $NON-NLS-1$
bay.getName() + "[" + eSource.getEntity().getEquipmentNum(bay) + "] not found in " + // $NON-NLS-1$
getLocationName());
}
}
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
}
use of megamek.common.annotations.Nullable in project megameklab by MegaMek.
the class PrintMech method loadPipSVG.
@Nullable
private NodeList loadPipSVG(String filename) {
File f = new File(filename);
if (!f.exists()) {
return null;
}
Document doc;
try (InputStream is = new FileInputStream(f)) {
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
final String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
doc = df.createDocument(f.toURI().toASCIIString(), is);
} catch (Exception e) {
LogManager.getLogger().error("Failed to open pip SVG file! Path: " + f.getName());
return null;
}
if (doc == null) {
LogManager.getLogger().error("Failed to open pip SVG file! Path: " + f.getName());
return null;
} else {
return doc.getElementsByTagName(SVGConstants.SVG_PATH_TAG);
}
}
use of megamek.common.annotations.Nullable in project megameklab by MegaMek.
the class PrintRecordSheet method loadSVG.
/**
* Creates a {@link Document} from an svg image file
*
* @param filename The name of the SVG file
* @return The document object
*/
@Nullable
static Document loadSVG(String dirName, String filename) {
File f = new File(dirName, filename);
Document svgDocument = null;
try (InputStream is = new FileInputStream(f)) {
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
final String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
svgDocument = df.createDocument(f.toURI().toASCIIString(), is);
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
}
if (svgDocument == null) {
LogManager.getLogger().error("Failed to open SVG file! Path: data/images/recordsheets/" + filename);
}
return svgDocument;
}
Aggregations