summaryrefslogtreecommitdiff
path: root/py_modules
diff options
context:
space:
mode:
authorxXJSONDeruloXx <danielhimebauch@gmail.com>2025-07-22 13:06:46 -0400
committerxXJSONDeruloXx <danielhimebauch@gmail.com>2025-07-22 13:06:46 -0400
commitdf0635f1bba611b8b44975057acd579102d209dd (patch)
tree79a3ae004d5de136a5b5647e87f325d62561f9de /py_modules
parentf8c09209513507ad9af7822c32119cf6d6fae0ac (diff)
downloaddecky-lsfg-vk-df0635f1bba611b8b44975057acd579102d209dd.tar.gz
decky-lsfg-vk-df0635f1bba611b8b44975057acd579102d209dd.zip
further automate population of hardcoded fields
Diffstat (limited to 'py_modules')
-rw-r--r--py_modules/lsfg_vk/config_schema.py64
-rw-r--r--py_modules/lsfg_vk/config_schema_generated.py118
-rw-r--r--py_modules/lsfg_vk/configuration.py44
-rw-r--r--py_modules/lsfg_vk/configuration_helpers_generated.py22
4 files changed, 164 insertions, 84 deletions
diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py
index 6728106..a7827ae 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:
@@ -68,19 +71,11 @@ 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
- mangohud_workaround: bool
- disable_vkbasalt: 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:
@@ -295,46 +290,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"
- elif key == "MANGOHUD":
- script_values["mangohud_workaround"] = value == "1"
- elif key == "DISABLE_VKBASALT":
- script_values["disable_vkbasalt"] = value == "1"
-
- 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:
diff --git a/py_modules/lsfg_vk/config_schema_generated.py b/py_modules/lsfg_vk/config_schema_generated.py
new file mode 100644
index 0000000..46bc58f
--- /dev/null
+++ b/py_modules/lsfg_vk/config_schema_generated.py
@@ -0,0 +1,118 @@
+"""
+Auto-generated configuration schema components from shared_config.py
+DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build
+"""
+
+from typing import TypedDict, Dict, Any, Union, cast
+from enum import Enum
+import sys
+from pathlib import Path
+
+# Import shared configuration constants
+sys.path.insert(0, str(Path(__file__).parent.parent.parent))
+from shared_config import CONFIG_SCHEMA_DEF, ConfigFieldType
+
+
+class ConfigurationData(TypedDict):
+ """Type-safe configuration data structure - AUTO-GENERATED"""
+ 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
+ mangohud_workaround: bool
+ disable_vkbasalt: bool
+
+
+def get_script_parsing_logic():
+ """Return the script parsing logic as a callable"""
+ def parse_script_values(lines):
+ script_values = {}
+ for line in lines:
+ line = line.strip()
+ if not line or line.startswith("#") or not line.startswith("export "):
+ continue
+ if "=" in line:
+ export_line = line[len("export "):]
+ key, value = export_line.split("=", 1)
+ key = key.strip()
+ value = value.strip()
+
+ # Auto-generated parsing logic:
+ if key == "DXVK_FRAME_RATE":
+ try:
+ script_values["dxvk_frame_rate"] = int(value)
+ except ValueError:
+ pass
+ if key == "PROTON_USE_WOW64":
+ script_values["enable_wow64"] = value == "1"
+ if key == "SteamDeck":
+ script_values["disable_steamdeck_mode"] = value == "0"
+ if key == "MANGOHUD":
+ script_values["mangohud_workaround"] = value == "1"
+ if key == "DISABLE_VKBASALT":
+ script_values["disable_vkbasalt"] = value == "1"
+
+ return script_values
+ return parse_script_values
+
+
+def get_script_generation_logic():
+ """Return the script generation logic as a callable"""
+ def generate_script_lines(config):
+ lines = []
+ dxvk_frame_rate = config.get("dxvk_frame_rate", 0)
+ if dxvk_frame_rate > 0:
+ lines.append(f"export DXVK_FRAME_RATE={dxvk_frame_rate}")
+ if config.get("enable_wow64", False):
+ lines.append("export PROTON_USE_WOW64=1")
+ if config.get("disable_steamdeck_mode", False):
+ lines.append("export SteamDeck=0")
+ if config.get("mangohud_workaround", False):
+ lines.append("export MANGOHUD=1")
+ if config.get("disable_vkbasalt", False):
+ lines.append("export DISABLE_VKBASALT=1")
+ return lines
+ return generate_script_lines
+
+
+def get_function_parameters() -> str:
+ """Return function signature parameters"""
+ return """dll: str = "/games/Lossless Scaling/Lossless.dll",
+ multiplier: int = 1,
+ flow_scale: float = 0.8,
+ performance_mode: bool = True,
+ hdr_mode: bool = False,
+ experimental_present_mode: str = "fifo",
+ dxvk_frame_rate: int = 0,
+ enable_wow64: bool = False,
+ disable_steamdeck_mode: bool = False,
+ mangohud_workaround: bool = False,
+ disable_vkbasalt: bool = False"""
+
+
+def create_config_dict(**kwargs) -> ConfigurationData:
+ """Create configuration dictionary from keyword 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,
+ "mangohud_workaround": mangohud_workaround,
+ "disable_vkbasalt": disable_vkbasalt,
+ })
+
+
+# Field lists for dynamic operations
+TOML_FIELDS = ['dll', 'multiplier', 'flow_scale', 'performance_mode', 'hdr_mode', 'experimental_present_mode']
+SCRIPT_FIELDS = ['dxvk_frame_rate', 'enable_wow64', 'disable_steamdeck_mode', 'mangohud_workaround', 'disable_vkbasalt']
+ALL_FIELDS = ['dll', 'multiplier', 'flow_scale', 'performance_mode', 'hdr_mode', 'experimental_present_mode', 'dxvk_frame_rate', 'enable_wow64', 'disable_steamdeck_mode', 'mangohud_workaround', 'disable_vkbasalt']
diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py
index 49653ea..e745e29 100644
--- a/py_modules/lsfg_vk/configuration.py
+++ b/py_modules/lsfg_vk/configuration.py
@@ -6,7 +6,9 @@ from pathlib import Path
from typing import Dict, Any
from .base_service import BaseService
-from .config_schema import ConfigurationManager, ConfigurationData, CONFIG_SCHEMA
+from .config_schema import ConfigurationManager, CONFIG_SCHEMA
+from .config_schema_generated import ConfigurationData, get_script_generation_logic
+from .configuration_helpers_generated import log_configuration_update
from .types import ConfigurationResponse
@@ -149,13 +151,8 @@ class ConfigurationService(BaseService):
if not script_result["success"]:
self.log.warning(f"Failed to update launch script: {script_result['error']}")
- self.log.info(f"Updated lsfg TOML configuration: "
- f"dll='{dll}', multiplier={multiplier}, flow_scale={flow_scale}, "
- f"performance_mode={performance_mode}, hdr_mode={hdr_mode}, "
- f"experimental_present_mode='{experimental_present_mode}', "
- f"dxvk_frame_rate={dxvk_frame_rate}, "
- f"enable_wow64={enable_wow64}, disable_steamdeck_mode={disable_steamdeck_mode}, "
- f"mangohud_workaround={mangohud_workaround}, disable_vkbasalt={disable_vkbasalt}")
+ # Use auto-generated logging
+ log_configuration_update(self.log, config)
return self._success_response(ConfigurationResponse,
"lsfg configuration updated successfully",
@@ -254,29 +251,14 @@ class ConfigurationService(BaseService):
"# This script sets up the environment for lsfg-vk to work with the plugin configuration"
]
- # Add optional export statements based on configuration
- if config.get("enable_wow64", False):
- lines.append("export PROTON_USE_WOW64=1")
+ # Use auto-generated script generation logic
+ generate_script_lines = get_script_generation_logic()
+ lines.extend(generate_script_lines(config))
- if config.get("disable_steamdeck_mode", False):
- lines.append("export SteamDeck=0")
-
- if config.get("mangohud_workaround", False):
- lines.append("export MANGOHUD=1")
- lines.append("export MANGOHUD_CONFIG=alpha=0.001,background_alpha=0.001")
-
- if config.get("disable_vkbasalt", False):
- lines.append("export DISABLE_VKBASALT=1")
-
- # Add DXVK_FRAME_RATE if dxvk_frame_rate is set
- dxvk_frame_rate = config.get("dxvk_frame_rate", 0)
- if dxvk_frame_rate > 0:
- lines.append(f"export DXVK_FRAME_RATE={dxvk_frame_rate}")
-
- # Always add the LSFG_PROCESS export
- lines.append("export LSFG_PROCESS=decky-lsfg-vk")
-
- # Add the execution line
- lines.append('exec "$@"')
+ # Always add the LSFG_PROCESS export and execution line
+ lines.extend([
+ "export LSFG_PROCESS=decky-lsfg-vk",
+ 'exec "$@"'
+ ])
return "\n".join(lines) + "\n"
diff --git a/py_modules/lsfg_vk/configuration_helpers_generated.py b/py_modules/lsfg_vk/configuration_helpers_generated.py
new file mode 100644
index 0000000..f9f4a65
--- /dev/null
+++ b/py_modules/lsfg_vk/configuration_helpers_generated.py
@@ -0,0 +1,22 @@
+"""
+Auto-generated configuration helper functions from shared_config.py
+DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build
+"""
+
+from typing import Dict, Any
+from .config_schema_generated import ConfigurationData, ALL_FIELDS
+
+
+def log_configuration_update(logger, config: ConfigurationData) -> None:
+ """Log configuration update with all field values"""
+ logger.info(f"Updated lsfg TOML configuration: dll={config['dll']}, multiplier={config['multiplier']}, flow_scale={config['flow_scale']}, performance_mode={config['performance_mode']}, hdr_mode={config['hdr_mode']}, experimental_present_mode={config['experimental_present_mode']}, dxvk_frame_rate={config['dxvk_frame_rate']}, enable_wow64={config['enable_wow64']}, disable_steamdeck_mode={config['disable_steamdeck_mode']}, mangohud_workaround={config['mangohud_workaround']}, disable_vkbasalt={config['disable_vkbasalt']}")
+
+
+def get_config_field_names() -> list[str]:
+ """Get all configuration field names"""
+ return ALL_FIELDS.copy()
+
+
+def extract_config_values(config: ConfigurationData) -> Dict[str, Any]:
+ """Extract configuration values as a dictionary"""
+ return {field: config[field] for field in ALL_FIELDS}