Skip to content

Commit 479a5ca

Browse files
committed
Strip 'soundscape' value type from non-Strata games, use in ents
1 parent dabcd81 commit 479a5ca

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

fgd/point/env/env_soundscape.fgd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
[
1515
radius(integer) : "Radius" : 128 : "If set to -1, then the player can hear the soundscape as long as they can see it (regardless of distance to it)."
1616

17-
soundscape[engine](string) : "Soundscape" : "" : "The name of the soundscape to use. Corresponds to an entry in the soundscapes*.txt file in the scripts/ directory."
17+
// Strata and srctools support this, to dynamically figure out the names.
18+
soundscape[engine](soundscape) : "Soundscape" : "" : "The name of the soundscape to use. Corresponds to an entry in the soundscapes*.txt file in the scripts/ directory."
19+
soundscape[STRATA](soundscape) : "Soundscape" : "" : "The name of the soundscape to use. Corresponds to an entry in the soundscapes*.txt file in the scripts/ directory."
1820
soundscape(choices) : "Soundscape" : "Nothing" : "The name of the soundscape to use. Corresponds to an entry in the soundscapes*.txt file in the scripts/ directory." =
1921
[
2022
"Nothing": "Nothing"
@@ -25,7 +27,7 @@
2527
]
2628

2729

28-
// up to date as of 04/01/2019 - Ficool/Pinsplash
30+
// up to date as of 04/01/2019
2931
soundscape[tf2](choices) : "Soundscape" : "tf2.general_ambient" : "The name of the soundscape to use. Corresponds to an entry in the soundscapes*.txt file in the scripts/ directory." =
3032
[
3133
"tf2.general_ambient" : "General Ambience"
@@ -602,4 +604,5 @@
602604

603605
// Outputs
604606
output OnPlay(void) : "Fired when this soundscape becomes the active one."
607+
@resources [] // Just the soundscape.
605608
]

fgd/point/env/env_soundscape_triggerable.fgd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
iconsprite("editor/env_soundscape_triggerable.vmt")
44
= env_soundscape_triggerable: "An entity that works like env_soundscape except that it works in conjunction with trigger_soundscape to determine when a player hears it."
55
[
6-
input ChangeSoundscape[KZ](void) : "Change the activator's soundscape to the soundscape specified in this entity."
6+
input ChangeSoundscape[KZ](void) : "Change the activator's soundscape to the soundscape specified in this entity."
7+
@resources [] // Just the soundscape, in parent.
78
]

src/hammeraddons/unify_fgd.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
from srctools import fgd
1717
from srctools.fgd import (
18-
FGD, AutoVisgroup, EntAttribute, EntityDef, EntityTypes, Helper, HelperExtAppliesTo,
19-
HelperTypes, KVDef, ResourceCtx, Snippet, ValueTypes, match_tags, validate_tags,
18+
FGD, AutoVisgroup, EntAttribute, EntityDef, EntityTypes, TagsSet, Helper, HelperExtAppliesTo,
19+
HelperTypes, KVDef, ResourceCtx, Snippet, ValueTypes, match_tags, validate_tags
2020
)
2121
from srctools.filesys import File, RawFileSystem
2222
from srctools.math import Vec, format_float
@@ -150,9 +150,10 @@
150150
}
151151

152152
# If the tag is present, run to backport newer FGD syntax to older engines.
153-
POLYFILLS: list[tuple[frozenset[str], Callable[[FGD], None]]] = []
153+
type PolyFill = Callable[[FGD, TagsSet], None]
154+
POLYFILLS: list[tuple[TagsSet, PolyFill]] = []
154155
# Ones which should run in the engine dump
155-
POLYFILLS_ENGINE: list[Callable[[FGD], None]] = []
156+
POLYFILLS_ENGINE: list[PolyFill] = []
156157

157158
# This ends up being the C1 Reverse Line Feed in CP1252,
158159
# which Hammer displays as nothing. We can suffix visgroups with this to
@@ -186,7 +187,7 @@
186187
SNIPPET_USED: set[str] = set()
187188

188189

