From 3fca8d89d42a72129a12e328b9ca0a5c48416429 Mon Sep 17 00:00:00 2001 From: TheArturZh Date: Thu, 16 Nov 2023 06:16:35 +0300 Subject: [PATCH] Add seen objects --- .../SS220/Photography/PhotoCameraSystem.cs | 14 ++++++++-- .../SS220/Photography/PhotoManager.cs | 27 +++++++++++-------- .../SS220/Photography/PhotoComponent.cs | 14 ++++++---- .../ss220/photography/photo-component.ftl | 3 ++- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Content.Server/SS220/Photography/PhotoCameraSystem.cs b/Content.Server/SS220/Photography/PhotoCameraSystem.cs index 752cd49b348e..79bab9630d16 100644 --- a/Content.Server/SS220/Photography/PhotoCameraSystem.cs +++ b/Content.Server/SS220/Photography/PhotoCameraSystem.cs @@ -25,10 +25,20 @@ public override void Initialize() SubscribeLocalEvent(OnCameraActivate); SubscribeLocalEvent>(OnVerb); SubscribeLocalEvent(OnCameraExamine); + SubscribeLocalEvent(OnPhotoExamine); SubscribeLocalEvent(OnFilmUse); SubscribeLocalEvent(OnFilmExamine); } + private void OnPhotoExamine(Entity entity, ref ExaminedEvent args) + { + if (entity.Comp.SeenObjects.Count == 0) + return; + + var seenFormatted = string.Join(", ", entity.Comp.SeenObjects.ToArray()); + args.PushMarkup(Loc.GetString("photo-component-seen-objects", ("seen", seenFormatted))); + } + private void OnVerb(Entity entity, ref GetVerbsEvent args) { // standard interaction checks @@ -122,13 +132,13 @@ private bool TryPhoto(Entity entity, [NotNullWhen(true)] o else cameraRotation = _transform.GetWorldRotation(xform); - var id = _photo.TryCapture(xform.MapPosition, cameraRotation, entity.Comp.SelectedPhotoDimensions); - if (id is null) + if (!_photo.TryCapture(xform.MapPosition, cameraRotation, entity.Comp.SelectedPhotoDimensions, out var id, out var seenObjects)) return false; photoEntity = Spawn(entity.Comp.PhotoPrototypeId, xform.MapPosition); var photoComp = EnsureComp(photoEntity.Value); photoComp.PhotoID = id; + photoComp.SeenObjects = seenObjects; Dirty(photoEntity.Value, photoComp); return true; diff --git a/Content.Server/SS220/Photography/PhotoManager.cs b/Content.Server/SS220/Photography/PhotoManager.cs index 03e2e1aa07b8..20ef10ad0ea2 100644 --- a/Content.Server/SS220/Photography/PhotoManager.cs +++ b/Content.Server/SS220/Photography/PhotoManager.cs @@ -1,4 +1,5 @@ // © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt +using System.Diagnostics.CodeAnalysis; using System.Numerics; using Content.Server.Decals; using Content.Server.Hands.Systems; @@ -33,16 +34,13 @@ public sealed class PhotoManager : EntitySystem private Dictionary _photos = new(); private ISawmill _sawmill = Logger.GetSawmill("photo-manager"); - private float _pvsRange = 10; + private float _photoRange = 10; //10 is the radius of average powered light public const float MAX_PHOTO_RADIUS = 20; public override void Initialize() { base.Initialize(); - _cfg.OnValueChanged(CVars.NetMaxUpdateRange, OnPvsRangeChanged, true); - _pvsRange = _cfg.GetCVar(CVars.NetMaxUpdateRange); - _gridQuery = EntityManager.GetEntityQuery(); SubscribeNetworkEvent(OnPhotoDataRequest); @@ -53,7 +51,6 @@ public override void Shutdown() { base.Shutdown(); _photos.Clear(); - _cfg.UnsubValueChanged(CVars.NetMaxUpdateRange, OnPvsRangeChanged); } public void OnRoundRestart(RoundRestartCleanupEvent args) @@ -61,8 +58,6 @@ public void OnRoundRestart(RoundRestartCleanupEvent args) _photos.Clear(); } - private void OnPvsRangeChanged(float value) => _pvsRange = value; - private void OnPhotoDataRequest(PhotoDataRequest message, EntitySessionEventArgs eventArgs) { var sender = eventArgs.SenderSession; @@ -77,12 +72,19 @@ private void OnPhotoDataRequest(PhotoDataRequest message, EntitySessionEventArgs RaiseNetworkEvent(ev, sender); } - public string? TryCapture(MapCoordinates focusCoords, Angle cameraRotation, float captureSize) + public bool TryCapture( + MapCoordinates focusCoords, + Angle cameraRotation, + float captureSize, + [NotNullWhen(true)] out string? id, + [NotNullWhen(true)] out List? seenObjects) { - var id = Guid.NewGuid().ToString(); + id = Guid.NewGuid().ToString(); + seenObjects = new(); var focusWorldPos = focusCoords.Position; + var captureSizeSquareHalf = (captureSize * captureSize) / 2; //for optimization purposes - var radius = MathF.Min(_pvsRange, MAX_PHOTO_RADIUS); //cap because scary + var radius = MathF.Min(_photoRange, MAX_PHOTO_RADIUS); //cap because scary var range = new Vector2(radius, radius); var worldArea = new Box2(focusWorldPos - range, focusWorldPos + range); @@ -176,6 +178,9 @@ private void OnPhotoDataRequest(PhotoDataRequest message, EntitySessionEventArgs if (TryComp(entity, out var humanoidAppearance)) { humanoidAppearanceState = EntityManager.GetComponentState(EntityManager.EventBus, humanoidAppearance, null, GameTick.Zero); + + if ((_transform.GetWorldPosition(entity) - focusWorldPos).LengthSquared() < captureSizeSquareHalf) + seenObjects.Add(Name(entity)); } // Point light state @@ -284,6 +289,6 @@ private void OnPhotoDataRequest(PhotoDataRequest message, EntitySessionEventArgs _photos.Add(id, data); _sawmill.Debug("Photo taken! Entity count: " + data.Entities.Count + ", Grid count: " + data.Grids.Count + ", ID: " + id); - return id; + return true; } } diff --git a/Content.Shared/SS220/Photography/PhotoComponent.cs b/Content.Shared/SS220/Photography/PhotoComponent.cs index 0a478721ab3f..54b8bed17ee4 100644 --- a/Content.Shared/SS220/Photography/PhotoComponent.cs +++ b/Content.Shared/SS220/Photography/PhotoComponent.cs @@ -18,12 +18,15 @@ public sealed partial class PhotoComponent : Component, IPhotocopyableComponent /// [DataField, AutoNetworkedField] public string PhotoID = ""; + [DataField, AutoNetworkedField] + public List SeenObjects = new(); public IPhotocopiedComponentData GetPhotocopiedData() { return new PhotoPhotocopiedData() { - PhotoID = PhotoID + PhotoID = PhotoID, + SeenObjects = SeenObjects }; } } @@ -32,17 +35,18 @@ public IPhotocopiedComponentData GetPhotocopiedData() public sealed class PhotoPhotocopiedData : IPhotocopiedComponentData { public string PhotoID = ""; + public List SeenObjects = new(); public void RestoreFromData(EntityUid uid, Component someComponent) { if (someComponent is not PhotoComponent component) return; - var entSys = IoCManager.Resolve(); - var changed = PhotoID != component.PhotoID; component.PhotoID = PhotoID; - if (changed) - entSys.Dirty(uid, component); + component.SeenObjects = SeenObjects; + + var entSys = IoCManager.Resolve(); + entSys.Dirty(uid, component); } } diff --git a/Resources/Locale/ru-RU/ss220/photography/photo-component.ftl b/Resources/Locale/ru-RU/ss220/photography/photo-component.ftl index a106bcc6f954..e9ac5ebb1f9f 100644 --- a/Resources/Locale/ru-RU/ss220/photography/photo-component.ftl +++ b/Resources/Locale/ru-RU/ss220/photography/photo-component.ftl @@ -1,2 +1,3 @@ photo-loading-text-label = Загрузка... -photo-failed-text-label = Не удалось загрузить фотографию. \ No newline at end of file +photo-failed-text-label = Не удалось загрузить фотографию. +photo-component-seen-objects = На фото вы видите: {$seen}