Files
EscapistsReintroduced/tools/project_schema.py
T

35 lines
1.4 KiB
Python

"""Strict reviewed addon project grammar shared by source and packed validation.
The optional Core configuration adds owned menu and observer-input resources.
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*
(?:InputManagerSettings\s+InputManagerSettings\s+"\{50A48858902D5F64\}"\s*\{\s*
Default\s+"\{A7B19F416E541000\}Configs/ERR/ObserverInput\.conf"\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)