Re-organize all projects (#4166)
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Singularity.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IClientSingularityInstance))]
|
||||
class ClientSingularityComponent : SharedSingularityComponent, IClientSingularityInstance
|
||||
{
|
||||
[ViewVariables]
|
||||
public int Level { get; set; }
|
||||
|
||||
//I am lazy
|
||||
[ViewVariables]
|
||||
public float Intensity
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Level)
|
||||
{
|
||||
case 0:
|
||||
return 0.0f;
|
||||
case 1:
|
||||
return 2.7f;
|
||||
case 2:
|
||||
return 14.4f;
|
||||
case 3:
|
||||
return 47.2f;
|
||||
case 4:
|
||||
return 180.0f;
|
||||
case 5:
|
||||
return 600.0f;
|
||||
case 6:
|
||||
return 800.0f;
|
||||
}
|
||||
return -1.0f;
|
||||
}
|
||||
}
|
||||
[ViewVariables]
|
||||
public float Falloff
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Level)
|
||||
{
|
||||
case 0:
|
||||
return 9999f;
|
||||
case 1:
|
||||
return 6.4f;
|
||||
case 2:
|
||||
return 7.0f;
|
||||
case 3:
|
||||
return 8.0f;
|
||||
case 4:
|
||||
return 10.0f;
|
||||
case 5:
|
||||
return 12.0f;
|
||||
case 6:
|
||||
return 12.0f;
|
||||
}
|
||||
return -1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
if (curState is not SingularityComponentState state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Level = state.Level;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
|
||||
namespace Content.Client.Singularity.Components
|
||||
{
|
||||
public class ContainmentFieldComponent : Component
|
||||
{
|
||||
public override string Name => "Containment Field";
|
||||
|
||||
private SpriteComponent? _spriteComponent;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (!Owner.TryGetComponent(out _spriteComponent))
|
||||
{
|
||||
Logger.Error("Containmentfieldcomponent created without spritecomponent");
|
||||
}
|
||||
else
|
||||
{
|
||||
_spriteComponent.Directional = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Content.Client/Singularity/Components/ISingularity.cs
Normal file
12
Content.Client/Singularity/Components/ISingularity.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Content.Client.Singularity.Components
|
||||
{
|
||||
interface IClientSingularityInstance
|
||||
{
|
||||
public float Intensity { get; }
|
||||
public float Falloff { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Singularity.Components
|
||||
{
|
||||
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IClientSingularityInstance))]
|
||||
public class ToySingularityComponent : Component, IClientSingularityInstance
|
||||
{
|
||||
public override string Name => "ToySingularity";
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Falloff { get; set; } = 2.0f;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Intensity { get; set; } = 0.25f;
|
||||
}
|
||||
}
|
||||
143
Content.Client/Singularity/SingularityOverlay.cs
Normal file
143
Content.Client/Singularity/SingularityOverlay.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.Singularity.Components;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Singularity
|
||||
{
|
||||
public class SingularityOverlay : Overlay
|
||||
{
|
||||
[Dependency] private readonly IComponentManager _componentManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IClyde _displayManager = default!;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
public override bool RequestScreenTexture => true;
|
||||
|
||||
private readonly ShaderInstance _shader;
|
||||
|
||||
Dictionary<EntityUid, SingularityShaderInstance> _singularities = new Dictionary<EntityUid, SingularityShaderInstance>();
|
||||
|
||||
public SingularityOverlay()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_shader = _prototypeManager.Index<ShaderPrototype>("Singularity").Instance().Duplicate();
|
||||
}
|
||||
|
||||
public override bool OverwriteTargetFrameBuffer()
|
||||
{
|
||||
return _singularities.Count() > 0;
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
{
|
||||
SingularityQuery(args.Viewport.Eye);
|
||||
|
||||
var viewportWB = args.WorldBounds;
|
||||
// Has to be correctly handled because of the way intensity/falloff transform works so just do it.
|
||||
_shader?.SetParameter("renderScale", args.Viewport.RenderScale);
|
||||
foreach (SingularityShaderInstance instance in _singularities.Values)
|
||||
{
|
||||
// To be clear, this needs to use "inside-viewport" pixels.
|
||||
// In other words, specifically NOT IViewportControl.WorldToScreen (which uses outer coordinates).
|
||||
var tempCoords = args.Viewport.WorldToLocal(instance.CurrentMapCoords);
|
||||
tempCoords.Y = args.Viewport.Size.Y - tempCoords.Y;
|
||||
_shader?.SetParameter("positionInput", tempCoords);
|
||||
if (ScreenTexture != null)
|
||||
_shader?.SetParameter("SCREEN_TEXTURE", ScreenTexture);
|
||||
_shader?.SetParameter("intensity", instance.Intensity);
|
||||
_shader?.SetParameter("falloff", instance.Falloff);
|
||||
|
||||
var worldHandle = args.WorldHandle;
|
||||
worldHandle.UseShader(_shader);
|
||||
worldHandle.DrawRect(viewportWB, Color.White);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Queries all singulos on the map and either adds or removes them from the list of rendered singulos based on whether they should be drawn (in range? on the same z-level/map? singulo entity still exists?)
|
||||
private float _maxDist = 15.0f;
|
||||
private void SingularityQuery(IEye? currentEye)
|
||||
{
|
||||
if (currentEye == null)
|
||||
{
|
||||
_singularities.Clear();
|
||||
return;
|
||||
}
|
||||
var currentEyeLoc = currentEye.Position;
|
||||
var currentMap = currentEye.Position.MapId;
|
||||
|
||||
var singuloComponents = _componentManager.EntityQuery<IClientSingularityInstance>();
|
||||
foreach (var singuloInterface in singuloComponents) //Add all singulos that are not added yet but qualify
|
||||
{
|
||||
var singuloComponent = (Component)singuloInterface;
|
||||
var singuloEntity = singuloComponent.Owner;
|
||||
if (!_singularities.Keys.Contains(singuloEntity.Uid) && SinguloQualifies(singuloEntity, currentEyeLoc))
|
||||
{
|
||||
_singularities.Add(singuloEntity.Uid, new SingularityShaderInstance(singuloEntity.Transform.MapPosition.Position, singuloInterface.Intensity, singuloInterface.Falloff));
|
||||
}
|
||||
}
|
||||
|
||||
var activeShaderUids = _singularities.Keys;
|
||||
foreach (var activeSinguloUid in activeShaderUids) //Remove all singulos that are added and no longer qualify
|
||||
{
|
||||
if (_entityManager.TryGetEntity(activeSinguloUid, out IEntity? singuloEntity))
|
||||
{
|
||||
if (!SinguloQualifies(singuloEntity, currentEyeLoc))
|
||||
{
|
||||
_singularities.Remove(activeSinguloUid);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!singuloEntity.TryGetComponent<IClientSingularityInstance>(out var singuloInterface))
|
||||
{
|
||||
_singularities.Remove(activeSinguloUid);
|
||||
}
|
||||
else
|
||||
{
|
||||
var shaderInstance = _singularities[activeSinguloUid];
|
||||
shaderInstance.CurrentMapCoords = singuloEntity.Transform.MapPosition.Position;
|
||||
shaderInstance.Intensity = singuloInterface.Intensity;
|
||||
shaderInstance.Falloff = singuloInterface.Falloff;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_singularities.Remove(activeSinguloUid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private bool SinguloQualifies(IEntity singuloEntity, MapCoordinates currentEyeLoc)
|
||||
{
|
||||
return singuloEntity.Transform.MapID == currentEyeLoc.MapId && singuloEntity.Transform.Coordinates.InRange(_entityManager, EntityCoordinates.FromMap(_entityManager, singuloEntity.Transform.ParentUid, currentEyeLoc), _maxDist);
|
||||
}
|
||||
|
||||
private sealed class SingularityShaderInstance
|
||||
{
|
||||
public Vector2 CurrentMapCoords;
|
||||
public float Intensity;
|
||||
public float Falloff;
|
||||
public SingularityShaderInstance(Vector2 mapCoords, float intensity, float falloff)
|
||||
{
|
||||
CurrentMapCoords = mapCoords;
|
||||
Intensity = intensity;
|
||||
Falloff = falloff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
50
Content.Client/Singularity/Visualizers/EmitterVisualizer.cs
Normal file
50
Content.Client/Singularity/Visualizers/EmitterVisualizer.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Singularity.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class EmitterVisualizer : AppearanceVisualizer
|
||||
{
|
||||
private const string OverlayBeam = "beam";
|
||||
private const string OverlayUnderPowered = "underpowered";
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!component.TryGetData(EmitterVisuals.Locked, out bool locked))
|
||||
locked = false;
|
||||
|
||||
|
||||
if (!component.TryGetData(EmitterVisuals.VisualState, out EmitterVisualState state))
|
||||
state = EmitterVisualState.Off;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case EmitterVisualState.On:
|
||||
sprite.LayerSetVisible(1, true);
|
||||
sprite.LayerSetState(1, OverlayBeam);
|
||||
break;
|
||||
case EmitterVisualState.Underpowered:
|
||||
sprite.LayerSetVisible(1, true);
|
||||
sprite.LayerSetState(1, OverlayUnderPowered);
|
||||
break;
|
||||
case EmitterVisualState.Off:
|
||||
sprite.LayerSetVisible(1, false);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
sprite.LayerSetVisible(2, locked);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Client.Singularity.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class RadiationCollectorVisualizer : AppearanceVisualizer, ISerializationHooks
|
||||
{
|
||||
private const string AnimationKey = "radiationcollector_animation";
|
||||
|
||||
private Animation ActivateAnimation = default!;
|
||||
private Animation DeactiveAnimation = default!;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
ActivateAnimation = new Animation {Length = TimeSpan.FromSeconds(0.8f)};
|
||||
{
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
ActivateAnimation.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = RadiationCollectorVisualLayers.Main;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("ca_active", 0f));
|
||||
|
||||
/*var sound = new AnimationTrackPlaySound();
|
||||
CloseAnimation.AnimationTracks.Add(sound);
|
||||
sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(closeSound, 0));*/
|
||||
}
|
||||
|
||||
DeactiveAnimation = new Animation {Length = TimeSpan.FromSeconds(0.8f)};
|
||||
{
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
DeactiveAnimation.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = RadiationCollectorVisualLayers.Main;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("ca_deactive", 0f));
|
||||
|
||||
/*var sound = new AnimationTrackPlaySound();
|
||||
CloseAnimation.AnimationTracks.Add(sound);
|
||||
sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(closeSound, 0));*/
|
||||
}
|
||||
}
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
if (!entity.HasComponent<AnimationPlayerComponent>())
|
||||
{
|
||||
entity.AddComponent<AnimationPlayerComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent<ISpriteComponent>(out var sprite)) return;
|
||||
if (!component.Owner.TryGetComponent<AnimationPlayerComponent>(out var animPlayer)) return;
|
||||
if (!component.TryGetData(RadiationCollectorVisuals.VisualState, out RadiationCollectorVisualState state))
|
||||
{
|
||||
state = RadiationCollectorVisualState.Deactive;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case RadiationCollectorVisualState.Active:
|
||||
sprite.LayerSetState(RadiationCollectorVisualLayers.Main, "ca_on");
|
||||
break;
|
||||
case RadiationCollectorVisualState.Activating:
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Play(ActivateAnimation, AnimationKey);
|
||||
animPlayer.AnimationCompleted += _ =>
|
||||
component.SetData(RadiationCollectorVisuals.VisualState,
|
||||
RadiationCollectorVisualState.Active);
|
||||
}
|
||||
break;
|
||||
case RadiationCollectorVisualState.Deactivating:
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
{
|
||||
animPlayer.Play(DeactiveAnimation, AnimationKey);
|
||||
animPlayer.AnimationCompleted += _ =>
|
||||
component.SetData(RadiationCollectorVisuals.VisualState,
|
||||
RadiationCollectorVisualState.Deactive);
|
||||
}
|
||||
break;
|
||||
case RadiationCollectorVisualState.Deactive:
|
||||
sprite.LayerSetState(RadiationCollectorVisualLayers.Main, "ca_off");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum RadiationCollectorVisualLayers : byte
|
||||
{
|
||||
Main
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Content.Shared.Singularity;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Singularity.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SingularityVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("layer")]
|
||||
private int Layer { get; } = 0;
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
entity.GetComponentOrNull<SpriteComponent>()?.LayerMapReserveBlank(Layer);
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!component.Owner.TryGetComponent(out SpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!component.TryGetData(SingularityVisuals.Level, out int level))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sprite.LayerSetRSI(Layer, "Constructible/Power/Singularity/singularity_" + level + ".rsi");
|
||||
sprite.LayerSetState(Layer, "singularity_" + level);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user