-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break out ambient_generic spawnflags into keyvalues
This makes them less confusing, and also allows setting them with $fixup variables. See #260.
- Loading branch information
1 parent
526295c
commit fd03ff7
Showing
5 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Allow ambient_generic's confusing spawnflags to be set via keyvalues instead.""" | ||
from typing import Final | ||
|
||
from hammeraddons.bsp_transform import Context, trans, ent_description | ||
from srctools import conv_int, logger | ||
|
||
|
||
LOGGER = logger.get_logger(__name__) | ||
|
||
|
||
FLAG_INFINITE: Final = 1 | ||
FLAG_START_SILENT: Final = 16 | ||
FLAG_NOT_LOOPED: Final = 32 | ||
|
||
|
||
@trans('FGD - ambient_generic keyvalues') | ||
def ambient_generic_kvs(ctx: Context) -> None: | ||
"""Allow ambient_generic's confusing spawnflags to be set via keyvalues instead. | ||
This also allows them to be easily set from $fixup values. | ||
Importantly this runs after inv_booleans, so it doesn't need to handle that. | ||
""" | ||
for ent in ctx.vmf.by_class['ambient_generic']: | ||
flags = conv_int(ent['spawnflags']) | ||
|
||
# These are inverted. | ||
for name, pretty, flag in [ | ||
('haddons_enabled', 'Enabled', FLAG_START_SILENT), | ||
('haddons_mode', 'Mode', FLAG_NOT_LOOPED), | ||
]: | ||
value = conv_int(ent[name]) | ||
if value == -1: | ||
pass # Keep spawnflag | ||
elif value == 0: | ||
flags |= flag | ||
elif value == 1: | ||
flags &= ~flag | ||
else: | ||
LOGGER.warning( | ||
'{} value "{}" is invalid for {}: must be -1, 0 or 1!', | ||
pretty, ent[name], ent_description(ent), | ||
) | ||
|
||
# Non-inverted | ||
value = conv_int(ent['haddons_infrange']) | ||
if value == -1: | ||
pass # Keep spawnflag | ||
elif value == 0: | ||
flags &= ~FLAG_INFINITE | ||
elif value == 1: | ||
flags |= FLAG_INFINITE | ||
else: | ||
LOGGER.warning( | ||
'{} value "{}" is invalid for {}: must be -1, 0 or 1!', | ||
'Infinite Range', ent['haddons_infrange'], ent_description(ent), | ||
) | ||
ent['spawnflags'] = flags |