Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,38 @@
using Content.Client.Light.Components;
using Content.Shared.Light.Component;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
namespace Content.Client.Light.Visualizers
{
[UsedImplicitly]
public class ExpendableLightVisualizer : AppearanceVisualizer
{
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (component.Deleted)
{
return;
}
if (component.TryGetData(ExpendableLightVisuals.State, out string lightBehaviourID))
{
if (component.Owner.TryGetComponent<LightBehaviourComponent>(out var lightBehaviour))
{
lightBehaviour.StopLightBehaviour();
if (lightBehaviourID != string.Empty)
{
lightBehaviour.StartLightBehaviour(lightBehaviourID);
}
else if (component.Owner.TryGetComponent<PointLightComponent>(out var light))
{
light.Enabled = false;
}
}
}
}
}
}

View File

@@ -0,0 +1,117 @@
using System;
using Content.Shared.Light.Component;
using JetBrains.Annotations;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.GameObjects;
namespace Content.Client.Light.Visualizers
{
[UsedImplicitly]
public class FlashLightVisualizer : AppearanceVisualizer
{
private readonly Animation _radiatingLightAnimation = new()
{
Length = TimeSpan.FromSeconds(1),
AnimationTracks =
{
new AnimationTrackComponentProperty
{
ComponentType = typeof(PointLightComponent),
InterpolationMode = AnimationInterpolationMode.Linear,
Property = nameof(PointLightComponent.Radius),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(3.0f, 0),
new AnimationTrackProperty.KeyFrame(2.0f, 0.5f),
new AnimationTrackProperty.KeyFrame(3.0f, 1)
}
}
}
};
private readonly Animation _blinkingLightAnimation = new()
{
Length = TimeSpan.FromSeconds(1),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(PointLightComponent),
//To create the blinking effect we go from nearly zero radius, to the light radius, and back
//We do this instead of messing with the `PointLightComponent.enabled` because we don't want the animation to affect component behavior
InterpolationMode = AnimationInterpolationMode.Nearest,
Property = nameof(PointLightComponent.Radius),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(0.1f, 0),
new AnimationTrackProperty.KeyFrame(2f, 0.5f),
new AnimationTrackProperty.KeyFrame(0.1f, 1)
}
}
}
};
private Action<string>? _radiatingCallback;
private Action<string>? _blinkingCallback;
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (component.Deleted)
{
return;
}
if (component.TryGetData(HandheldLightVisuals.Power,
out HandheldLightPowerStates state))
{
PlayAnimation(component, state);
}
}
private void PlayAnimation(AppearanceComponent component, HandheldLightPowerStates state)
{
component.Owner.EnsureComponent(out AnimationPlayerComponent animationPlayer);
switch (state)
{
case HandheldLightPowerStates.LowPower:
if (!animationPlayer.HasRunningAnimation("radiatingLight"))
{
animationPlayer.Play(_radiatingLightAnimation, "radiatingLight");
_radiatingCallback = (s) => animationPlayer.Play(_radiatingLightAnimation, s);
animationPlayer.AnimationCompleted += _radiatingCallback;
}
break;
case HandheldLightPowerStates.Dying:
animationPlayer.Stop("radiatingLight");
animationPlayer.AnimationCompleted -= _radiatingCallback;
if (!animationPlayer.HasRunningAnimation("blinkingLight"))
{
animationPlayer.Play(_blinkingLightAnimation, "blinkingLight");
_blinkingCallback = (s) => animationPlayer.Play(_blinkingLightAnimation, s);
animationPlayer.AnimationCompleted += _blinkingCallback;
}
break;
case HandheldLightPowerStates.FullPower:
if (animationPlayer.HasRunningAnimation("blinkingLight"))
{
animationPlayer.Stop("blinkingLight");
animationPlayer.AnimationCompleted -= _blinkingCallback;
}
if (animationPlayer.HasRunningAnimation("radiatingLight"))
{
animationPlayer.Stop("radiatingLight");
animationPlayer.AnimationCompleted -= _radiatingCallback;
}
break;
}
}
}
}

