Skip to content

Commit

Permalink
Write migrated widgets as stylevars also, to preserve backwards compa…
Browse files Browse the repository at this point in the history
…tibility
  • Loading branch information
TeamSpen210 committed Sep 9, 2024
1 parent 85950f8 commit 0fc45b2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/exporting/stylevar.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Export stylevar selections."""
from srctools import Keyvalues, bool_as_int

from . import ExportData, STEPS, StepResource
from packages import StyleVar
from config.widgets import WidgetConfig
from packages import ConfigGroup, StyleVar
import config

from . import ExportData, STEPS, StepResource


@STEPS.add_step(prereq=[], results=[StepResource.VCONF_DATA])
Expand All @@ -14,8 +16,17 @@ async def step_add_stylevars(exp_data: ExportData) -> None:
"""
style_vars: dict[str, bool] = exp_data.selected[StyleVar]
# Add the StyleVars block, containing each style_var.
exp_data.vbsp_conf.append(Keyvalues('StyleVars', [
block = Keyvalues('StyleVars', [
Keyvalues(key, bool_as_int(val))
for key, val in
style_vars.items()
]))
])
# Also add all widgets that were stylevars, so previous packages still function.
for group in exp_data.packset.all_obj(ConfigGroup):
for widget in group.widgets:
if widget.stylevar_id:
value = config.APP.get_cur_conf(WidgetConfig, widget.conf_id()).values
if isinstance(value, str):
block[widget.stylevar_id] = value

exp_data.vbsp_conf.append(block)

0 comments on commit 0fc45b2

Please sign in to comment.