Skip to main content

Parser for .darkest file

Project description

darkest-parser

darkest-parser is a module to parser .darkest file originally from Darkest Dungeon programatically.

Usage

pip install darkest-parser
from darkest_parser import parse, unparse

text = '''
resistances: .stun 40% .poison 40% .bleed 40% .disease 30% .move 40% .debuff 30% .death_blow 67% .trap 40%
weapon: .name "houndmaster_weapon_0" .atk 0% .dmg 4 7 .crit 4% .spd 5
armour: .name "houndmaster_armour_0" .def 10% .prot 0 .hp 21 .spd 0
combat_skill: .id "hounds_rush" .level 0 .type "ranged" .atk 85% .dmg 0% .crit 5% .launch 432 .target 1234 .effect "Beast Killer 1"
combat_skill: .id "hounds_rush" .level 1 .type "ranged" .atk 90% .dmg 0% .crit 6% .launch 432 .target 1234 .effect "Beast Killer 2"
'''

dark = parse(text)

dark[0].tag == 'resistances'
dark[0].set('stun', '60%')
dark[0].poison = '40%'


weapon0 = dark.find('weapon', name='houndmaster_weapon_0')
weapon0.tag == 'weapon'
weapon0.dmg = [14, 17]
weapon0.spd = 25

for rush in dark.finditer('combat_skill', id='hounds_rush'):
    rush.type = 'meele'
    rush.set('ignore_guarded')

rush0 = dark.find(id='hounds_rush', level=0)
# x invalid:
# rush0.effect.append('Human Killer 1')
# √ use instead:
rush0.effect = [*rush0.effect, 'Human Killer 1']

rush1 = dark.find(id='hounds_rush', level=1)
rush1.has('target') == True
rush1.set('target', '~1234', 'literal')
# literal means that the value is unquoted, it's useful in some case,
# for example: launch, target, valid_modes, etc.

print(unparse(dark))

API Reference

def parse(str) -> Darkest:
    ...
def unparse(Darkest) -> str:
    ...

class Darkest:
    def __getitem__(int) -> Element:
        ...
    def finditer(str | None, **{str: Any}) -> Generator[Element, Any, Any]:
        ...
    def findall(str | None, **{str: Any}) -> List[Element]:
        ...
    def find(str | None, **{str: Any}) -> Element:
        ...

class Element:
    def get(str) -> List[Any]:
        ...
    def set(str, Any | List[Any] | None, Literal['number', 'bool', 'string', 'literal'] | None):
        ...
    def pop(str):
        ...
    def has(str) -> bool:
        ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

darkest_parser-1.1.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

darkest_parser-1.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file darkest_parser-1.1.1.tar.gz.

File metadata

  • Download URL: darkest_parser-1.1.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.12.0 Windows/10

File hashes

Hashes for darkest_parser-1.1.1.tar.gz
Algorithm Hash digest
SHA256 879865922565d8984e9b2fbc73602eebe270b0c9fbd6cd909333cc1f189c8e4c
MD5 35f405493482ca2f051825073cbd7cd0
BLAKE2b-256 29c960645cb48e7bc62e0ec8774e638f65c04dca40b9bbed54e054532f711fa3

See more details on using hashes here.

File details

Details for the file darkest_parser-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: darkest_parser-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.12.0 Windows/10

File hashes

Hashes for darkest_parser-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 364f73590370a88ddb331574580e60a3b58d9d6c7a72ce2102a343f302ababe8
MD5 468124942b8bf0c001d88673891a47e2
BLAKE2b-256 cff0210280696097b1f7e986bf9e37a05fd26ff2e45f2603dd9d2d09a75ea28f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page