Skip to content

Commit

Permalink
Fix Toolshed Crash (#1415)
Browse files Browse the repository at this point in the history
I'm not fully confident in this fix, I can't test it right now.
closes #1409 1409

---------

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
  • Loading branch information
sleepyyapril and ElectroJr authored Jan 7, 2025
1 parent bac302c commit f026528
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
7 changes: 2 additions & 5 deletions Content.Server/Language/Commands/AdminLanguageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ public sealed class AdminLanguageCommand : ToolshedCommand
public EntityUid AddLanguage(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<LanguagePrototype>> @ref,
[CommandArgument] ProtoId<LanguagePrototype> language,
[CommandArgument] bool canSpeak = true,
[CommandArgument] bool canUnderstand = true
)
{
var language = @ref.Evaluate(ctx)!;

if (language == SharedLanguageSystem.UniversalPrototype)
{
EnsureComp<UniversalLanguageSpeakerComponent>(input);
Expand All @@ -45,12 +43,11 @@ public EntityUid AddLanguage(
public EntityUid RemoveLanguage(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<LanguagePrototype>> @ref,
[CommandArgument] ProtoId<LanguagePrototype> language,
[CommandArgument] bool removeSpeak = true,
[CommandArgument] bool removeUnderstand = true
)
{
var language = @ref.Evaluate(ctx)!;
if (language == SharedLanguageSystem.UniversalPrototype && HasComp<UniversalLanguageSpeakerComponent>(input))
{
RemComp<UniversalLanguageSpeakerComponent>(input);
Expand Down
12 changes: 4 additions & 8 deletions Content.Server/Language/Commands/AdminTranslatorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ public sealed class AdminTranslatorCommand : ToolshedCommand
public EntityUid AddLanguage(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<LanguagePrototype>> @ref,
[CommandArgument] ProtoId<LanguagePrototype> language,
[CommandArgument] bool addSpeak = true,
[CommandArgument] bool addUnderstand = true
)
{
var language = @ref.Evaluate(ctx)!;
// noob trap - needs a universallanguagespeakercomponent
if (language == SharedLanguageSystem.UniversalPrototype)
throw new ArgumentException(Loc.GetString("command-language-error-this-will-not-work"));
Expand All @@ -53,12 +52,11 @@ public EntityUid AddLanguage(
public EntityUid RemoveLanguage(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<LanguagePrototype>> @ref,
[CommandArgument] ProtoId<LanguagePrototype> language,
[CommandArgument] bool removeSpeak = true,
[CommandArgument] bool removeUnderstand = true
)
{
var language = @ref.Evaluate(ctx)!;
if (!TryGetTranslatorComp(input, out var translator))
throw new ArgumentException(Loc.GetString("command-language-error-not-a-translator", ("entity", input)));

Expand All @@ -76,9 +74,8 @@ public EntityUid RemoveLanguage(
public EntityUid AddRequiredLanguage(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<LanguagePrototype>> @ref)
[CommandArgument] ProtoId<LanguagePrototype> language)
{
var language = @ref.Evaluate(ctx)!;
if (!TryGetTranslatorComp(input, out var translator))
throw new ArgumentException(Loc.GetString("command-language-error-not-a-translator", ("entity", input)));

Expand All @@ -95,9 +92,8 @@ public EntityUid AddRequiredLanguage(
public EntityUid RemoveRequiredLanguage(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<LanguagePrototype>> @ref)
[CommandArgument] ProtoId<LanguagePrototype> language)
{
var language = @ref.Evaluate(ctx)!;
if (!TryGetTranslatorComp(input, out var translator))
throw new ArgumentException(Loc.GetString("command-language-error-not-a-translator", ("entity", input)));

Expand Down
28 changes: 11 additions & 17 deletions Content.Server/Station/Commands/JobsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Syntax;
using Robust.Shared.Toolshed.TypeParsers;
Expand All @@ -26,28 +27,24 @@ public IEnumerable<JobSlotRef> Jobs([PipedArgument] EntityUid station)
}

[CommandImplementation("jobs")]
public IEnumerable<JobSlotRef> Jobs([PipedArgument] IEnumerable<EntityUid> stations)
=> stations.SelectMany(Jobs);
public IEnumerable<JobSlotRef> Jobs([PipedArgument] IEnumerable<EntityUid> stations) => stations.SelectMany(Jobs);

[CommandImplementation("job")]
public JobSlotRef Job([PipedArgument] EntityUid station, Prototype<JobPrototype> job)
public JobSlotRef Job([PipedArgument] EntityUid station, ProtoId<JobPrototype> job)
{
_jobs ??= GetSys<StationJobsSystem>();

return new JobSlotRef(job.Value.ID, station, _jobs, EntityManager);
return new JobSlotRef(job, station, _jobs, EntityManager);
}

[CommandImplementation("job")]
public IEnumerable<JobSlotRef> Job([PipedArgument] IEnumerable<EntityUid> stations, Prototype<JobPrototype> job)
=> stations.Select(x => Job(x, job));
public IEnumerable<JobSlotRef> Job([PipedArgument] IEnumerable<EntityUid> stations, ProtoId<JobPrototype> job) => stations.Select(x => Job(x, job));

[CommandImplementation("isinfinite")]
public bool IsInfinite([PipedArgument] JobSlotRef job, [CommandInverted] bool inverted)
=> job.Infinite() ^ inverted;
public bool IsInfinite([PipedArgument] JobSlotRef job, [CommandInverted] bool inverted) => job.Infinite() ^ inverted;

[CommandImplementation("isinfinite")]
public IEnumerable<bool> IsInfinite([PipedArgument] IEnumerable<JobSlotRef> jobs, [CommandInverted] bool inverted)
=> jobs.Select(x => IsInfinite(x, inverted));
public IEnumerable<bool> IsInfinite([PipedArgument] IEnumerable<JobSlotRef> jobs, [CommandInverted] bool inverted) => jobs.Select(x => IsInfinite(x, inverted));

[CommandImplementation("adjust")]
public JobSlotRef Adjust([PipedArgument] JobSlotRef @ref, int by)
Expand All @@ -58,8 +55,7 @@ public JobSlotRef Adjust([PipedArgument] JobSlotRef @ref, int by)
}

[CommandImplementation("adjust")]
public IEnumerable<JobSlotRef> Adjust([PipedArgument] IEnumerable<JobSlotRef> @ref, int by)
=> @ref.Select(x => Adjust(x, by));
public IEnumerable<JobSlotRef> Adjust([PipedArgument] IEnumerable<JobSlotRef> @ref, int by) => @ref.Select(x => Adjust(x, by));


[CommandImplementation("set")]
Expand All @@ -71,20 +67,18 @@ public JobSlotRef Set([PipedArgument] JobSlotRef @ref, int by)
}

[CommandImplementation("set")]
public IEnumerable<JobSlotRef> Set([PipedArgument] IEnumerable<JobSlotRef> @ref, int by)
=> @ref.Select(x => Set(x, by));
public IEnumerable<JobSlotRef> Set([PipedArgument] IEnumerable<JobSlotRef> @ref, int by) => @ref.Select(x => Set(x, by));

[CommandImplementation("amount")]
public uint Amount([PipedArgument] JobSlotRef @ref)
{
_jobs ??= GetSys<StationJobsSystem>();
_jobs.TryGetJobSlot(@ref.Station, @ref.Job, out var slots);
return slots.HasValue ? slots.Value : 0;
return slots ?? 0;
}

[CommandImplementation("amount")]
public IEnumerable<uint> Amount([PipedArgument] IEnumerable<JobSlotRef> @ref)
=> @ref.Select(Amount);
public IEnumerable<uint> Amount([PipedArgument] IEnumerable<JobSlotRef> @ref) => @ref.Select(Amount);
}

// Used for Toolshed queries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public sealed class StationEventCommand : ToolshedCommand
/// to even exist) so I think it's fine.
/// </remarks>
[CommandImplementation("simulate")]
public IEnumerable<(string, float)> Simulate([CommandArgument] int rounds, [CommandArgument] int playerCount, [CommandArgument] float roundEndMean, [CommandArgument] float roundEndStdDev)
public IEnumerable<(string, float)> Simulate(EntityPrototype eventScheduler, int rounds, int playerCount, float roundEndMean, float roundEndStdDev)
{
_stationEvent ??= GetSys<EventManagerSystem>();
_basicScheduler ??= GetSys<BasicStationEventSchedulerSystem>();
Expand Down

0 comments on commit f026528

Please sign in to comment.