Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into upstream-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Morb0 committed Aug 2, 2023
2 parents d662450 + 11aa7e0 commit afcb4ea
Show file tree
Hide file tree
Showing 66 changed files with 1,307 additions and 865 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
namespace Content.Client.Bql;

[UsedImplicitly]
public sealed class BqlResultsEui : BaseEui
public sealed class ToolshedVisualizeEui : BaseEui
{
private readonly BqlResultsWindow _window;
private readonly ToolshedVisualizeWindow _window;

public BqlResultsEui()
public ToolshedVisualizeEui()
{
_window = new BqlResultsWindow(
_window = new ToolshedVisualizeWindow(
IoCManager.Resolve<IClientConsoleHost>(),
IoCManager.Resolve<ILocalizationManager>()
);
Expand All @@ -23,7 +23,7 @@ public BqlResultsEui()

public override void HandleState(EuiStateBase state)
{
if (state is not BqlResultsEuiState castState)
if (state is not ToolshedVisualizeEuiState castState)
return;

_window.Update(castState.Entities);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
namespace Content.Client.Bql;

[GenerateTypedNameReferences]
internal sealed partial class BqlResultsWindow : DefaultWindow
internal sealed partial class ToolshedVisualizeWindow : DefaultWindow
{
private readonly IClientConsoleHost _console;
private readonly ILocalizationManager _loc;

public BqlResultsWindow(IClientConsoleHost console, ILocalizationManager loc)
public ToolshedVisualizeWindow(IClientConsoleHost console, ILocalizationManager loc)
{
_console = console;
_loc = loc;
Expand Down
3 changes: 3 additions & 0 deletions Content.Client/Content.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<Compile Update="UserInterface\Systems\Inventory\Windows\StrippingWindow.xaml.cs">
<DependentUpon>StrippingWindow.xaml</DependentUpon>
</Compile>
<Compile Update="Bql\ToolshedVisualizeWindow.xaml.cs">
<DependentUpon>ToolshedVisualizeWindow.xaml</DependentUpon>
</Compile>
</ItemGroup>

<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
Expand Down
3 changes: 3 additions & 0 deletions Content.Client/Stylesheets/StyleNano.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public StyleNano(IResourceCache resCache) : base(resCache)
var notoSansBold16 = resCache.NotoStack(variation: "Bold", size: 16);
var notoSansBold18 = resCache.NotoStack(variation: "Bold", size: 18);
var notoSansBold20 = resCache.NotoStack(variation: "Bold", size: 20);
var notoSansMono = resCache.GetFont("/EngineFonts/NotoSans/NotoSansMono-Regular.ttf", size: 12);
var windowHeaderTex = resCache.GetTexture("/Textures/Interface/Nano/window_header.png");
var windowHeader = new StyleBoxTexture
{
Expand Down Expand Up @@ -512,6 +513,8 @@ public StyleNano(IResourceCache resCache) : base(resCache)

Stylesheet = new Stylesheet(BaseRules.Concat(new[]
{
Element().Class("monospace")
.Prop("font", notoSansMono),
// Window title.
new StyleRule(
new SelectorElement(typeof(Label), new[] {DefaultWindow.StyleClassWindowTitle}, null, null),
Expand Down
3 changes: 2 additions & 1 deletion Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Client.Items;
using Content.Client.Weapons.Ranged.Components;
using Content.Shared.Camera;
using Content.Shared.CombatMode;
using Content.Shared.Spawners.Components;
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
Expand Down Expand Up @@ -126,7 +127,7 @@ public override void Update(float frameTime)

var entityNull = _player.LocalPlayer?.ControlledEntity;

if (entityNull == null)
if (entityNull == null || !TryComp<CombatModeComponent>(entityNull, out var combat) || !combat.IsInCombatMode)
{
return;
}
Expand Down
6 changes: 4 additions & 2 deletions Content.IntegrationTests/Tests/Commands/RejuvenateTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Administration.Commands;
using Content.Server.Administration.Systems;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
Expand All @@ -11,7 +12,7 @@
namespace Content.IntegrationTests.Tests.Commands
{
[TestFixture]
[TestOf(typeof(RejuvenateCommand))]
[TestOf(typeof(RejuvenateSystem))]
public sealed class RejuvenateTest
{
private const string Prototypes = @"
Expand Down Expand Up @@ -42,6 +43,7 @@ public async Task RejuvenateDeadTest()
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
var mobStateSystem = entManager.EntitySysManager.GetEntitySystem<MobStateSystem>();
var damSystem = entManager.EntitySysManager.GetEntitySystem<DamageableSystem>();
var rejuvenateSystem = entManager.EntitySysManager.GetEntitySystem<RejuvenateSystem>();

await server.WaitAssertion(() =>
{
Expand Down Expand Up @@ -78,7 +80,7 @@ await server.WaitAssertion(() =>
});
// Rejuvenate them
RejuvenateCommand.PerformRejuvenate(human);
rejuvenateSystem.PerformRejuvenate(human);
// Check that it is alive and with no damage
Assert.Multiple(() =>
Expand Down
20 changes: 20 additions & 0 deletions Content.IntegrationTests/Tests/Toolshed/AdminTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Toolshed;

namespace Content.IntegrationTests.Tests.Toolshed;

[TestFixture]
public sealed class AdminTest : ToolshedTest
{
[Test]
public async Task AllCommandsHavePermissions()
{
await Server.WaitAssertion(() =>
{
Assert.That(InvokeCommand("cmd:list where { acmd:perms isnull }", out var res));
var list = ((IEnumerable<CommandSpec>) res).ToList();
Assert.That(list, Is.Empty, "All commands must have admin permissions set up.");
});
}
}
84 changes: 84 additions & 0 deletions Content.IntegrationTests/Tests/Toolshed/CommandParseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Syntax;
using Robust.Shared.Toolshed.TypeParsers;

namespace Content.IntegrationTests.Tests.Toolshed;

[TestFixture]
public sealed class CommandRunTest : ToolshedTest
{
[Test]
public async Task SimpleCommandRun()
{
await Server.WaitAssertion(() =>
{
ParseCommand("entities");
ParseCommand("entities select 1");
ParseCommand("entities with Item select 1");
ExpectError<OutOfInputError>();
ParseCommand("entities with");
ExpectError<NoImplementationError>();
ParseCommand("player:list with MetaData");
ExpectError<ExpressionOfWrongType>();
ParseCommand("player:list", expectedType: typeof(IEnumerable<EntityUid>));
ParseCommand("entities not with MetaData");
ParseCommand("with MetaData select 2 any", inputType: typeof(List<EntityUid>));
ParseCommand("entities not with MetaData => $myEntities");
ParseCommand("=> $fooBar with MetaData", inputType: typeof(List<EntityUid>));
});
}

[Test]
public async Task EntityUidTypeParser()
{
await Server.WaitAssertion(() =>
{
ParseCommand("ent 1");
ParseCommand("ent c1");
ExpectError<InvalidEntityUid>();
ParseCommand("ent foodigity");
});
}

[Test]
public async Task QuantityTypeParser()
{
await Server.WaitAssertion(() =>
{
ParseCommand("entities select 100");
ParseCommand("entities select 50%");
ExpectError<InvalidQuantity>();
ParseCommand("entities select -1");
ExpectError<InvalidQuantity>();
ParseCommand("entities select 200%");
ExpectError<InvalidQuantity>();
ParseCommand("entities select hotdog");
});
}

[Test]
public async Task ComponentTypeParser()
{
await Server.WaitAssertion(() =>
{
ParseCommand("entities with MetaData");
ExpectError<UnknownComponentError>();
ParseCommand("entities with Foodiddy");
ExpectError<UnknownComponentError>();
ParseCommand("entities with MetaDataComponent");
});
}
}
19 changes: 19 additions & 0 deletions Content.IntegrationTests/Tests/Toolshed/LocTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Toolshed;

namespace Content.IntegrationTests.Tests.Toolshed;

[TestFixture]
public sealed class LocTest : ToolshedTest
{
[Test]
public async Task AllCommandsHaveDescriptions()
{
await Server.WaitAssertion(() =>
{
Assert.That(InvokeCommand("cmd:list where { cmd:descloc loc:tryloc isnull }", out var res));
Assert.That((IEnumerable<CommandSpec>)res, Is.Empty, "All commands must have localized descriptions.");
});
}
}
153 changes: 153 additions & 0 deletions Content.IntegrationTests/Tests/Toolshed/ToolshedTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#nullable enable
using System.Collections.Generic;
using Content.Server.Administration.Managers;
using Robust.Server.Player;
using Robust.Shared.Players;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Errors;
using Robust.Shared.Toolshed.Syntax;
using Robust.UnitTesting;

namespace Content.IntegrationTests.Tests.Toolshed;

[TestFixture]
[FixtureLifeCycle(LifeCycle.SingleInstance)]
public abstract class ToolshedTest : IInvocationContext
{
protected PairTracker PairTracker = default!;

protected virtual bool NoClient => true;
protected virtual bool AssertOnUnexpectedError => true;

protected RobustIntegrationTest.ServerIntegrationInstance Server = default!;
protected RobustIntegrationTest.ClientIntegrationInstance? Client = null;
protected ToolshedManager Toolshed = default!;
protected IAdminManager AdminManager = default!;

protected IInvocationContext? Context = null;

[TearDown]
public virtual async Task TearDown()
{
Assert.IsEmpty(_expectedErrors);
ClearErrors();
}

[OneTimeSetUp]
public virtual async Task Setup()
{
PairTracker = await PoolManager.GetServerClient(new PoolSettings {NoClient = NoClient});
Server = PairTracker.Pair.Server;

if (!NoClient)
{
Client = PairTracker.Pair.Client;
await Client.WaitIdleAsync();
}

await Server.WaitIdleAsync();

Toolshed = Server.ResolveDependency<ToolshedManager>();
AdminManager = Server.ResolveDependency<IAdminManager>();
}

protected bool InvokeCommand(string command, out object? result, IPlayerSession? session = null)
{
return Toolshed.InvokeCommand(this, command, null, out result);
}

protected void ParseCommand(string command, Type? inputType = null, Type? expectedType = null, bool once = false)
{
var parser = new ForwardParser(command, Toolshed);
var success = CommandRun.TryParse(false, false, parser, inputType, expectedType, once, out _, out _, out var error);

if (error is not null)
ReportError(error);

if (error is null)
Assert.That(success, $"Parse failed despite no error being reported. Parsed {command}");
}

public bool CheckInvokable(CommandSpec command, out IConError? error)
{
if (Context is not null)
{
return Context.CheckInvokable(command, out error);
}

error = null;
return true;
}

protected IPlayerSession? InvocationSession { get; set; }

public ICommonSession? Session
{
get
{
if (Context is not null)
{
return Context.Session;
}

return InvocationSession;
}
}

public void WriteLine(string line)
{
return;
}

private Queue<Type> _expectedErrors = new();

private List<IConError> _errors = new();

public void ReportError(IConError err)
{
if (_expectedErrors.Count == 0)
{
if (AssertOnUnexpectedError)
{
Assert.Fail($"Got an error, {err.GetType()}, when none was expected.\n{err.Describe()}");
}

goto done;
}

var ty = _expectedErrors.Dequeue();

if (AssertOnUnexpectedError)
{
Assert.That(
err.GetType().IsAssignableTo(ty),
$"The error {err.GetType()} wasn't assignable to the expected type {ty}.\n{err.Describe()}"
);
}

done:
_errors.Add(err);
}

public IEnumerable<IConError> GetErrors()
{
return _errors;
}

public void ClearErrors()
{
_errors.Clear();
}

public Dictionary<string, object?> Variables { get; } = new();

protected void ExpectError(Type err)
{
_expectedErrors.Enqueue(err);
}

protected void ExpectError<T>()
{
_expectedErrors.Enqueue(typeof(T));
}
}
Loading

0 comments on commit afcb4ea

Please sign in to comment.