Skip to content

Commit

Permalink
Add option to comp_adv_output to have it expand target searches itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Dec 4, 2024
1 parent 6a02dea commit 45ef190
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Boolean keyvalues (yes/no) can now be set to `!$var`, to invert the value of the variable.
* Propcombine will now preserve prop fade distances, by calculating a new distance which encloses the original fade spheres.
* Warn if propcombine or packing was disabled via command line.
* Add option to `comp_adv_output` to have it expand target searches itself.

## Bugfixes
* Fix a compile failure if prop ropes were placed in a group with no connections.
Expand Down
3 changes: 2 additions & 1 deletion fgd/point/comp/comp_adv_output.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
target_local(target_destination) : "Target - Ent Name" : : "If set, the entity to fire inputs at."

target_instname(string) : "Target - Instance Name" : : "If set, this is appended to the target to form a full target-inst_name name."
target_expand(boolean) : "Expand Target" : : "If set, apply the list of target entities at compile time."

inp_name(string) : "Input Name" : : "The input to fire."

Expand All @@ -21,7 +22,7 @@

times(integer) : "Times to Fire" : -1 : "The number of times this output can fire, or -1 for infinite. Hammer normally only allows setting this to 1 or -1."

params_fmt(string) : "Parameter" : "{1}" : "Sets the parameter to use. This can contain placeholders like {1},{2} etc which will be filled by values in the" +
params_fmt(string) : "Parameter" : : "Sets the parameter to use. This can contain placeholders like {1},{2} etc which will be filled by values in the" +
" following parameters. Use two braces like {{ or }} if you need them in the parameter directly."

params_mode1[engine](integer) : "Parameter 1 - Mode" : "legacy"
Expand Down
42 changes: 31 additions & 11 deletions transforms/comp_adv_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import itertools
import string
from typing import Any, List, Mapping, Sequence, Union
from typing import Any, Collection, List, Mapping, Sequence, Union

from srctools import EmptyMapping, Vec, conv_float, conv_int
from srctools import EmptyMapping, Vec, conv_bool, conv_float, conv_int
from srctools.vmf import Output, Entity
from srctools.logger import get_logger

Expand Down Expand Up @@ -42,6 +42,7 @@ def advanced_output(ctx: Context) -> None:
input_name = adv_out['inp_name']
target_name = adv_out['target_local'] or adv_out['target_global']
times = conv_int(adv_out['times'], -1)
expand_target = conv_bool(adv_out['target_expand'])
if not target_name:
LOGGER.warning(
'No target entity for conv_adv_output at ({})!',
Expand Down Expand Up @@ -87,16 +88,35 @@ def advanced_output(ctx: Context) -> None:
continue

found_ent = None

targets: Collection[str] = (target_name, )
for found_ent in ctx.vmf.search(adv_out['out_ent']):
found_ent.add_out(Output(
output_name,
target_name,
input_name,
parameter,
delay,
times=times,
))
if expand_target:
targets = {
targ['targetname']
for targ in ctx.vmf.search(target_name)
}
if not any(targets):
LOGGER.warning(
'No matching named entities for search "{}" for conv_adv_output at ({})!',
target_name
)
# Fall back to letting the game do the search.
targets = (target_name, )
else:
LOGGER.info(
'Expanding {} -> {} = {}',
found_ent['targetname'], target_name,
sorted(targets),
)
for targ in targets:
found_ent.add_out(Output(
output_name,
targ,
input_name,
parameter,
delay,
times=times,
))

if found_ent is None:
LOGGER.warning(
Expand Down

0 comments on commit 45ef190

Please sign in to comment.