Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.

Commit d4a5cc6

Browse files
authored
Merge pull request #10 from Project-Collapse-Studios/psc-dev
Update dynpr
2 parents ef77887 + 5b68786 commit d4a5cc6

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

transforms/dynamic_priority.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from hammeraddons.bsp_transform import trans, Context
22

33
from srctools import VMF, Entity, conv_int, Vec, Output
4-
import logging
4+
from srctools.logger import get_logger
55

6-
LOGGER = logging.getLogger("[Transform][Dynamic Priority]")
6+
LOGGER = get_logger(__name__)
77

88

99
@trans("Dynamic Priority")
@@ -37,11 +37,15 @@ def dynamic_priority(ctx: Context):
3737
available_styles = list(available_styles - used_styles)
3838

3939
lg0_static_style = available_styles[0]
40-
lg0_dynamic_style = available_styles[1]
41-
lg1_static_style = available_styles[2]
40+
lg1_static_style = available_styles[1]
41+
lg0_dynamic_style = available_styles[2]
4242
lg1_dynamic_style = available_styles[3]
4343

4444
for light in lights:
45+
46+
if conv_int(light["_lightmode"], 2) == 1: # Convert specular to dynamic
47+
LOGGER.info(f"Converting light at {light.get_origin()} to Baked Bounce!")
48+
light["_lightmode"] = 2
4549

4650
if conv_int(light["_lightmode"], 2) != 2: # Only Baked Bounce makes sense to have this functionality
4751
continue
@@ -60,7 +64,7 @@ def dynamic_priority(ctx: Context):
6064
if dynpr == 2: # On High, don't change since the light is always dynamic
6165
continue
6266

63-
LOGGER.info(f"Processing light at {light.get_origin()}")
67+
#LOGGER.info(f"Processing light at {light.get_origin()}")
6468

6569
if not added_logic:
6670
added_logic = True
@@ -70,15 +74,23 @@ def dynamic_priority(ctx: Context):
7074

7175
light_copy = light.copy()
7276
light_bounce = light.copy()
77+
#It turns out, bounce isn't needed, it will get generated from the dynamic light since it doesn't have the style kv
7378

7479
light_bounce["_lightmode"] = 2 # Ensure Bounce is created
75-
light_bounce["_removeaftercompile"] = 1 # Make VRAD remove this light after compilation
80+
#light_bounce["_removeaftercompile"] = 1 # Make VRAD remove this light after compilation
7681
# This trick allows us to create artificial bounce-only lights, because named lights don't get bounce lights
82+
83+
# Okay it turns out this "trick" works only sometimes and sometimes it crashes the game
84+
85+
light_bounce.add_out(
86+
Output("OnUser1", "!self", "Kill", "", 0.2)
87+
)
7788

7889
# The thing is, even when switching the modes, bounce lights will remain on, because we're switching between groups and not on/off
7990

8091
light["targetname"] = f"light_dynpr_dynamic_{dynpr}"
8192

93+
#Dynamic lights don't need styles for networking
8294
if dynpr == 0:
8395
light["style"] = lg0_dynamic_style
8496
elif dynpr == 1:
@@ -96,17 +108,18 @@ def dynamic_priority(ctx: Context):
96108
light_copy["_lightmode"] = 0 # Fully static
97109

98110
# We expect the mode to be medium by default, it also limits the amount of lights being switched at once when changing from this mode on map load
99-
if dynpr == 1: # Medium, set the static light to dark
100-
spawnflags = conv_int(light_copy["spawnflags", 0])
101-
spawnflags |= 1 # Sets Initially Dark to True
102-
light_copy["spawnflags"] = spawnflags
103-
104-
elif dynpr == 0: # Low, set the dynamic light to dark
105-
spawnflags = conv_int(light["spawnflags", 0])
106-
spawnflags |= 1 # Sets Initially Dark to True
107-
light["spawnflags"] = spawnflags
111+
#if dynpr == 1: # Medium, set the static light to dark
112+
# spawnflags = conv_int(light_copy["spawnflags", 0])
113+
# spawnflags |= 1 # Sets Initially Dark to True
114+
# light_copy["spawnflags"] = spawnflags
115+
#
116+
#elif dynpr == 0: # Low, set the dynamic light to dark
117+
spawnflags = conv_int(light["spawnflags", 0])
118+
spawnflags |= 1 # Sets Initially Dark to True
119+
light["spawnflags"] = spawnflags
108120

109-
vmf.add_ents([light_copy, light_bounce])
121+
vmf.add_ents([light_copy])
122+
vmf.add_ents([light_bounce])
110123

111124

112125

@@ -132,7 +145,8 @@ def AddLogic(vmf: VMF, pos: Vec):
132145
)
133146

134147
logic_auto.add_out(
135-
Output("OnMapSpawn", "@PC_dynpr", "RunScriptCode", "LoadFromMemory()")
148+
Output("OnMapSpawn", "@PC_dynpr", "RunScriptCode", "LoadFromMemory()"),
149+
Output("OnMapSpawn", "light_rt*", "FireUser1", only_once=True) # Kill bounce only lights
136150
)
137151

138152
logic_script.add_out(

0 commit comments

Comments
 (0)