Skip to content

Python library for accessing regiments of «IL-2 Sturmovik: Forgotten Battles» flight simulator.

License

Notifications You must be signed in to change notification settings

IL2HorusTeam/il2fb-regiments

Repository files navigation

IL-2 FB Regiments

This is a Python library used for accessing information about regiments present in «IL-2 Sturmovik: Forgotten Battles» flight simulator.

Version of PyPI package Supported versions of Python Supported version of IL-2 FB MIT license

unix_build Build status of the master branch on Windows Code quality provided by «Codebeat» Code quality provided by «Codacy» Code quality provided by «Scrutinizer CI»

Data sources

Information about regiments is extracted directly from game's SFS archive named files.sfs.

Data in il2fb/regiments/data directory contains the following files:

Source path in files.sfs Stored as Comments
files.sfs/i18n/regShort.properties regShort_en.properties Added _en suffix
files.sfs/i18n/regShort_ru.properties regShort_ru.properties  
files.sfs/i18n/regInfo.properties regInfo_en.properties Added _en suffix
files.sfs/i18n/regInfo_ru.properties regInfo_ru.properties  
files.sfs/PaintSchemes/regiments.ini regiments.ini  

All data files retain their original encoding, which is CP1251.

Do not edit or resave the data files in this directory manually! Instead, extract them from SFS archive and replace the current ones with them.

Installation

The package is available at PyPI:

pip install il2fb-regiments

Usage

from il2fb.regiments import Regiments

regiments = Regiments()

regiment = regiments.get_by_code_name("USN_VT_9B")

print(regiment.code_name)
# USN_VT_9B

print(regiment.air_force.verbose_name)
# USN

print(regiment.verbose_name)
# VT-9 USS Essex CV-9

print(regiment.help_text)
# US Navy Torpedo Squadron 9 USS Essex CV-9

L10N

Values of human-readable properties (verbose_name, help_text) are sensitive to the current language in use.

The current language is detected via verboselib library.

The set of supported languages is defined by il2fb-commons library.

from verboselib import set_language
from il2fb.regiments import Regiments

regiments = Regiments()

regiment = regiments.get_by_code_name("890DBAP")

print(regiment.verbose_name)
# 890th "Bryansk" AP DD

print(regiment.help_text)
# 890th "Bryansk" AP DD

set_language("ru")

print(regiment.verbose_name)
# 890-й Брянский АП ДД

print(regiment.help_text)
# 890-й Брянский Авиационный Полк Дальнего Действия

Serialization

It's possible to convert Regiment objects into Python's primitives for further serialization.

This can be done via to_primitive() method:

import json

from il2fb.regiments import Regiments

regiments = Regiments()

regiment = regiments.get_by_code_name("USN_VT_9B")

print(json.dumps(regiment.to_primitive(), indent=2))

Outputs:

{
  "air_force": {
    "name": "USN",
    "value": "un",
    "verbose_name": "USN",
    "help_text": "United States Navy",
    "country": {
      "name": "US",
      "verbose_name": "United States",
      "help_text": null
    },
    "default_flight_prefix": "UN_NN"
  },
  "code_name": "USN_VT_9B",
  "verbose_name": "VT-9 USS Essex CV-9",
  "help_text": "US Navy Torpedo Squadron 9 USS Essex CV-9"
}

About

Python library for accessing regiments of «IL-2 Sturmovik: Forgotten Battles» flight simulator.

Resources

License

Stars

Watchers

Forks

Languages