using System.Diagnostics.CodeAnalysis; using Robust.Client.ComponentTrees; using Robust.Client.ResourceManagement; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; using Robust.Shared.Prototypes; namespace Robust.Client.GameObjects { public sealed partial class PointLightSystem : SharedPointLightSystem { [Dependency] private IResourceCache _resourceCache = default!; [Dependency] private IPrototypeManager _proto = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnLightGetState); SubscribeLocalEvent(HandleInit); SubscribeLocalEvent(OnLightHandleState); } private void OnLightHandleState(EntityUid uid, PointLightComponent component, ref ComponentHandleState args) { if (args.Current is not PointLightComponentState state) return; component.Enabled = state.Enabled; component.Offset = state.Offset; component.Softness = state.Softness; component.Falloff = state.Falloff; component.CurveFactor = state.CurveFactor; component.CastShadows = state.CastShadows; component.Energy = state.Energy; component.Radius = state.Radius; component.Color = state.Color; component.ContainerOccluded = state.ContainerOccluded; _lightTree.QueueTreeUpdate(uid, component); } public override SharedPointLightComponent EnsureLight(EntityUid uid) { return EnsureComp(uid); } public override bool ResolveLight(EntityUid uid, [NotNullWhen(true)] ref SharedPointLightComponent? component) { if (component is not null) return true; TryComp(uid, out var comp); component = comp; return component != null; } public override bool TryGetLight(EntityUid uid, [NotNullWhen(true)] out SharedPointLightComponent? component) { if (TryComp(uid, out var comp)) { component = comp; return true; } component = null; return false; } public override bool RemoveLightDeferred(EntityUid uid) { return RemCompDeferred(uid); } protected override void UpdatePriority(EntityUid uid, SharedPointLightComponent comp, MetaDataComponent meta) { } private void HandleInit(EntityUid uid, PointLightComponent component, ComponentInit args) { SetMask(component.LightMask, component); } public void SetMask(ProtoId? lightMask, PointLightComponent component) { if (_proto.Resolve(lightMask, out var mask)) component.Mask = _resourceCache.GetResource(mask.MaskPath); else component.Mask = null; } } }