Move faction cache out of db.py.

This commit is contained in:
Dan Albert 2022-02-18 17:58:34 -08:00
parent 36f74ae0a9
commit b4742ad54c
8 changed files with 31 additions and 31 deletions

View File

@ -27,7 +27,6 @@ from dcs.vehicles import (
)
# PATCH pydcs data with MODS
from game.factions.faction_loader import FactionLoader
"""
---------- BEGINNING OF CONFIGURATION SECTION
@ -55,12 +54,6 @@ For example, player accessible Hornet is called `FA_18C_hornet`, and MANPAD Igla
# to be cheap enough to repair with a single turn's income.
RUNWAY_REPAIR_COST = 100
"""
Units separated by country.
country : DCS Country name
"""
FACTIONS = FactionLoader()
"""
Possible time periods for new games

View File

@ -0,0 +1,4 @@
from .faction import Faction
from .faction_loader import FactionLoader
FACTIONS = FactionLoader()

View File

@ -4,7 +4,8 @@ from typing import Optional
from dcs.unitgroup import VehicleGroup
from game import db, Game
from game import Game
from game.factions import FACTIONS
from game.theater.theatergroundobject import CoastalSiteGroundObject
from gen.coastal.silkworm import SilkwormGenerator
@ -21,7 +22,7 @@ def generate_coastal_group(
:return: The generated group, or None if this faction does not support coastal
defenses.
"""
faction = db.FACTIONS[faction_name]
faction = FACTIONS[faction_name]
if len(faction.coastal_defenses) > 0:
generators = faction.coastal_defenses
if len(generators) > 0:

View File

@ -3,9 +3,10 @@ from typing import Optional
from dcs.unitgroup import VehicleGroup
from game import db, Game
from game import Game
from game.data.groundunitclass import GroundUnitClass
from game.dcs.groundunittype import GroundUnitType
from game.factions import FACTIONS
from game.theater.theatergroundobject import VehicleGroupGroundObject
from gen.defenses.armored_group_generator import (
ArmoredGroupGenerator,
@ -27,7 +28,7 @@ def generate_armor_group(
GroundUnitClass.Tank,
)
possible_unit = [
u for u in db.FACTIONS[faction].frontline_units if u.unit_class in armor_types
u for u in FACTIONS[faction].frontline_units if u.unit_class in armor_types
]
if len(possible_unit) > 0:
unit_type = random.choice(possible_unit)

View File

@ -2,14 +2,14 @@ from __future__ import annotations
import logging
import random
from typing import TYPE_CHECKING, Optional
from typing import Optional, TYPE_CHECKING
from dcs.unitgroup import ShipGroup
from game import db
from game.factions import FACTIONS
from game.theater.theatergroundobject import (
LhaGroundObject,
CarrierGroundObject,
LhaGroundObject,
ShipGroundObject,
)
from gen.fleet.carrier_group import CarrierGroupGenerator
@ -21,10 +21,10 @@ from gen.fleet.dd_group import (
from gen.fleet.lacombattanteII import LaCombattanteIIGroupGenerator
from gen.fleet.lha_group import LHAGroupGenerator
from gen.fleet.ru_dd_group import (
RussianNavyGroupGenerator,
GrishaGroupGenerator,
MolniyaGroupGenerator,
KiloSubGroupGenerator,
MolniyaGroupGenerator,
RussianNavyGroupGenerator,
TangoSubGroupGenerator,
)
from gen.fleet.schnellboot import SchnellbootGroupGenerator
@ -59,7 +59,7 @@ def generate_ship_group(
This generate a ship group
:return: The generated group, or None if this faction does not support ships.
"""
faction = db.FACTIONS[faction_name]
faction = FACTIONS[faction_name]
if len(faction.navy_generators) > 0:
gen = random.choice(faction.navy_generators)
if gen in SHIP_MAP.keys():
@ -86,7 +86,7 @@ def generate_carrier_group(
:param ground_object: The ground object which will own the ship group
:return: The generated group.
"""
generator = CarrierGroupGenerator(game, ground_object, db.FACTIONS[faction])
generator = CarrierGroupGenerator(game, ground_object, FACTIONS[faction])
generator.generate()
return generator.get_generated_group()
@ -101,6 +101,6 @@ def generate_lha_group(
:param ground_object: The ground object which will own the ship group
:return: The generated group.
"""
generator = LHAGroupGenerator(game, ground_object, db.FACTIONS[faction])
generator = LHAGroupGenerator(game, ground_object, FACTIONS[faction])
generator.generate()
return generator.get_generated_group()

View File

@ -4,7 +4,8 @@ from typing import Optional
from dcs.unitgroup import VehicleGroup
from game import db, Game
from game import Game
from game.factions import FACTIONS
from game.theater.theatergroundobject import MissileSiteGroundObject
from gen.missiles.scud_site import ScudGenerator
from gen.missiles.v1_group import V1GroupGenerator
@ -19,7 +20,7 @@ def generate_missile_group(
This generate a missiles group
:return: Nothing, but put the group reference inside the ground object
"""
faction = db.FACTIONS[faction_name]
faction = FACTIONS[faction_name]
if len(faction.missiles) > 0:
generators = faction.missiles
if len(generators) > 0:

View File

@ -15,8 +15,8 @@ from dcs.payloads import PayloadDirectories
from game import Game, VERSION, persistency
from game.campaignloader.campaign import Campaign
from game.data.weapons import Pylon, Weapon, WeaponGroup
from game.db import FACTIONS
from game.dcs.aircrafttype import AircraftType
from game.factions import FACTIONS
from game.profiling import logged_duration
from game.server import EventStream, GameContext, Server
from game.settings import Settings

View File

@ -11,7 +11,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
from game import db
from game.campaignloader.campaign import Campaign
from game.factions.faction import Faction
from game.factions import FACTIONS, Faction
from game.settings import Settings
from game.theater.start_generator import GameGenerator, GeneratorSettings, ModSettings
from qt_ui.widgets.QLiberationCalendar import QLiberationCalendar
@ -179,7 +179,7 @@ class FactionSelection(QtWidgets.QWizardPage):
blueFaction = QtWidgets.QLabel("<b>Player Faction :</b>")
self.blueFactionSelect = QtWidgets.QComboBox()
for f in db.FACTIONS:
for f in FACTIONS:
self.blueFactionSelect.addItem(f)
blueFaction.setBuddy(self.blueFactionSelect)
@ -195,7 +195,7 @@ class FactionSelection(QtWidgets.QWizardPage):
self.redFactionDescription.setReadOnly(True)
# Setup default selected factions
for i, r in enumerate(db.FACTIONS):
for i, r in enumerate(FACTIONS):
self.redFactionSelect.addItem(r)
if r == "Russia 1990":
self.redFactionSelect.setCurrentIndex(i)
@ -241,10 +241,10 @@ class FactionSelection(QtWidgets.QWizardPage):
self.blueFactionSelect.clear()
self.redFactionSelect.clear()
for f in db.FACTIONS:
for f in FACTIONS:
self.blueFactionSelect.addItem(f)
for i, r in enumerate(db.FACTIONS):
for i, r in enumerate(FACTIONS):
self.redFactionSelect.addItem(r)
if r == campaign.recommended_enemy_faction:
self.redFactionSelect.setCurrentIndex(i)
@ -255,8 +255,8 @@ class FactionSelection(QtWidgets.QWizardPage):
def updateUnitRecap(self):
red_faction = db.FACTIONS[self.redFactionSelect.currentText()]
blue_faction = db.FACTIONS[self.blueFactionSelect.currentText()]
red_faction = FACTIONS[self.redFactionSelect.currentText()]
blue_faction = FACTIONS[self.blueFactionSelect.currentText()]
template = jinja_env.get_template("factiontemplate_EN.j2")
@ -268,11 +268,11 @@ class FactionSelection(QtWidgets.QWizardPage):
@property
def selected_blue_faction(self) -> Faction:
return db.FACTIONS[self.blueFactionSelect.currentText()]
return FACTIONS[self.blueFactionSelect.currentText()]
@property
def selected_red_faction(self) -> Faction:
return db.FACTIONS[self.redFactionSelect.currentText()]
return FACTIONS[self.redFactionSelect.currentText()]
class TheaterConfiguration(QtWidgets.QWizardPage):