Skip to content

Commit

Permalink
Correctly look up types for conditional shader parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Nov 2, 2024
1 parent c63b295 commit d8e1f44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Version (dev)
* Add a `custom_syntax` option to :py:meth:`FGD.export() <srctools.fgd.FGD.export>`, disabling
export of custom syntax. Resources can now be exported.
* Escape all characters `utilbuffer.cpp` does - `\\n`, `\\t`, `\\v`, `\\b`, `\\r`, `\\f`, `\\a`, `\\`, `?`, `'`, `"`.
* Uncondintioanally enable support for escaping characters in DMX Keyvalues2, since Valve's parser can handle it. Binary formats never needed escaping.
* Unconditionally enable support for escaping characters in DMX Keyvalues2, since Valve's parser can handle it. Binary formats never needed escaping.
* Correctly look up types for conditional shader parameters (`ldr?$bumpmap`).

-------------
Version 2.3.4
Expand Down
2 changes: 2 additions & 0 deletions src/srctools/vmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def get_parm_type(name: str, default: Optional[ArgT] = None) -> Union[VarType, A

def _get_parm_type_real(name: str, default: Optional[ArgT] = None) -> Union[VarType, ArgT, None]:
"""Retrieve the type a parameter has, or return the default."""
if '?' in name:
flag, name = name.split('?', 1)
try:
return _SHADER_PARAM_TYPES[name.lstrip('$').casefold()]
except KeyError:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_vmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def test_vartypes() -> None:
assert get_parm_type('$detailblendmode') is VarType.INT
assert get_parm_type('$bottommaterial') is VarType.MATERIAL
assert get_parm_type('$bumptransform') is VarType.MATRIX
# ? flags are ignored.
assert get_parm_type('hdr?$ssbump') is VarType.INT
assert get_parm_type('!360?cheapwaterenddistance') is VarType.FLOAT
# % must be specified
assert get_parm_type('%compilenodraw') is VarType.FLAG
assert get_parm_type('compilesky', 'missing') == 'missing'
Expand Down

0 comments on commit d8e1f44

Please sign in to comment.