public Entity loadEntity(File f, String entityName) { Entity entity = null; try { entity = new MechFileParser(f, entityName).getEntity(); } catch (megamek.common.loaders.EntityLoadingException e) { System.out.println("Exception: " + e.toString()); } return entity; }
public Entity loadEntity(File f, String entityName) { Entity entity = null; try { entity = new MechFileParser(f, entityName).getEntity(); } catch (megamek.common.loaders.EntityLoadingException e) { System.out.println("Exception: " + e.toString()); //$NON-NLS-1$ } return entity; }
public Entity loadEntity(File f, String entityName) { Entity entity = null; try { entity = new MechFileParser(f, entityName).getEntity(); } catch (megamek.common.loaders.EntityLoadingException e) { System.out.println("Exception: " + e.toString()); //$NON-NLS-1$ } return entity; }
public static Entity loadEntity(File f, String entityName) { Entity entity = null; try { entity = new MechFileParser(f, entityName).getEntity(); } catch (megamek.common.loaders.EntityLoadingException e) { System.out.println("Exception: " + e.toString()); e.printStackTrace(); } return entity; }
/** * Loads the Entity and counts the number of docking hardpoints. * * @param ms The unit to load * @return The number of docking hardpoints on the unit. */ private int countHardpoints(MechSummary ms) { try { Entity entity = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); int hardpoints = entity.getDockingCollars().size(); // TODO: count dropshuttle bays hardpointCache.put(ms, hardpoints); return hardpoints; } catch (EntityLoadingException ex) { return 0; } }
/** * Loads the entity, counts the unit type transport capacity, and adds to the cache. * * @param ms The unit to load * @return true if the Entity can be loaded and counted, false if there was an EntityLoadingException */ private boolean countBays(MechSummary ms) { try { Entity entity = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); bayTypeCache.put(ms, countBays(entity)); return true; } catch (EntityLoadingException ex) { return false; } }
public static void main(String[] ARGS) throws Exception { MechSummary ms = MechSummaryCache.getInstance().getMech(ARGS[0]); Entity e = new MechFileParser(ms.getSourceFile(), ms.getEntryName()) .getEntity(); System.out.println(format(e)); } }
public SkinEditorMainGUI() { super(new BorderLayout()); this.addComponentListener(this); panMain.setLayout(cardsMain); panSecondary.setLayout(cardsSecondary); JPanel panDisplay = new JPanel(new BorderLayout()); panDisplay.add(panMain, BorderLayout.CENTER); panDisplay.add(panSecondary, BorderLayout.SOUTH); add(panDisplay, BorderLayout.CENTER); UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(frame); if (!MechSummaryCache.getInstance().isInitialized()) { unitLoadingDialog.setVisible(true); } try { MechSummary ms = MechSummaryCache.getInstance().getMech( "Archer ARC-2W"); testEntity = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); } catch (EntityLoadingException e) { e.printStackTrace(); } }
@Test public void testCalculateWeight() { File f; MechFileParser mfp; Entity e; int expectedWeight, computedWeight; // Test 1/1 try { f = new File("data/mechfiles/mechs/3050U/Exterminator EXT-4A.mtf"); mfp = new MechFileParser(f); e = mfp.getEntity(); expectedWeight = 65; computedWeight = (int)e.getWeight(); TestCase.assertEquals(expectedWeight, computedWeight); } catch (Exception exc){ TestCase.fail(exc.getMessage()); } }
public Entity getSelectedEntity() { int view = tableUnits.getSelectedRow(); if (view < 0) { // selection got filtered away return null; } int selected = tableUnits.convertRowIndexToModel(view); // else MechSummary ms = mechs[selected]; try { // For some unknown reason the base path gets screwed up after you // print so this sets the source file to the full path. Entity entity = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); return entity; } catch (EntityLoadingException ex) { System.out.println("Unable to load mech: " + ms.getSourceFile() + ": " + ms.getEntryName() + ": " + ex.getMessage()); ex.printStackTrace(); return null; } }
public void loadEntities(Ruleset.ProgressListener l, double progress) { if (element) { MechSummary ms = MechSummaryCache.getInstance().getMech(getModelName()); if (ms != null) { try { entity = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); entity.setCrew(getCo().createCrew(entity.defaultCrewType())); entity.setExternalIdAsString(UUID.randomUUID().toString()); } catch (EntityLoadingException ex) { DefaultMmLogger.getInstance().log(getClass(), "loadEntities(Ruleset#ProgressListener, double)", LogLevel.ERROR, "Error loading " + ms.getName() + " from file " + ms.getSourceFile().getPath()); DefaultMmLogger.getInstance().error(getClass(), "loadEntities(Ruleset#ProgressListener, double)", ex); } } } int count = subforces.size() + attached.size(); subforces.forEach(fd -> fd.loadEntities(l, progress / count)); attached.forEach(fd -> fd.loadEntities(l, progress / count)); if (count == 0 && null != l) { l.updateProgress(progress, "Loading entities"); } }
public static Entity getBrandNewUndamagedEntity(String entityShortName) { MechSummary mechSummary = MechSummaryCache.getInstance().getMech( entityShortName); if (mechSummary == null) { return null; } MechFileParser mechFileParser = null; try { mechFileParser = new MechFileParser(mechSummary.getSourceFile()); } catch (EntityLoadingException ex) { MekHQ.getLogger().error(Campaign.class, "getBrandNewUndamagedEntity(String)", ex); } if (mechFileParser == null) { return null; } return mechFileParser.getEntity(); }
private void offerChanged(ListSelectionEvent evt) { final String METHOD_NAME = "offerChanged(ListSelectionEvent)"; //$NON-NLS-1$ int view = tableUnits.getSelectedRow(); if(view < 0) { //selection got filtered away selectedEntity= null; refreshOfferView(); return; } MechSummary ms = marketModel.getOffer(tableUnits.convertRowIndexToModel(view)).unit; try { selectedEntity = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); } catch (EntityLoadingException e) { selectedEntity = null; btnPurchase.setEnabled(false); MekHQ.getLogger().log(getClass(), METHOD_NAME, LogLevel.ERROR, "Unable to load mech: " + ms.getSourceFile() + ": " //$NON-NLS-1$ + ms.getEntryName() + ": " + e.getMessage()); //$NON-NLS-1$ MekHQ.getLogger().error(getClass(), METHOD_NAME, e); refreshOfferView(); return; } refreshOfferView(); }
@Override public Object getNewEquipment() { final String METHOD_NAME = "getNewEquipment()"; //$NON-NLS-1$ String name = getEntity().getChassis() + " " + getEntity().getModel(); name = name.trim(); MechSummary summary = MechSummaryCache.getInstance().getMech(name); if(null == summary) { //throw(new EntityLoadingException()); MekHQ.getLogger().log(getClass(), METHOD_NAME, LogLevel.ERROR, "Could not find a mech summary for " + name); //$NON-NLS-1$ return null; } try { return new MechFileParser(summary.getSourceFile(), summary.getEntryName()).getEntity(); } catch (EntityLoadingException e) { MekHQ.getLogger().log(getClass(), METHOD_NAME, LogLevel.ERROR, "Could not load " + summary.getEntryName()); //$NON-NLS-1$ return null; } }
private void populateRefits() { ArrayList<Refit> refits = new ArrayList<Refit>(); for(String model : Utilities.getAllVariants(unit.getEntity(), campaign)) { MechSummary summary = MechSummaryCache.getInstance().getMech(unit.getEntity().getChassis() + " " + model); if(null == summary) { continue; } try { Entity refitEn = new MechFileParser(summary.getSourceFile(), summary.getEntryName()).getEntity(); if(null != refitEn) { Refit r = new Refit(unit, refitEn, false, false); if(null == r.checkFixable()) { refits.add(r); } } } catch (EntityLoadingException ex) { MekHQ.getLogger().error(getClass(), "populateRefits()", ex); //$NON-NLS-1$ } } refitModel = new RefitTableModel(refits); }
public UnitStatus(Unit unit) { this.unit = unit; this.name = unit.getName(); chassis = unit.getEntity().getChassis(); model = unit.getEntity().getModel(); //assume its a total loss until we find something that says otherwise totalLoss = true; //create a brand new entity until we find one MechSummary summary = MechSummaryCache.getInstance().getMech(getLookupName()); if(null == summary) { } else { try { entity = unit.getEntity() == null ? new MechFileParser(summary.getSourceFile(), summary.getEntryName()).getEntity() : unit.getEntity(); baseEntity = new MechFileParser(summary.getSourceFile(), summary.getEntryName()).getEntity(); } catch (EntityLoadingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public void resetUnit() { MechSummary mechSummary = MechSummaryCache.getInstance().getMech(unit.getEntity().getShortName()); Entity entity = null; try { entity = (new MechFileParser(mechSummary.getSourceFile(), mechSummary.getEntryName())).getEntity(); } catch (EntityLoadingException ex) { MekHQ.getLogger().error(getClass(), "resetUnit()", ex); //$NON-NLS-1$ } entity.setYear(unit.campaign.getCalendar().get(Calendar.YEAR)); UnitUtil.updateLoadedUnit(entity); removeAll(); labPanel = getCorrectLab(entity); refreshRefitSummary(); add(summaryPane, BorderLayout.LINE_START); add(labPanel, BorderLayout.CENTER); labPanel.refreshAll(); }
private void stockBattleArmorSuits(Campaign c) { //this is just a test for(MechSummary summary : MechSummaryCache.getInstance().getAllMechs()) { if(!summary.getUnitType().equals("BattleArmor")) { continue; } //FIXME: I can't pull entity movement mode and quad shape off of mechsummary //try loading the full entity, but this might take too long if(null != summary) { Entity newEntity = null; try { newEntity = new MechFileParser(summary.getSourceFile(), summary.getEntryName()).getEntity(); } catch (EntityLoadingException e) { e.printStackTrace(); } if(null != newEntity) { BattleArmorSuit ba = new BattleArmorSuit(summary.getChassis(), summary.getModel(), (int)summary.getTons(), 1, summary.getWeightClass(), summary.getWalkMp(), summary.getJumpMp(), newEntity.entityIsQuad(), summary.isClan(), newEntity.getMovementMode(), c); parts.add(ba); } } } }
public void loadUnit(Unit u) { unit = u; MechSummary mechSummary = MechSummaryCache.getInstance().getMech(unit.getEntity().getShortNameRaw()); Entity entity = null; try { entity = (new MechFileParser(mechSummary.getSourceFile(), mechSummary.getEntryName())).getEntity(); } catch (EntityLoadingException ex) { MekHQ.getLogger().error(getClass(), "loadUnit(Unit)", ex); //$NON-NLS-1$ } entity.setYear(unit.campaign.getCalendar().get(Calendar.YEAR)); UnitUtil.updateLoadedUnit(entity); entity.setModel(entity.getModel() + " Mk II"); removeAll(); // We need to override the values in the MML properties file with the campaign options settings. CConfig.setParam(CConfig.TECH_EXTINCT, String.valueOf(campaignGUI.getCampaign().showExtinct())); CConfig.setParam(CConfig.TECH_PROGRESSION, String.valueOf(campaignGUI.getCampaign().useVariableTechLevel())); CConfig.setParam(CConfig.TECH_SHOW_FACTION, String.valueOf(campaignGUI.getCampaign().getTechFaction() >= 0)); CConfig.setParam(CConfig.TECH_UNOFFICAL_NO_YEAR, String.valueOf(campaignGUI.getCampaign().unofficialNoYear())); CConfig.setParam(CConfig.TECH_USE_YEAR, String.valueOf(campaignGUI.getCampaign().getGameYear())); CConfig.setParam(CConfig.TECH_YEAR, String.valueOf(campaignGUI.getCampaign().getGameYear())); labPanel = getCorrectLab(entity); labPanel.setTechFaction(campaignGUI.getCampaign().getTechFaction()); refreshRefitSummary(); add(summaryPane, BorderLayout.LINE_START); add(labPanel, BorderLayout.CENTER); labPanel.refreshAll(); }
private static ITechnology calcTechProgression(MechSummary ms, int techFaction) { final String METHOD_NAME = "calcTechProgression(MechSummary, int)"; // $NON-NLS-1$ try { Entity en = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); if (null == en) { MekHQ.getLogger().log(BuildMapTask.class, METHOD_NAME, LogLevel.ERROR, "Entity was null: " + ms.getName()); } return en.factionTechLevel(techFaction); } catch (EntityLoadingException ex) { MekHQ.getLogger().log(BuildMapTask.class, METHOD_NAME, LogLevel.ERROR, "Exception loading entity " + ms.getName()); MekHQ.getLogger().error(BuildMapTask.class, METHOD_NAME, ex); return null; } }