Adds prettier user-facing aircraft names. (#726)

This makes the names of the aircraft displayed to the player in the UI more verbose and readable.

It allows allows specific countries to display an aircraft's name differently. An example of this would be the JF-17 Thunder, which is known in China as the FC-1 Fierce Dragon - this now displays correctly in the Liberation UI.
This commit is contained in:
Simon Clark
2021-01-05 21:21:38 +00:00
committed by GitHub
parent c3401d478b
commit c740c8304b
12 changed files with 331 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
from datetime import datetime
from enum import Enum
from typing import Dict, List, Optional, Tuple, Type, Union
import json
from pathlib import Path
from dcs.countries import country_dict
from dcs.helicopters import (
@@ -169,6 +171,8 @@ from pydcs_extensions.mb339.mb339 import MB_339PAN
from pydcs_extensions.rafale.rafale import Rafale_A_S, Rafale_M, Rafale_B
from pydcs_extensions.su57.su57 import Su_57
PRETTYNAMES_PATH = Path("./resources/units/pretty_unit_names.json")
plane_map["A-4E-C"] = A_4E_C
plane_map["MB-339PAN"] = MB_339PAN
plane_map["Rafale_M"] = Rafale_M
@@ -1321,6 +1325,25 @@ def unit_type_name(unit_type) -> str:
def unit_type_name_2(unit_type) -> str:
return unit_type.name and unit_type.name or unit_type.id
def unit_pretty_name(country_name: str, unit_type) -> str:
original_name = unit_type.name and unit_type.name or unit_type.id
default_name = None
faction_name = None
with PRETTYNAMES_PATH.open("r", encoding="utf-8") as fdata:
data = json.load(fdata, encoding="utf-8")
type_exists = data.get(original_name)
if type_exists is None:
return original_name
for faction in type_exists:
if default_name is None:
default_name = faction.get("default")
if faction_name is None:
faction_name = faction.get(country_name)
if default_name is None:
return original_name
if faction_name is None:
return default_name
return faction_name
def unit_type_from_name(name: str) -> Optional[Type[UnitType]]:
if name in vehicle_map: