22
33using Source ;
44using Source . Common ;
5+ using Source . Common . Engine ;
6+ using Source . Common . Mathematics ;
57
68using System . Numerics ;
79
@@ -24,6 +26,98 @@ public partial class Sun : BaseEntity
2426 new ( nameof ( HDRColorScale ) ) { Encoding = NetEncoding . Float , Bits = 0 , Flags = PropFlags . NoScale , Low = 0.0f , High = 100.0f } ,
2527 ] ;
2628
29+ public static readonly new DataMap DataDesc = new ( typeof ( Sun ) , BaseEntity . DataDesc , [
30+ DEFINE < Sun > . FIELD ( nameof ( Direction ) , FieldType . Vector ) ,
31+
32+ DEFINE < Sun > . KEYFIELD ( nameof ( UseAngles ) , FieldType . Integer , "use_angles" ) ,
33+ DEFINE < Sun > . KEYFIELD ( nameof ( Pitch ) , FieldType . Float , "pitch" ) ,
34+ DEFINE < Sun > . KEYFIELD ( nameof ( Yaw ) , FieldType . Float , "angle" ) ,
35+ DEFINE < Sun > . KEYFIELD ( nameof ( Size ) , FieldType . Integer , "size" ) ,
36+ DEFINE < Sun > . KEYFIELD ( nameof ( Overlay ) , FieldType . Color32 , "overlaycolor" ) ,
37+ DEFINE < Sun > . KEYFIELD ( nameof ( OverlaySize ) , FieldType . Integer , "overlaysize" ) ,
38+ DEFINE < Sun > . KEYFIELD ( nameof ( StrMaterial ) , FieldType . String , "material" ) ,
39+ DEFINE < Sun > . KEYFIELD ( nameof ( StrOverlayMaterial ) , FieldType . String , "overlaymaterial" ) ,
40+
41+ DEFINE < Sun > . FIELD ( nameof ( On ) , FieldType . Boolean ) ,
42+
43+ DEFINE < Sun > . INPUTFUNC ( FieldType . Void , "TurnOn" , nameof ( InputTurnOn ) , ( INPUTFUNCPTR ) ( ( self , data ) => ( ( Sun ) self ) . InputTurnOn ( data ) ) ) ,
44+ DEFINE < Sun > . INPUTFUNC ( FieldType . Void , "TurnOff" , nameof ( InputTurnOff ) , ( INPUTFUNCPTR ) ( ( self , data ) => ( ( Sun ) self ) . InputTurnOff ( data ) ) ) ,
45+ DEFINE < Sun > . INPUTFUNC ( FieldType . Color32 , "SetColor" , nameof ( InputSetColor ) , ( INPUTFUNCPTR ) ( ( self , data ) => ( ( Sun ) self ) . InputSetColor ( data ) ) ) ,
46+
47+ DEFINE < Sun > . KEYFIELD ( nameof ( HDRColorScale ) , FieldType . Float , "HDRColorScale" ) ,
48+ ] ) ;
49+ public override DataMap ? GetDataDescMap ( ) => DataDesc ;
50+
51+ public Sun ( ) {
52+ Direction = new ( 0 , 0 , 1 ) ;
53+
54+ UseAngles = 0 ;
55+ Pitch = 0 ;
56+ Yaw = 0 ;
57+ Size = 16 ;
58+
59+ On = true ;
60+ AddEFlags ( EFL . ForceCheckTransmit ) ;
61+
62+ StrMaterial = null ;
63+ StrOverlayMaterial = null ;
64+ OverlaySize = - 1 ;
65+ }
66+
67+ public override void Activate ( ) {
68+ base . Activate ( ) ;
69+
70+ if ( UseAngles != 0 ) {
71+ MapUtils . SetupLightNormalFromProps ( GetAbsAngles ( ) , Yaw , Pitch , out Vector3 direction ) ;
72+ Direction = - direction ;
73+ }
74+ else {
75+ BaseEntity ? ent = gEntList . FindEntityByName ( null , Target ) ;
76+ if ( ent != null ) {
77+ Vector3 direction = GetAbsOrigin ( ) - ent . GetAbsOrigin ( ) ;
78+ MathLib . VectorNormalize ( ref direction ) ;
79+ Direction = direction ;
80+ }
81+ }
82+
83+ if ( OverlaySize == - 1 )
84+ OverlaySize = Size ;
85+
86+ if ( StrMaterial == null )
87+ StrMaterial = "sprites/light_glow02_add_noz.vmt" ;
88+ else if ( StrMaterial . AsSpan ( ) . GetFileExtension ( ) . IsEmpty )
89+ StrMaterial += ".vmt" ;
90+
91+ if ( StrOverlayMaterial == null )
92+ StrOverlayMaterial = "sprites/light_glow02_add_noz.vmt" ;
93+ else if ( StrOverlayMaterial . AsSpan ( ) . GetFileExtension ( ) . IsEmpty )
94+ StrOverlayMaterial += ".vmt" ;
95+
96+ Material = PrecacheModel ( StrMaterial ) ;
97+ OverlayMaterial = PrecacheModel ( StrOverlayMaterial ) ;
98+ }
99+
100+ void InputTurnOn ( InputData inputdata ) {
101+ if ( ! On )
102+ On = true ;
103+ }
104+
105+ void InputTurnOff ( InputData inputdata ) {
106+ if ( On )
107+ On = false ;
108+ }
109+
110+ void InputSetColor ( InputData inputdata ) => Render = inputdata . Value . Color32 ( ) ;
111+
112+ public override EdictFlags UpdateTransmitState ( ) => SetTransmitState ( EdictFlags . Always ) ;
113+
114+ public string ? StrMaterial ;
115+ public string ? StrOverlayMaterial ;
116+
117+ public int UseAngles ;
118+ public float Pitch ;
119+ public float Yaw ;
120+
27121 [ NetworkVar ( "m_clrRender" ) ]
28122 public partial Color Render { get ; set ; }
29123 [ NetworkVar ( "m_clrOverlay" ) ]
@@ -41,5 +135,5 @@ public partial class Sun : BaseEntity
41135 [ NetworkVar ( "m_nOverlayMaterial" ) ]
42136 public partial int OverlayMaterial { get ; set ; }
43137 [ NetworkVar ( "HDRColorScale" ) ]
44- public partial int HDRColorScale { get ; set ; }
138+ public partial float HDRColorScale { get ; set ; }
45139}
0 commit comments