189-
def _polyfill[Func: Callable[[FGD], None]](
190+
def _polyfill[Func: PolyFill](
190191
*tags: str,
191192
engine: bool = False,
192193
) -> Callable[[Func], Func]:
@@ -201,7 +202,7 @@ def deco(func: Func) -> Func:
201202

202203

203204
@_polyfill('until_asw', 'mesa')
204-
def _polyfill_boolean(fgd: FGD) -> None:
205+
def _polyfill_boolean(fgd: FGD, _: TagsSet) -> None:
205206
"""Before Alien Swarm's Hammer, boolean was not available as a keyvalue type.
206207
207208
Substitute with choices.
@@ -218,7 +219,7 @@ def _polyfill_boolean(fgd: FGD) -> None:
218219

219220

220221
@_polyfill('until_asw')
221-
def _polyfill_particlesystem(fgd: FGD) -> None:
222+
def _polyfill_particlesystem(fgd: FGD, _: TagsSet) -> None:
222223
"""Before Alien Swarm's Hammer, the particle system viewer was not available.
223224
224225
Substitute with just a string.
@@ -231,7 +232,7 @@ def _polyfill_particlesystem(fgd: FGD) -> None:
231232

232233

233234
@_polyfill('until_asw')
234-
def _polyfill_node_id(fgd: FGD) -> None:
235+
def _polyfill_node_id(fgd: FGD, _: TagsSet) -> None:
235236
"""Before Alien Swarm's Hammer, node_id was not available as a keyvalue type.
236237
237238
Substitute with integer.
@@ -244,7 +245,7 @@ def _polyfill_node_id(fgd: FGD) -> None:
244245

245246

246247
@_polyfill('until_l4d2', '!tf2')
247-
def _polyfill_scripts(fgd: FGD) -> None:
248+
def _polyfill_scripts(fgd: FGD, _: TagsSet) -> None:
248249
"""Before L4D2's Hammer (except TF2), the vscript specific types were not available.
249250
250251
Substitute with just a string.
@@ -261,15 +262,21 @@ def _polyfill_scripts(fgd: FGD) -> None:
261262

262263

263264
@_polyfill()
264-
def _polyfill_ext_valuetypes(fgd: FGD) -> None:
265-
# Convert extension types to the closest standard equivalent.
265+
def _polyfill_ext_valuetypes(fgd: FGD, tags: TagsSet) -> None:
266+
"""Convert extension types to the closest standard equivalent.
267+
268+
Does not apply to engine builds, those accept our custom types.
269+
"""
266270
decay = {
267271
ValueTypes.EXT_STR_TEXTURE: ValueTypes.STRING,
268272
ValueTypes.EXT_ANGLE_PITCH: ValueTypes.FLOAT,
269273
ValueTypes.EXT_ANGLES_LOCAL: ValueTypes.ANGLES,
270274
ValueTypes.EXT_VEC_DIRECTION: ValueTypes.VEC,
271275
ValueTypes.EXT_VEC_LOCAL: ValueTypes.VEC,
272276
}
277+
if 'STRATA' not in tags:
278+
decay[ValueTypes.EXT_SOUNDSCAPE] = ValueTypes.STRING
279+
273280
for ent in fgd.entities.values():
274281
for tag_map in ent.keyvalues.values():
275282
for kv in tag_map.values():
@@ -278,8 +285,9 @@ def _polyfill_ext_valuetypes(fgd: FGD) -> None:
278285
kv.type = decay.get(kv.type, kv.type)
279286

280287

281-
@_polyfill('!P2DES', engine=True) # Fixed in VitaminSource.
282-
def _polyfill_frustum_literals(fgd: FGD) -> None:
288+
# This is supported in VitaminSource. We want to remove in engine, so these keys get defined.
289+
@_polyfill('!P2DES', engine=True)
290+
def _polyfill_frustum_literals(fgd: FGD, _: TagsSet) -> None:
283291
"""The frustum() helper does not support literal values, only keyvalues."""
284292
keys = [
285293
('fov', '_frustum_fov', '<Frustum FOV>'),
@@ -301,7 +309,6 @@ def _polyfill_frustum_literals(fgd: FGD) -> None:
301309
while name in ent.keyvalues:
302310
i += 1
303311
name = f'{name_base}{i}'
304-
# This should be !ENGINE, but we don't run polyfills in engine mode.
305312
ent.keyvalues[name] = {frozenset(): KVDef(
306313
name,
307314
type=ValueTypes.COLOR_255 if attr == 'color' else ValueTypes.FLOAT,
@@ -327,7 +334,7 @@ def format_all_tags() -> str:
327334
)
328335

329336

330-
def expand_tags(tags: frozenset[str]) -> frozenset[str]:
337+
def expand_tags(tags: TagsSet) -> TagsSet:
331338
"""Expand the given tags, producing the full list of tags these will search.
332339
333340
This adds since_/until_ tags, and values in FEATURES.
@@ -405,6 +412,7 @@ def load_database(
405412

406413
# Classname -> filename
407414
ent_source: dict[str, str] = {}
415+
extra_fsys: RawFileSystem | None
408416

409417
if extra_loc is not None:
410418
if single_extra := extra_loc.is_file():
@@ -653,7 +661,7 @@ def get_appliesto(ent: EntityDef) -> list[str]:
653661
return arg_list
654662

655663

656-
def add_tag(tags: frozenset[str], new_tag: str) -> frozenset[str]:
664+
def add_tag(tags: TagsSet, new_tag: str) -> TagsSet:
657665
"""Modify these tags such that they allow the new tag."""
658666
is_inverted = new_tag.startswith(('!', '-'))
659667

@@ -726,7 +734,7 @@ def action_count(
726734

727735
print('Done.\nGames: ' + ', '.join(sorted(games)))
728736

729-
expanded: dict[str, frozenset[str]] = {
737+
expanded: dict[str, TagsSet] = {
730738
# Opt into complete list, since we're checking against engine dumps.
731739
game: expand_tags(frozenset({game, 'COMPLETE'}))
732740
for game in ALL_GAMES | ALL_MODS
@@ -980,7 +988,7 @@ def action_import(
980988
ent.helpers.append(helper)
981989

982990
for cat in ('keyvalues', 'inputs', 'outputs'):
983-
cur_map: dict[str, dict[frozenset[str], EntityDef]] = getattr(ent, cat)
991+
cur_map: dict[str, dict[TagsSet, EntityDef]] = getattr(ent, cat)
984992
new_map = getattr(new_ent, cat)
985993
new_names = set()
986994
for name, tag_map in new_map.items():
@@ -1039,7 +1047,7 @@ def action_import(
10391047
def action_export(
10401048
dbase: Path,
10411049
extra_db: Path | None,
1042-
tags: frozenset[str],
1050+
tags: TagsSet,
10431051
output_path: Path,
10441052
as_binary: bool,
10451053
engine_mode: bool,
@@ -1100,8 +1108,8 @@ def action_export(
11001108
ent.bases = [base_entity_def]
11011109

11021110
value: EntAttribute
1103-
category: dict[str, dict[frozenset[str], EntAttribute]]
1104-
base_cat: dict[str, dict[frozenset[str], EntAttribute]]
1111+
category: dict[str, dict[TagsSet, EntAttribute]]
1112+
base_cat: dict[str, dict[TagsSet, EntAttribute]]
11051113
for attr_name in ['inputs', 'outputs', 'keyvalues']:
11061114
# Unsafe cast, we're not going to insert the wrong kind of attribute though.
11071115
category = getattr(ent, attr_name)
@@ -1115,7 +1123,7 @@ def action_export(
11151123
# Remake the map, excluding non-engine tags.
11161124
# If any are explicitly matching us, just use that
11171125
# directly.
1118-
tag_map: dict[frozenset[str], EntAttribute] = {}
1126+
tag_map: dict[TagsSet, EntAttribute] = {}
11191127
for tags, value in orig_tag_map.items():
11201128
if 'ENGINE' in tags or '+ENGINE' in tags:
11211129
if value.type is ValueTypes.CHOICES:
@@ -1267,12 +1275,12 @@ def action_export(
12671275
if engine_mode:
12681276
for polyfill in POLYFILLS_ENGINE:
12691277
print(f' - {polyfill.__name__.removeprefix('_polyfill_')}')
1270-
polyfill(fgd)
1278+
polyfill(fgd, tags)
12711279
else:
12721280
for poly_tag, polyfill in POLYFILLS:
12731281
if match_tags(tags, poly_tag):
12741282
print(f' - {polyfill.__name__.removeprefix('_polyfill_')}: Applying')
1275-
polyfill(fgd)
1283+
polyfill(fgd, tags)
12761284
else:
12771285
print(f' - {polyfill.__name__.removeprefix('_polyfill_')}: Not required')
12781286

0 commit comments

Comments
 (0)