diff --git a/CHANGELOG.md b/CHANGELOG.md index 93f09eb6..d4ec5ce2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ * Fix various incorrect usages of the FGD `frustum()` helper. * Normals are now correctly calculated when generating propcombined models. This requires all previous models to be rebuilt, unfortunately. * Fix overlays not functioning with `material_modify_control` parent searching. -* #274: Force `light_environment` to use the required `SunSpreadAngle` casing. +* #274, #277: Force required keyvalue casing for `light_environment`'s `SunSpreadAngle` and `lua_run`'s `Code` keys. -------------------- diff --git a/transforms/fgd_tweaks/case_sensitive.py b/transforms/fgd_tweaks/case_sensitive.py new file mode 100644 index 00000000..938623b9 --- /dev/null +++ b/transforms/fgd_tweaks/case_sensitive.py @@ -0,0 +1,27 @@ +"""Some keyvalues are case-sensitive, force the required casing.""" +from srctools import VMF, logger + +from hammeraddons.bsp_transform import Context, trans +from hammeraddons.bsp_transform.common import ent_description + +LOGGER = logger.get_logger(__name__) + + +@trans('FGD - Fix key casing') +def force_case_sensitivity(ctx: Context) -> None: + """Force case-sensitivity on some keyvalues that require it.""" + fix_casing(ctx.vmf, 'light_environment', 'SunSpreadAngle') + fix_casing(ctx.vmf, 'light_directional', 'SunSpreadAngle') + fix_casing(ctx.vmf, 'lua_run', 'Code') + + +def fix_casing(vmf: VMF, classname: str, *keys: str) -> None: + """Fix the casing for one entity.""" + for ent in vmf.by_class[classname]: + for key in keys: + if value := ent.pop(key): + LOGGER.warning( + 'Correcting case of "{}" for {}', + key, ent_description(ent), + ) + ent[key] = value diff --git a/transforms/fgd_tweaks/light_sun_spread_angle.py b/transforms/fgd_tweaks/light_sun_spread_angle.py deleted file mode 100644 index d307a092..00000000 --- a/transforms/fgd_tweaks/light_sun_spread_angle.py +++ /dev/null @@ -1,10 +0,0 @@ -"""This keyvalue is case-sensitive, force the required casing.""" -from hammeraddons.bsp_transform import Context, trans - - -@trans('FGD - Fix Sun Spread Angle') -def light_sun_spread_angle(ctx: Context) -> None: - """Force case-sensitivity on this keyvalue.""" - for ent in ctx.vmf.by_class['light_environment'] | ctx.vmf.by_class['light_directional']: - ent['SunSpreadAngle'] = ent.pop('sunspreadangle') - print(dict(ent.items()))