Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
beck-thompson committed Jan 9, 2025
1 parent 6c20cd9 commit 3a3ca66
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 7 deletions.
80 changes: 80 additions & 0 deletions Content.Server/_DV/FeedbackPopup/FeedbackPopupCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Linq;
using Content.Server.Administration;
using Content.Shared._DV.FeedbackOverwatch;
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;

namespace Content.Server._DV.FeedbackPopup;

[AdminCommand(AdminFlags.Server)]
public sealed class FeedbackPopupCommand : IConsoleCommand
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IEntityManager _entities = default!;

private SharedFeedbackOverwatchSystem? _feedback;

public string Command => Loc.GetString("feedbackpopup-command-name");
public string Description => Loc.GetString("feedbackpopup-command-description");
public string Help => Loc.GetString("feedbackpopup-command-help", ("command", Command));

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("feedbackpopup-command-error-wrong-arguments"));
return;
}

if (!int.TryParse(args[0], out var entityUidInt))
{
shell.WriteError(Loc.GetString("feedbackpopup-command-error-invalid-uid"));
return;
}

var netEnt = new NetEntity(entityUidInt);

if (!_entities.TryGetEntity(netEnt, out var target))
{
shell.WriteLine(Loc.GetString("feedbackpopup-command-error-entity-not-found"));
return;
}

if (!_proto.HasIndex<FeedbackPopupPrototype>(args[1]))
{
shell.WriteError(Loc.GetString("feedbackpopup-command-error-invalid-proto"));
return;
}

_feedback ??= _entities.System<SharedFeedbackOverwatchSystem>();

if (!_feedback.SendPopup(target, args[1]))
{
shell.WriteError(Loc.GetString("feedbackpopup-command-error-popup-send-fail"));
return;
}

shell.WriteLine(Loc.GetString("feedbackpopup-command-success"));
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHint(Loc.GetString("feedbackpopup-command-hint-playerUid"));
}

if (args.Length == 2)
{
var options = _proto
.EnumeratePrototypes<FeedbackPopupPrototype>()
.OrderBy(p => p.ID)
.Select(p => p.ID);

return CompletionResult.FromHintOptions(options, Loc.GetString("feedbackpopup-command-hint-protoId"));
}

return CompletionResult.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,34 @@ public override void Initialize()
/// </summary>
/// <param name="uid">UID of the entity the player is controlling.</param>
/// <param name="popupPrototype">Popup to send them.</param>
public void SendPopup(EntityUid? uid, ProtoId<FeedbackPopupPrototype> popupPrototype)
/// <returns>Returns true if the popup message was sent to the client successfully.</returns>
public bool SendPopup(EntityUid? uid, ProtoId<FeedbackPopupPrototype> popupPrototype)
{
if (uid == null)
return;
return false;

if (!_mind.TryGetMind(uid.Value, out var mindUid, out _))
return;
return false;

SendPopupMind(mindUid, popupPrototype);
return SendPopupMind(mindUid, popupPrototype);
}

/// <summary>
/// Send a popup to the given client controlling the given mind.
/// </summary>
/// <param name="uid">UID of the players mind.</param>
/// <param name="popupPrototype">Popup to send them.</param>
public void SendPopupMind(EntityUid? uid, ProtoId<FeedbackPopupPrototype> popupPrototype)
/// <returns>Returns true if the popup message was sent to the client successfully.</returns>
public bool SendPopupMind(EntityUid? uid, ProtoId<FeedbackPopupPrototype> popupPrototype)
{
if (uid == null)
return;
return false;

if (!_mind.TryGetSession(uid, out var session))
return;
return false;

var msg = new FeedbackPopupMessage(popupPrototype);
RaiseNetworkEvent(msg, session);
return true;
}
}
15 changes: 15 additions & 0 deletions Resources/Locale/en-US/_DV/feedbackpopup/feedbackpopup.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ feedbackpopup-discord-format-header = ```[Round number: {$roundNumber}, Player n
feedbackpopup-discord-format-info = Feedback name: **{$feedbackName}**
feedbackpopup-discord-format-spacer = ---- Feedback start ----
feedbackpopup-discord-format-feedbackbody = {$feedback}
# Command strings
feedbackpopup-command-name = givefeedbackpopup
feedbackpopup-command-description = Gives the targeted player a feedback popup.
feedbackpopup-command-help = Usage: {$command} <playerUid> <prototypeId>
feedbackpopup-command-error-wrong-arguments = Wrong number of arguments.
feedbackpopup-command-error-invalid-uid = Invalid entity uid.
feedbackpopup-command-error-entity-not-found = Couldn't find entity.
feedbackpopup-command-error-invalid-proto = Invalid feedback popup prototype.
feedbackpopup-command-error-popup-send-fail = Couldn't send popup. There probably isn't a mind attached to the given entity.
feedbackpopup-command-success = Sent popup!
feedbackpopup-command-hint-playerUid = <playerUid>
feedbackpopup-command-hint-protoId = <prototypeId>

0 comments on commit 3a3ca66

Please sign in to comment.