Skip to content

Commit

Permalink
Add description of tool qualities to entity (#32436)
Browse files Browse the repository at this point in the history
* Add description of tool qualities to entity

* LMAO I FORGOT FUCKING FTL FILE

* minor cleanup

---------

Co-authored-by: slarticodefast <[email protected]>
  • Loading branch information
lzk228 and slarticodefast authored Dec 20, 2024
1 parent bbceffa commit 919fdc0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Content.Shared/Tools/Systems/SharedToolSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Shared.Administration.Logs;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Item.ItemToggle;
using Content.Shared.Maps;
Expand Down Expand Up @@ -41,6 +42,7 @@ public override void Initialize()
InitializeTile();
InitializeWelder();
SubscribeLocalEvent<ToolComponent, ToolDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<ToolComponent, ExaminedEvent>(OnExamine);
}

private void OnDoAfter(EntityUid uid, ToolComponent tool, ToolDoAfterEvent args)
Expand All @@ -57,6 +59,34 @@ private void OnDoAfter(EntityUid uid, ToolComponent tool, ToolDoAfterEvent args)
RaiseLocalEvent((object) ev);
}

private void OnExamine(Entity<ToolComponent> ent, ref ExaminedEvent args)
{
// If the tool has no qualities, exit early
if (ent.Comp.Qualities.Count == 0)
return;

var message = new FormattedMessage();

// Create a list to store tool quality names
var toolQualities = new List<string>();

// Loop through tool qualities and add localized names to the list
foreach (var toolQuality in ent.Comp.Qualities)
{
if (_protoMan.TryIndex<ToolQualityPrototype>(toolQuality ?? string.Empty, out var protoToolQuality))
{
toolQualities.Add(Loc.GetString(protoToolQuality.Name));
}
}

// Combine the qualities into a single string and localize the final message
var qualitiesString = string.Join(", ", toolQualities);

// Add the localized message to the FormattedMessage object
message.AddMarkupPermissive(Loc.GetString("tool-component-qualities", ("qualities", qualitiesString)));
args.PushMessage(message);
}

public void PlayToolSound(EntityUid uid, ToolComponent tool, EntityUid? user)
{
if (tool.UseSound == null)
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/tools/components/tool-component.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool-component-qualities = This item can be used for [color=yellow]{ $qualities }[/color].

0 comments on commit 919fdc0

Please sign in to comment.