summaryrefslogtreecommitdiff
path: root/py_modules/lsfg_vk/config_schema.py
diff options
context:
space:
mode:
Diffstat (limited to 'py_modules/lsfg_vk/config_schema.py')
-rw-r--r--py_modules/lsfg_vk/config_schema.py118
1 files changed, 30 insertions, 88 deletions
diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py
index c82d1d3..bbace42 100644
--- a/py_modules/lsfg_vk/config_schema.py
+++ b/py_modules/lsfg_vk/config_schema.py
@@ -19,6 +19,9 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from shared_config import CONFIG_SCHEMA_DEF, ConfigFieldType, get_field_names, get_defaults, get_field_types
+# Import auto-generated configuration components
+from .config_schema_generated import ConfigurationData, get_script_parsing_logic, get_script_generation_logic
+
@dataclass
class ConfigField:
@@ -52,45 +55,27 @@ CONFIG_SCHEMA["dll"] = ConfigField(
description="specify where Lossless.dll is stored"
)
-# Fields that should ONLY be in the lsfg script, not in TOML config
+# Get script-only fields dynamically from shared config
SCRIPT_ONLY_FIELDS = {
- "dxvk_frame_rate": ConfigField(
- name="dxvk_frame_rate",
- field_type=ConfigFieldType.INTEGER,
- default=0,
- description="base framerate cap for DirectX games, before frame multiplier (0 = disabled, requires game re-launch)"
- ),
-
- "enable_wow64": ConfigField(
- name="enable_wow64",
- field_type=ConfigFieldType.BOOLEAN,
- default=False,
- description="enable PROTON_USE_WOW64=1 for 32-bit games (use with ProtonGE to fix crashing)"
- ),
-
- "disable_steamdeck_mode": ConfigField(
- name="disable_steamdeck_mode",
- field_type=ConfigFieldType.BOOLEAN,
- default=False,
- description="disable Steam Deck mode (unlocks hidden settings in some games)"
+ field_name: ConfigField(
+ name=field_def["name"],
+ field_type=ConfigFieldType(field_def["fieldType"]),
+ default=field_def["default"],
+ description=field_def["description"]
)
+ for field_name, field_def in CONFIG_SCHEMA_DEF.items()
+ if field_def.get("location") == "script"
}
# Complete configuration schema (TOML + script-only fields)
COMPLETE_CONFIG_SCHEMA = {**CONFIG_SCHEMA, **SCRIPT_ONLY_FIELDS}
-class ConfigurationData(TypedDict):
- """Type-safe configuration data structure"""
- dll: str
- multiplier: int
- flow_scale: float
- performance_mode: bool
- hdr_mode: bool
- experimental_present_mode: str
- dxvk_frame_rate: int
- enable_wow64: bool
- disable_steamdeck_mode: bool
+# Import auto-generated configuration components
+from .config_schema_generated import ConfigurationData, get_script_parsing_logic, get_script_generation_logic
+
+# Note: ConfigurationData is now imported from generated file
+# No need to manually maintain the TypedDict anymore!
class ConfigurationManager:
@@ -186,7 +171,9 @@ class ConfigurationManager:
if config.get("dll"):
lines.append("[global]")
lines.append(f"# specify where Lossless.dll is stored")
- lines.append(f'dll = "{config["dll"]}"')
+ # Generate TOML lines for TOML fields only - USE GENERATED CONSTANTS
+ from .config_schema_generated import DLL
+ lines.append(f'dll = "{config[DLL]}"')
lines.append("")
# Add game section with process name for LSFG_PROCESS approach
@@ -263,9 +250,10 @@ class ConfigurationManager:
elif value.startswith("'") and value.endswith("'"):
value = value[1:-1]
- # Handle global section (dll only)
+ # Handle global section (dll only) - USE GENERATED CONSTANTS
if in_global_section and key == "dll":
- config["dll"] = value
+ from .config_schema_generated import DLL
+ config[DLL] = value
# Handle game section
elif in_game_section:
@@ -305,42 +293,9 @@ class ConfigurationManager:
Returns:
Dict containing parsed script-only field values
"""
- script_values = {}
-
- try:
- lines = script_content.split('\n')
-
- for line in lines:
- line = line.strip()
-
- # Skip comments, empty lines, and non-export lines
- if not line or line.startswith('#') or not line.startswith('export '):
- continue
-
- # Parse export statements: export VAR=value
- if '=' in line:
- # Remove 'export ' prefix
- export_line = line[len('export '):]
- key, value = export_line.split('=', 1)
- key = key.strip()
- value = value.strip()
-
- # Map environment variables to config field names
- if key == "DXVK_FRAME_RATE":
- try:
- script_values["dxvk_frame_rate"] = int(value)
- except ValueError:
- pass
- elif key == "PROTON_USE_WOW64":
- script_values["enable_wow64"] = value == "1"
- elif key == "SteamDeck":
- script_values["disable_steamdeck_mode"] = value == "0"
-
- except (ValueError, KeyError, IndexError) as e:
- # If parsing fails, log the error and return empty dict (will use defaults)
- print(f"Error parsing script content: {e}")
-
- return script_values
+ # Use auto-generated parsing logic
+ parse_script_values = get_script_parsing_logic()
+ return parse_script_values(script_content.split('\n'))
@staticmethod
def merge_config_with_script(toml_config: ConfigurationData, script_values: Dict[str, Union[bool, int, str]]) -> ConfigurationData:
@@ -363,21 +318,8 @@ class ConfigurationManager:
return cast(ConfigurationData, merged_config)
@staticmethod
- def create_config_from_args(dll: str, multiplier: int, flow_scale: float,
- performance_mode: bool, hdr_mode: bool,
- experimental_present_mode: str = "fifo",
- dxvk_frame_rate: int = 0,
- enable_wow64: bool = False,
- disable_steamdeck_mode: bool = False) -> ConfigurationData:
- """Create configuration from individual arguments"""
- return cast(ConfigurationData, {
- "dll": dll,
- "multiplier": multiplier,
- "flow_scale": flow_scale,
- "performance_mode": performance_mode,
- "hdr_mode": hdr_mode,
- "experimental_present_mode": experimental_present_mode,
- "dxvk_frame_rate": dxvk_frame_rate,
- "enable_wow64": enable_wow64,
- "disable_steamdeck_mode": disable_steamdeck_mode
- })
+ @staticmethod
+ def create_config_from_args(**kwargs) -> ConfigurationData:
+ """Create configuration from keyword arguments - USES GENERATED CODE"""
+ from .config_schema_generated import create_config_dict
+ return create_config_dict(**kwargs)