View File

@@ -0,0 +1,142 @@
#nullable enable
using System;
using Content.Shared.Light;
using JetBrains.Annotations;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Client.Light.Visualizers
{
[UsedImplicitly]
public class PoweredLightVisualizer : AppearanceVisualizer
{
[DataField("minBlinkingTime")] private float _minBlinkingTime = 0.5f;
[DataField("maxBlinkingTime")] private float _maxBlinkingTime = 2;
[DataField("blinkingSound")] private string? _blinkingSound;
private bool _wasBlinking;
private Action<string>? _blinkingCallback;
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return;
if (!component.Owner.TryGetComponent(out PointLightComponent? light)) return;
if (!component.TryGetData(PoweredLightVisuals.BulbState, out PoweredLightState state)) return;
switch (state)
{
case PoweredLightState.Empty:
sprite.LayerSetState(PoweredLightLayers.Base, "empty");
ToggleBlinkingAnimation(component, false);
light.Enabled = false;
break;
case PoweredLightState.Off:
sprite.LayerSetState(PoweredLightLayers.Base, "off");
ToggleBlinkingAnimation(component, false);
light.Enabled = false;
break;
case PoweredLightState.On:
if (component.TryGetData(PoweredLightVisuals.BulbColor, out Color color))
light.Color = color;
if (component.TryGetData(PoweredLightVisuals.Blinking, out bool isBlinking))
ToggleBlinkingAnimation(component, isBlinking);
if (!isBlinking)
{
sprite.LayerSetState(PoweredLightLayers.Base, "on");
light.Enabled = true;
}
break;
case PoweredLightState.Broken:
sprite.LayerSetState(PoweredLightLayers.Base, "broken");
ToggleBlinkingAnimation(component, false);
light.Enabled = false;
break;
case PoweredLightState.Burned:
sprite.LayerSetState(PoweredLightLayers.Base, "burn");
ToggleBlinkingAnimation(component, false);
light.Enabled = false;
break;
}
}
private void ToggleBlinkingAnimation(AppearanceComponent component, bool isBlinking)
{
if (isBlinking == _wasBlinking)
return;
_wasBlinking = isBlinking;
component.Owner.EnsureComponent(out AnimationPlayerComponent animationPlayer);
if (isBlinking)
{
_blinkingCallback = (animName) => animationPlayer.Play(BlinkingAnimation(), "blinking");
animationPlayer.AnimationCompleted += _blinkingCallback;
animationPlayer.Play(BlinkingAnimation(), "blinking");
}
else if (animationPlayer.HasRunningAnimation("blinking"))
{
if (_blinkingCallback != null)
animationPlayer.AnimationCompleted -= _blinkingCallback;
animationPlayer.Stop("blinking");
}
}
private Animation BlinkingAnimation()
{
var random = IoCManager.Resolve<IRobustRandom>();
var randomTime = random.NextFloat() *
(_maxBlinkingTime - _minBlinkingTime) + _minBlinkingTime;
var blinkingAnim = new Animation()
{
Length = TimeSpan.FromSeconds(randomTime),
AnimationTracks =
{
new AnimationTrackComponentProperty
{
ComponentType = typeof(PointLightComponent),
InterpolationMode = AnimationInterpolationMode.Nearest,
Property = nameof(PointLightComponent.Enabled),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(false, 0),
new AnimationTrackProperty.KeyFrame(true, 1)
}
},
new AnimationTrackSpriteFlick()
{
LayerKey = PoweredLightLayers.Base,
KeyFrames =
{
new AnimationTrackSpriteFlick.KeyFrame("off", 0),
new AnimationTrackSpriteFlick.KeyFrame("on", 0.5f)
}
}
}
};
if (_blinkingSound != null)
{
blinkingAnim.AnimationTracks.Add(new AnimationTrackPlaySound()
{
KeyFrames =
{
new AnimationTrackPlaySound.KeyFrame(_blinkingSound, 0.5f)
}
});
}
return blinkingAnim;
}
}
}