Files
EscapistsReintroduced/tools/project_schema.py
T

33 lines
1.2 KiB
Python

"""Strict reviewed addon project grammar shared by source and packed validation.
The optional Core menu configuration preserves vanilla and adds one owned resource.
This is deliberately not a general Enfusion project parser: unreviewed settings,
other platforms, resource substitutions and omissions from the exact list fail.
Identity and exact dependency closure remain the caller's responsibility.
"""
import re
CORE_MENU_CONFIGURATION = r"""
Configurations\s*\{\s*
GameProjectConfig\s+PC\s*\{\s*
MenuManagerSettings\s+MenuManagerSettings\s+"\{50C890C996B0A6FC\}"\s*\{\s*
MenuConfigs\s*\{\s*
"\{C747AFB6B750CE9A\}Configs/System/chimeraMenus\.conf"\s*
"\{B48C7FA12692DE03\}Configs/ERR/AdminMenus\.conf"\s*
\}\s*\}\s*\}\s*\}
"""
def parse_project(text, *, allow_core_menu=False):
"""Return identity/GUID/title/dependency captures, or None for unreviewed syntax."""
extension = ''
if allow_core_menu:
extension = '(?:' + CORE_MENU_CONFIGURATION + r'\s*)?'
return re.fullmatch(
r'\s*GameProject\s*\{\s*'
r'ID\s+"([^"\r\n]+)"\s*'
r'GUID\s+"([A-F0-9]{16})"\s*'
r'TITLE\s+"([^"\r\n]+)"\s*'
r'Dependencies\s*\{((?:\s*"[A-F0-9]{16}"\s*)+)\}\s*'
+ extension + r'\}\s*', text, re.VERBOSE)