Skip to content

Commit

Permalink
Add seen objects
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArturZh committed Nov 16, 2023
1 parent 161eb66 commit 3fca8d8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
14 changes: 12 additions & 2 deletions Content.Server/SS220/Photography/PhotoCameraSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ public override void Initialize()
SubscribeLocalEvent<PhotoCameraComponent, UseInHandEvent>(OnCameraActivate);
SubscribeLocalEvent<PhotoCameraComponent, GetVerbsEvent<Verb>>(OnVerb);
SubscribeLocalEvent<PhotoCameraComponent, ExaminedEvent>(OnCameraExamine);
SubscribeLocalEvent<PhotoComponent, ExaminedEvent>(OnPhotoExamine);
SubscribeLocalEvent<PhotoFilmComponent, AfterInteractEvent>(OnFilmUse);
SubscribeLocalEvent<PhotoFilmComponent, ExaminedEvent>(OnFilmExamine);
}

private void OnPhotoExamine(Entity<PhotoComponent> 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<PhotoCameraComponent> entity, ref GetVerbsEvent<Verb> args)
{
// standard interaction checks
Expand Down Expand Up @@ -122,13 +132,13 @@ private bool TryPhoto(Entity<PhotoCameraComponent> 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<PhotoComponent>(photoEntity.Value);
photoComp.PhotoID = id;
photoComp.SeenObjects = seenObjects;
Dirty(photoEntity.Value, photoComp);

return true;
Expand Down
27 changes: 16 additions & 11 deletions Content.Server/SS220/Photography/PhotoManager.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,16 +34,13 @@ public sealed class PhotoManager : EntitySystem
private Dictionary<string, PhotoData> _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<MapGridComponent>();

SubscribeNetworkEvent<PhotoDataRequest>(OnPhotoDataRequest);
Expand All @@ -53,16 +51,13 @@ public override void Shutdown()
{
base.Shutdown();
_photos.Clear();
_cfg.UnsubValueChanged(CVars.NetMaxUpdateRange, OnPvsRangeChanged);
}

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;
Expand All @@ -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<string>? 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);

Expand Down Expand Up @@ -176,6 +178,9 @@ private void OnPhotoDataRequest(PhotoDataRequest message, EntitySessionEventArgs
if (TryComp<HumanoidAppearanceComponent>(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
Expand Down Expand Up @@ -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;
}
}
14 changes: 9 additions & 5 deletions Content.Shared/SS220/Photography/PhotoComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ public sealed partial class PhotoComponent : Component, IPhotocopyableComponent
/// </summary>
[DataField, AutoNetworkedField]
public string PhotoID = "";
[DataField, AutoNetworkedField]
public List<string> SeenObjects = new();

public IPhotocopiedComponentData GetPhotocopiedData()
{
return new PhotoPhotocopiedData()
{
PhotoID = PhotoID
PhotoID = PhotoID,
SeenObjects = SeenObjects
};
}
}
Expand All @@ -32,17 +35,18 @@ public IPhotocopiedComponentData GetPhotocopiedData()
public sealed class PhotoPhotocopiedData : IPhotocopiedComponentData
{
public string PhotoID = "";
public List<string> SeenObjects = new();

public void RestoreFromData(EntityUid uid, Component someComponent)
{
if (someComponent is not PhotoComponent component)
return;

var entSys = IoCManager.Resolve<IEntityManager>();
var changed = PhotoID != component.PhotoID;
component.PhotoID = PhotoID;
if (changed)
entSys.Dirty(uid, component);
component.SeenObjects = SeenObjects;

var entSys = IoCManager.Resolve<IEntityManager>();
entSys.Dirty(uid, component);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Resources/Locale/ru-RU/ss220/photography/photo-component.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
photo-loading-text-label = Загрузка...
photo-failed-text-label = Не удалось загрузить фотографию.
photo-failed-text-label = Не удалось загрузить фотографию.
photo-component-seen-objects = На фото вы видите: {$seen}

0 comments on commit 3fca8d8

Please sign in to comment.