77using Content . Shared . Item ;
88using Content . Shared . Light . Components ;
99using Content . Shared . Toggleable ;
10+ using Content . Shared . Wieldable ;
11+ using Content . Shared . Wieldable . Components ;
1012using Robust . Client . GameObjects ;
1113using Robust . Shared . Utility ;
1214
@@ -30,6 +32,10 @@ public override void Initialize()
3032 after : [ typeof ( ItemSystem ) ] ) ;
3133 SubscribeLocalEvent < ToggleableVisualsComponent , GetEquipmentVisualsEvent > ( OnGetEquipmentVisuals ,
3234 after : [ typeof ( ClientClothingSystem ) ] ) ;
35+ // Starlight begin
36+ SubscribeLocalEvent < ToggleableVisualsComponent , ItemWieldedEvent > ( OnItemWielded ) ;
37+ SubscribeLocalEvent < ToggleableVisualsComponent , ItemUnwieldedEvent > ( OnItemUnwielded ) ;
38+ // Starlight end
3339 }
3440
3541 protected override void OnAppearanceChange ( EntityUid uid ,
@@ -47,10 +53,20 @@ protected override void OnAppearanceChange(EntityUid uid,
4753 SpriteSystem . LayerMapTryGet ( ( uid , args . Sprite ) , component . SpriteLayer , out var layer , false ) )
4854 {
4955 SpriteSystem . LayerSetVisible ( ( uid , args . Sprite ) , layer , enabled ) ;
50- if ( modulateColor )
56+ if ( modulateColor && ! component . ModulateIgnoreLayers . Contains ( component . SpriteLayer ) ) // Starlight edit
5157 SpriteSystem . LayerSetColor ( ( uid , args . Sprite ) , component . SpriteLayer , color ) ;
5258 }
5359
60+ // Starlight begin
61+ foreach ( var spriteLayer in component . AdditionalLayers )
62+ if ( SpriteSystem . LayerMapTryGet ( ( uid , args . Sprite ) , spriteLayer , out var idx , false ) )
63+ {
64+ SpriteSystem . LayerSetVisible ( ( uid , args . Sprite ) , idx , enabled ) ;
65+ if ( modulateColor && ! component . ModulateIgnoreLayers . Contains ( spriteLayer ) )
66+ SpriteSystem . LayerSetColor ( ( uid , args . Sprite ) , idx , color ) ;
67+ }
68+ // Starlight end
69+
5470 // If there's a `ItemTogglePointLightComponent` that says to apply the color to attached lights, do so.
5571 if ( TryComp < ItemTogglePointLightComponent > ( uid , out var toggleLights ) &&
5672 TryComp ( uid , out PointLightComponent ? light ) )
@@ -101,7 +117,7 @@ private void OnGetEquipmentVisuals(EntityUid uid,
101117 i ++ ;
102118 }
103119
104- if ( modulateColor )
120+ if ( modulateColor && ! component . ModulateIgnoreLayers . Contains ( key ) ) // Starlight edit
105121 layer . Color = color ;
106122
107123 args . Layers . Add ( ( key , layer ) ) ;
@@ -115,8 +131,22 @@ private void OnGetHeldVisuals(EntityUid uid, ToggleableVisualsComponent componen
115131 || ! enabled )
116132 return ;
117133
118- if ( ! component . InhandVisuals . TryGetValue ( args . Location , out var layers ) )
134+ // Starlight begin
135+ List < PrototypeLayerData > ? layers ;
136+
137+ if ( TryComp < WieldableComponent > ( uid , out var wieldable ) )
138+ {
139+ if ( wieldable . Wielded && component . WieldingVisuals . Count > 0 )
140+ {
141+ if ( ! component . WieldingVisuals . TryGetValue ( args . Location , out layers ) )
142+ return ;
143+ }
144+ else if ( ! component . InhandVisuals . TryGetValue ( args . Location , out layers ) )
145+ return ;
146+ }
147+ else if ( ! component . InhandVisuals . TryGetValue ( args . Location , out layers ) )
119148 return ;
149+ // Starlight end
120150
121151 var modulateColor = AppearanceSystem . TryGetData < Color > ( uid , ToggleableVisuals . Color , out var color , appearance ) ;
122152
@@ -131,10 +161,20 @@ private void OnGetHeldVisuals(EntityUid uid, ToggleableVisualsComponent componen
131161 i ++ ;
132162 }
133163
134- if ( modulateColor )
164+ if ( modulateColor && ! component . ModulateIgnoreLayers . Contains ( key ) ) // Starlight edit
135165 layer . Color = color ;
136166
137167 args . Layers . Add ( ( key , layer ) ) ;
138168 }
139169 }
170+
171+ #region Starlight
172+
173+ private void OnItemWielded ( Entity < ToggleableVisualsComponent > ent , ref ItemWieldedEvent args ) =>
174+ _item . VisualsChanged ( ent ) ;
175+
176+ private void OnItemUnwielded ( Entity < ToggleableVisualsComponent > ent , ref ItemUnwieldedEvent args ) =>
177+ _item . VisualsChanged ( ent ) ;
178+
179+ #endregion
140180}
0 commit comments