use of games.strategy.engine.data.UnitTypeList in project triplea by triplea-game.
the class ParserTest method testUnitTypesAdded.
@Test
public void testUnitTypesAdded() {
final UnitTypeList units = gameData.getUnitTypeList();
assertEquals(1, units.size());
}
use of games.strategy.engine.data.UnitTypeList in project triplea by triplea-game.
the class OrderOfLossesInputPanel method isValidOrderOfLoss.
/**
* Validates if a given string can be parsed for order of losses.
*/
public static boolean isValidOrderOfLoss(final String orderOfLoss, final GameData data) {
if (orderOfLoss == null || orderOfLoss.trim().length() == 0) {
return true;
}
try {
final String[] sections;
if (orderOfLoss.contains(OOL_SEPARATOR)) {
sections = orderOfLoss.trim().split(OOL_SEPARATOR_REGEX);
} else {
sections = new String[1];
sections[0] = orderOfLoss.trim();
}
final UnitTypeList unitTypes;
try {
data.acquireReadLock();
unitTypes = data.getUnitTypeList();
} finally {
data.releaseReadLock();
}
for (final String section : sections) {
if (section.length() == 0) {
continue;
}
final String[] amountThenType = section.split(OOL_AMOUNT_DESCRIPTOR_REGEX);
if (amountThenType.length != 2) {
return false;
}
if (!amountThenType[0].equals(OOL_ALL)) {
final int amount = Integer.parseInt(amountThenType[0]);
if (amount <= 0) {
return false;
}
}
final UnitType type = unitTypes.getUnitType(amountThenType[1]);
if (type == null) {
return false;
}
}
} catch (final Exception e) {
return false;
}
return true;
}
use of games.strategy.engine.data.UnitTypeList in project triplea by triplea-game.
the class ExtendedStats method fillExtendedStats.
private void fillExtendedStats(final GameData data) {
// add other resources, other than PUs and tech tokens
final List<Resource> resources = data.getResourceList().getResources();
for (final Resource r : resources) {
if (r.getName().equals(Constants.PUS) || r.getName().equals(Constants.TECH_TOKENS)) {
continue;
}
final GenericResourceStat resourceStat = new GenericResourceStat();
resourceStat.init(r.getName());
final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
statsExtended.add(resourceStat);
this.statsExtended = statsExtended.toArray(new IStat[0]);
}
// add tech related stuff
if (Properties.getTechDevelopment(data)) {
// add tech tokens
if (data.getResourceList().getResource(Constants.TECH_TOKENS) != null) {
final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
statsExtended.add(new TechTokenStat());
this.statsExtended = statsExtended.toArray(new IStat[0]);
}
// add number of techs
final List<IStat> techStatsExtended = new ArrayList<>(Arrays.asList(statsExtended));
techStatsExtended.add(new TechCountStat());
statsExtended = techStatsExtended.toArray(new IStat[0]);
// add individual techs
for (final TechAdvance ta : TechAdvance.getTechAdvances(gameData)) {
final GenericTechNameStat techNameStat = new GenericTechNameStat();
techNameStat.init(ta);
final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
statsExtended.add(techNameStat);
this.statsExtended = statsExtended.toArray(new IStat[0]);
}
}
// now add actual number of each unit type (holy gumdrops batman, this is going to be long!)
final UnitTypeList allUnitTypes = data.getUnitTypeList();
for (final UnitType ut : allUnitTypes) {
final GenericUnitNameStat unitNameStat = new GenericUnitNameStat();
unitNameStat.init(ut);
final List<IStat> statsExtended = new ArrayList<>(Arrays.asList(this.statsExtended));
statsExtended.add(unitNameStat);
this.statsExtended = statsExtended.toArray(new IStat[0]);
}
}
Aggregations