Example #1
0
    def test_load_valid_faction_with_invalid_country(self):

        with (RESOURCES_DIR / "invalid_faction_country.json").open("r") as data:
            try:
                Faction.from_json(json.load(data))
                self.fail("Should have thrown assertion error")
            except AssertionError as e:
                pass
Example #2
0
    def test_load_valid_faction(self) -> None:
        with (RESOURCES_DIR / "valid_faction.json").open("r") as data:
            faction = Faction.from_json(json.load(data))

            self.assertEqual(faction.country, "USA")
            self.assertEqual(faction.name, "USA 2005")
            self.assertEqual(faction.authors, "Khopa")
            self.assertEqual(faction.description, "This is a test description")

            self.assertIn(F_15C, faction.aircrafts)
            self.assertIn(F_15E, faction.aircrafts)
            self.assertIn(F_14B, faction.aircrafts)
            self.assertIn(FA_18C_hornet, faction.aircrafts)
            self.assertIn(F_16C_50, faction.aircrafts)
            self.assertIn(A_10A, faction.aircrafts)
            self.assertIn(AV8BNA, faction.aircrafts)
            self.assertIn(UH_1H, faction.aircrafts)
            self.assertIn(AH_64A, faction.aircrafts)
            self.assertIn(B_52H, faction.aircrafts)
            self.assertIn(B_1B, faction.aircrafts)
            self.assertIn(F_117A, faction.aircrafts)
            self.assertIn(A_10C, faction.aircrafts)
            self.assertIn(A_10C_2, faction.aircrafts)

            self.assertEqual(len(faction.awacs), 1)
            self.assertIn(E_3A, faction.awacs)
            self.assertIn(E_2C, faction.awacs)

            self.assertEqual(len(faction.tankers), 2)
            self.assertIn(KC_135, faction.tankers)
            self.assertIn(KC130, faction.tankers)

            self.assertTrue(faction.has_jtac)
            self.assertEqual(faction.jtac_unit, MQ_9_Reaper)

            self.assertIn(Armor.M_1_Abrams, faction.frontline_units)
            self.assertIn(Armor.M1134_Stryker_ATGM, faction.frontline_units)
            self.assertIn(Armor.M1126_Stryker_ICV, faction.frontline_units)
            self.assertIn(Armor.M_2_Bradley, faction.frontline_units)
            self.assertIn(Armor.LAV_25, faction.frontline_units)
            self.assertIn(Armor.M1043_HMMWV_Armament, faction.frontline_units)
            self.assertIn(Armor.M1045_HMMWV_TOW, faction.frontline_units)

            self.assertIn(Artillery.MLRS, faction.artillery_units)
            self.assertIn(Artillery.M_109, faction.artillery_units)

            self.assertIn(Unarmed.M_818, faction.logistics_units)

            self.assertIn(Infantry.Soldier_M4, faction.infantry_units)
            self.assertIn(Infantry.Soldier_M249, faction.infantry_units)

            self.assertIn(Stennis.name, faction.naval_units)
            self.assertIn(LHA_Tarawa.name, faction.naval_units)

            self.assertIn("mod", faction.requirements.keys())
            self.assertIn("Some mod is required",
                          faction.requirements.values())

            self.assertEqual(4, len(faction.carrier_names))
            self.assertEqual(5, len(faction.helicopter_carrier_names))
    def load_factions(cls: Type[FactionLoader]) -> Dict[str, Faction]:
        files = [f for f in FACTION_DIRECTORY.glob("*.json") if f.is_file()]
        factions = {}

        for f in files:
            try:
                with f.open("r", encoding="utf-8") as fdata:
                    data = json.load(fdata, encoding="utf-8")
                    factions[data["name"]] = Faction.from_json(data)
                    logging.info("Loaded faction : " + str(f))
            except Exception:
                logging.exception(f"Unable to load faction : {f}")

        return factions
