From 45ef1907efab41d6cdb4c5872a370084622d2036 Mon Sep 17 00:00:00 2001 From: Spencer Brown Date: Wed, 4 Dec 2024 15:39:20 +1000 Subject: [PATCH] Add option to comp_adv_output to have it expand target searches itself. --- CHANGELOG.md | 1 + fgd/point/comp/comp_adv_output.fgd | 3 ++- transforms/comp_adv_output.py | 42 ++++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e7cedc9..8f276b97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/fgd/point/comp/comp_adv_output.fgd b/fgd/point/comp/comp_adv_output.fgd index f0ebff20..2ec8edbd 100644 --- a/fgd/point/comp/comp_adv_output.fgd +++ b/fgd/point/comp/comp_adv_output.fgd @@ -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." @@ -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" diff --git a/transforms/comp_adv_output.py b/transforms/comp_adv_output.py index 240820da..db5bcb74 100644 --- a/transforms/comp_adv_output.py +++ b/transforms/comp_adv_output.py @@ -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 @@ -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 ({})!', @@ -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(