-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #739 from Roudenn/upstream-sync
Upstream sync
- Loading branch information
Showing
205 changed files
with
41,617 additions
and
24,727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Numerics; | ||
using Content.Shared.Mining.Components; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Enums; | ||
using Robust.Shared.Timing; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client.Mining; | ||
|
||
public sealed class MiningOverlay : Overlay | ||
{ | ||
[Dependency] private readonly IEntityManager _entityManager = default!; | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
private readonly EntityLookupSystem _lookup; | ||
private readonly SpriteSystem _sprite; | ||
private readonly TransformSystem _xform; | ||
|
||
private readonly EntityQuery<SpriteComponent> _spriteQuery; | ||
private readonly EntityQuery<TransformComponent> _xformQuery; | ||
|
||
public override OverlaySpace Space => OverlaySpace.WorldSpace; | ||
public override bool RequestScreenTexture => false; | ||
|
||
private readonly HashSet<Entity<MiningScannerViewableComponent>> _viewableEnts = new(); | ||
|
||
public MiningOverlay() | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
|
||
_lookup = _entityManager.System<EntityLookupSystem>(); | ||
_sprite = _entityManager.System<SpriteSystem>(); | ||
_xform = _entityManager.System<TransformSystem>(); | ||
|
||
_spriteQuery = _entityManager.GetEntityQuery<SpriteComponent>(); | ||
_xformQuery = _entityManager.GetEntityQuery<TransformComponent>(); | ||
} | ||
|
||
protected override void Draw(in OverlayDrawArgs args) | ||
{ | ||
var handle = args.WorldHandle; | ||
|
||
if (_player.LocalEntity is not { } localEntity || | ||
!_entityManager.TryGetComponent<MiningScannerViewerComponent>(localEntity, out var viewerComp)) | ||
return; | ||
|
||
if (viewerComp.LastPingLocation == null) | ||
return; | ||
|
||
var scaleMatrix = Matrix3Helpers.CreateScale(Vector2.One); | ||
|
||
_viewableEnts.Clear(); | ||
_lookup.GetEntitiesInRange(viewerComp.LastPingLocation.Value, viewerComp.ViewRange, _viewableEnts); | ||
foreach (var ore in _viewableEnts) | ||
{ | ||
if (!_xformQuery.TryComp(ore, out var xform) || | ||
!_spriteQuery.TryComp(ore, out var sprite)) | ||
continue; | ||
|
||
if (xform.MapID != args.MapId || !sprite.Visible) | ||
continue; | ||
|
||
if (!sprite.LayerMapTryGet(MiningScannerVisualLayers.Overlay, out var idx)) | ||
continue; | ||
var layer = sprite[idx]; | ||
|
||
if (layer.ActualRsi?.Path == null || layer.RsiState.Name == null) | ||
continue; | ||
|
||
var gridRot = xform.GridUid == null ? 0 : _xformQuery.CompOrNull(xform.GridUid.Value)?.LocalRotation ?? 0; | ||
var rotationMatrix = Matrix3Helpers.CreateRotation(gridRot); | ||
|
||
var worldMatrix = Matrix3Helpers.CreateTranslation(_xform.GetWorldPosition(xform)); | ||
var scaledWorld = Matrix3x2.Multiply(scaleMatrix, worldMatrix); | ||
var matty = Matrix3x2.Multiply(rotationMatrix, scaledWorld); | ||
handle.SetTransform(matty); | ||
|
||
var spriteSpec = new SpriteSpecifier.Rsi(layer.ActualRsi.Path, layer.RsiState.Name); | ||
var texture = _sprite.GetFrame(spriteSpec, TimeSpan.FromSeconds(layer.AnimationTime)); | ||
|
||
var animTime = (viewerComp.NextPingTime - _timing.CurTime).TotalSeconds; | ||
|
||
|
||
var alpha = animTime < viewerComp.AnimationDuration | ||
? 0 | ||
: (float) Math.Clamp((animTime - viewerComp.AnimationDuration) / viewerComp.AnimationDuration, 0f, 1f); | ||
var color = Color.White.WithAlpha(alpha); | ||
|
||
handle.DrawTexture(texture, -(Vector2) texture.Size / 2f / EyeManager.PixelsPerMeter, layer.Rotation, modulate: color); | ||
|
||
} | ||
handle.SetTransform(Matrix3x2.Identity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Content.Shared.Mining.Components; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Client.Mining; | ||
|
||
/// <summary> | ||
/// This handles the lifetime of the <see cref="MiningOverlay"/> for a given entity. | ||
/// </summary> | ||
public sealed class MiningOverlaySystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly IOverlayManager _overlayMan = default!; | ||
|
||
private MiningOverlay _overlay = default!; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<MiningScannerViewerComponent, ComponentInit>(OnInit); | ||
SubscribeLocalEvent<MiningScannerViewerComponent, ComponentShutdown>(OnShutdown); | ||
SubscribeLocalEvent<MiningScannerViewerComponent, LocalPlayerAttachedEvent>(OnPlayerAttached); | ||
SubscribeLocalEvent<MiningScannerViewerComponent, LocalPlayerDetachedEvent>(OnPlayerDetached); | ||
|
||
_overlay = new(); | ||
} | ||
|
||
private void OnPlayerAttached(Entity<MiningScannerViewerComponent> ent, ref LocalPlayerAttachedEvent args) | ||
{ | ||
_overlayMan.AddOverlay(_overlay); | ||
} | ||
|
||
private void OnPlayerDetached(Entity<MiningScannerViewerComponent> ent, ref LocalPlayerDetachedEvent args) | ||
{ | ||
_overlayMan.RemoveOverlay(_overlay); | ||
} | ||
|
||
private void OnInit(Entity<MiningScannerViewerComponent> ent, ref ComponentInit args) | ||
{ | ||
if (_player.LocalEntity == ent) | ||
{ | ||
_overlayMan.AddOverlay(_overlay); | ||
} | ||
} | ||
|
||
private void OnShutdown(Entity<MiningScannerViewerComponent> ent, ref ComponentShutdown args) | ||
{ | ||
if (_player.LocalEntity == ent) | ||
{ | ||
_overlayMan.RemoveOverlay(_overlay); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Content.Server/Materials/Components/ProduceMaterialExtractorComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Content.Shared.Chemistry.Reagent; | ||
using Content.Shared.Materials; | ||
using Robust.Shared.Audio; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.Materials.Components; | ||
|
||
/// <summary> | ||
/// This is used for a machine that turns produce into a specified material. | ||
/// </summary> | ||
[RegisterComponent, Access(typeof(ProduceMaterialExtractorSystem))] | ||
public sealed partial class ProduceMaterialExtractorComponent : Component | ||
{ | ||
/// <summary> | ||
/// The material that produce is converted into | ||
/// </summary> | ||
[DataField] | ||
public ProtoId<MaterialPrototype> ExtractedMaterial = "Biomass"; | ||
|
||
/// <summary> | ||
/// List of reagents that determines how much material is yielded from a produce. | ||
/// </summary> | ||
[DataField] | ||
public List<ProtoId<ReagentPrototype>> ExtractionReagents = new() | ||
{ | ||
"Nutriment" | ||
}; | ||
|
||
[DataField] | ||
public SoundSpecifier? ExtractSound = new SoundPathSpecifier("/Audio/Effects/waterswirl.ogg"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Content.Server/Materials/ProduceMaterialExtractorSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Linq; | ||
using Content.Server.Botany.Components; | ||
using Content.Server.Materials.Components; | ||
using Content.Server.Power.EntitySystems; | ||
using Content.Shared.Chemistry.EntitySystems; | ||
using Content.Shared.Interaction; | ||
using Robust.Server.Audio; | ||
|
||
namespace Content.Server.Materials; | ||
|
||
public sealed class ProduceMaterialExtractorSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly AudioSystem _audio = default!; | ||
[Dependency] private readonly MaterialStorageSystem _materialStorage = default!; | ||
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<ProduceMaterialExtractorComponent, AfterInteractUsingEvent>(OnInteractUsing); | ||
} | ||
|
||
private void OnInteractUsing(Entity<ProduceMaterialExtractorComponent> ent, ref AfterInteractUsingEvent args) | ||
{ | ||
if (args.Handled) | ||
return; | ||
|
||
if (!this.IsPowered(ent, EntityManager)) | ||
return; | ||
|
||
if (!TryComp<ProduceComponent>(args.Used, out var produce)) | ||
return; | ||
|
||
if (!_solutionContainer.TryGetSolution(args.Used, produce.SolutionName, out var solution)) | ||
return; | ||
|
||
// Can produce even have fractional amounts? Does it matter if they do? | ||
// Questions man was never meant to answer. | ||
var matAmount = solution.Value.Comp.Solution.Contents | ||
.Where(r => ent.Comp.ExtractionReagents.Contains(r.Reagent.Prototype)) | ||
.Sum(r => r.Quantity.Float()); | ||
_materialStorage.TryChangeMaterialAmount(ent, ent.Comp.ExtractedMaterial, (int) matAmount); | ||
|
||
_audio.PlayPvs(ent.Comp.ExtractSound, ent); | ||
QueueDel(args.Used); | ||
args.Handled = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.