Example #4
0
    def possible_types_for_faction(self, faction: Faction) -> list[Type[DcsUnitType]]:
        """Determine the possible dcs unit types for the TgoLayoutGroup and the given faction"""
        unit_types = [t for t in self.unit_types if faction.has_access_to_dcs_type(t)]

        alternative_types = []
        for accessible_unit in faction.accessible_units:
            if accessible_unit.unit_class in self.unit_classes:
                unit_types.append(accessible_unit.dcs_unit_type)
            if accessible_unit.unit_class in self.fallback_classes:
                alternative_types.append(accessible_unit.dcs_unit_type)

        if not unit_types and not alternative_types and not self.optional:
            raise LayoutException(f"{self.name} not usable by faction {faction.name}")

        return unit_types or alternative_types
    def load_factions(cls: Type[FactionLoader]) -> Dict[str, Faction]:
        user_faction_path = Path(
            persistency.base_path()) / "Liberation/Factions"
        files = cls.find_faction_files_in(
            FACTION_DIRECTORY) + cls.find_faction_files_in(user_faction_path)
        factions = {}

        for f in files:
            try:
                with f.open("r", encoding="utf-8") as fdata:
                    data = json.load(fdata)
                    factions[data["name"]] = Faction.from_json(data)
                    logging.info("Loaded faction : " + str(f))
            except Exception:
                logging.exception(f"Unable to load faction : {f}")

        return factions
Example #6
0
    def test_load_valid_faction(self):
        with (RESOURCES_DIR / "valid_faction.json").open("r") as data:
            faction = Faction.from_json(json.load(data))

            self.assertEqual(faction.country, "USA")
            self.assertEqual(faction.name, "USA 2005")
            self.assertEqual(faction.authors, "Khopa")
            self.assertEqual(faction.description, "This is a test description")

            self.assertIn(F_15C, faction.aircrafts)
            self.assertIn(F_15E, faction.aircrafts)
            self.assertIn(F_14B, faction.aircrafts)
            self.assertIn(FA_18C_hornet, faction.aircrafts)
            self.assertIn(F_16C_50, faction.aircrafts)
            self.assertIn(A_10A, faction.aircrafts)
            self.assertIn(AV8BNA, faction.aircrafts)
            self.assertIn(UH_1H, faction.aircrafts)
            self.assertIn(AH_64A, faction.aircrafts)
            self.assertIn(B_52H, faction.aircrafts)
            self.assertIn(B_1B, faction.aircrafts)
            self.assertIn(F_117A, faction.aircrafts)
            self.assertIn(A_10C, faction.aircrafts)
            self.assertIn(A_10C_2, faction.aircrafts)

            self.assertEqual(len(faction.awacs), 1)
            self.assertIn(E_3A, faction.awacs)

            self.assertEqual(len(faction.tankers), 2)
            self.assertIn(KC_135, faction.tankers)
            self.assertIn(KC130, faction.tankers)

            self.assertTrue(faction.has_jtac)
            self.assertEqual(faction.jtac_unit, MQ_9_Reaper)

            self.assertIn(Armor.MBT_M1A2_Abrams, faction.frontline_units)
            self.assertIn(Armor.ATGM_M1134_Stryker, faction.frontline_units)
            self.assertIn(Armor.APC_M1126_Stryker_ICV, faction.frontline_units)
            self.assertIn(Armor.IFV_M2A2_Bradley, faction.frontline_units)
            self.assertIn(Armor.IFV_LAV_25, faction.frontline_units)
            self.assertIn(Armor.APC_M1043_HMMWV_Armament,
                          faction.frontline_units)
            self.assertIn(Armor.ATGM_M1045_HMMWV_TOW, faction.frontline_units)

            self.assertIn(Artillery.MLRS_M270, faction.artillery_units)
            self.assertIn(Artillery.SPH_M109_Paladin, faction.artillery_units)

            self.assertIn(Unarmed.Transport_M818, faction.logistics_units)

            self.assertIn(Infantry.Infantry_M4, faction.infantry_units)
            self.assertIn(Infantry.Soldier_M249, faction.infantry_units)

            self.assertIn("AvengerGenerator", faction.air_defenses)

            self.assertIn("HawkGenerator", faction.air_defenses)

            self.assertIn(CVN_74_John_C__Stennis, faction.aircraft_carrier)
            self.assertIn(LHA_1_Tarawa, faction.helicopter_carrier)
            self.assertIn(Oliver_Hazzard_Perry_class, faction.destroyers)
            self.assertIn(USS_Arleigh_Burke_IIa, faction.destroyers)
            self.assertIn(Ticonderoga_class, faction.cruisers)

            self.assertIn("mod", faction.requirements.keys())
            self.assertIn("Some mod is required",
                          faction.requirements.values())

            self.assertEqual(4, len(faction.carrier_names))
            self.assertEqual(5, len(faction.helicopter_carrier_names))

            self.assertIn("OliverHazardPerryGroupGenerator",
                          faction.navy_generators)
            self.assertIn("ArleighBurkeGroupGenerator",
                          faction.navy_generators)