Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

апстрим 14/10/2024 #131

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/Resources/engineCommandPerms.yml @moonheart08 @Chief-Engineer
/Resources/clientCommandPerms.yml @moonheart08 @Chief-Engineer

/Resources/Prototypes/Maps/ @Emisse
/Resources/Prototypes/Maps/** @Emisse

/Resources/Prototypes/Body/ @DrSmugleaf # suffering
/Resources/Prototypes/Entities/Mobs/Player/ @DrSmugleaf
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public void ReloadHandButtons()
OnPlayerHandsAdded?.Invoke(hands);
}

public override void DoDrop(EntityUid uid, Hand hand, bool doDropInteraction = true, HandsComponent? hands = null)
public override void DoDrop(EntityUid uid, Hand hand, bool doDropInteraction = true, HandsComponent? hands = null, bool log = true)
{
base.DoDrop(uid, hand, doDropInteraction, hands);
base.DoDrop(uid, hand, doDropInteraction, hands, log);

if (TryComp(hand.HeldEntity, out SpriteComponent? sprite))
sprite.RenderOrder = EntityManager.CurrentTick.Value;
Expand Down
11 changes: 1 addition & 10 deletions Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void PopulatePlaytimeData()
{
var overallPlaytime = _jobRequirementsManager.FetchOverallPlaytime();

var formattedPlaytime = ConvertTimeSpanToHoursMinutes(overallPlaytime);
var formattedPlaytime = overallPlaytime.ToString(Loc.GetString("ui-playtime-time-format"));
OverallPlaytimeLabel.Text = Loc.GetString("ui-playtime-overall", ("time", formattedPlaytime));

var rolePlaytimes = _jobRequirementsManager.FetchPlaytimeByRoles();
Expand Down Expand Up @@ -134,13 +134,4 @@ private void AddRolePlaytimeEntryToTable(string role, string playtimeString)
_sawmill.Error($"The provided playtime string '{playtimeString}' is not in the correct format.");
}
}

private static string ConvertTimeSpanToHoursMinutes(TimeSpan timeSpan)
{
var hours = (int) timeSpan.TotalHours;
var minutes = timeSpan.Minutes;

var formattedTimeLoc = Loc.GetString("ui-playtime-time-format", ("hours", hours), ("minutes", minutes));
return formattedTimeLoc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ private void ClientOnRunLevelChanged(object? sender, RunLevelChangedEventArgs e)
{
// Reset on disconnect, just in case.
_roles.Clear();
_jobWhitelists.Clear();
_roleBans.Clear();
}
}

private void RxRoleBans(MsgRoleBans message)
{
_sawmill.Debug($"Received roleban info containing {message.Bans.Count} entries.");

if (_roleBans.Equals(message.Bans))
return;

_roleBans.Clear();
_roleBans.AddRange(message.Bans);
Updated?.Invoke();
Expand Down
32 changes: 30 additions & 2 deletions Content.IntegrationTests/Pair/TestPair.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,41 @@ public async Task WaitClientCommand(string cmd, int numTicks = 10)
/// <summary>
/// Retrieve all entity prototypes that have some component.
/// </summary>
public List<EntityPrototype> GetPrototypesWithComponent<T>(
public List<(EntityPrototype, T)> GetPrototypesWithComponent<T>(
HashSet<string>? ignored = null,
bool ignoreAbstract = true,
bool ignoreTestPrototypes = true)
where T : IComponent
{
var id = Server.ResolveDependency<IComponentFactory>().GetComponentName(typeof(T));
var list = new List<(EntityPrototype, T)>();
foreach (var proto in Server.ProtoMan.EnumeratePrototypes<EntityPrototype>())
{
if (ignored != null && ignored.Contains(proto.ID))
continue;

if (ignoreAbstract && proto.Abstract)
continue;

if (ignoreTestPrototypes && IsTestPrototype(proto))
continue;

if (proto.Components.TryGetComponent(id, out var cmp))
list.Add((proto, (T)cmp));
}

return list;
}

/// <summary>
/// Retrieve all entity prototypes that have some component.
/// </summary>
public List<EntityPrototype> GetPrototypesWithComponent(Type type,
HashSet<string>? ignored = null,
bool ignoreAbstract = true,
bool ignoreTestPrototypes = true)
{
var id = Server.ResolveDependency<IComponentFactory>().GetComponentName(type);
var list = new List<EntityPrototype>();
foreach (var proto in Server.ProtoMan.EnumeratePrototypes<EntityPrototype>())
{
Expand All @@ -127,7 +155,7 @@ public List<EntityPrototype> GetPrototypesWithComponent<T>(
continue;

if (proto.Components.ContainsKey(id))
list.Add(proto);
list.Add((proto));
}

return list;
Expand Down
95 changes: 95 additions & 0 deletions Content.IntegrationTests/Tests/Minds/RoleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System.Linq;
using Content.Server.Roles;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
using Robust.Shared.GameObjects;
using Robust.Shared.Reflection;

namespace Content.IntegrationTests.Tests.Minds;

[TestFixture]
public sealed class RoleTests
{
/// <summary>
/// Check that any prototype with a <see cref="MindRoleComponent"/> is properly configured
/// </summary>
[Test]
public async Task ValidateRolePrototypes()
{
await using var pair = await PoolManager.GetServerClient();

var jobComp = pair.Server.ResolveDependency<IComponentFactory>().GetComponentName(typeof(JobRoleComponent));

Assert.Multiple(() =>
{
foreach (var (proto, comp) in pair.GetPrototypesWithComponent<MindRoleComponent>())
{
Assert.That(comp.AntagPrototype == null || comp.JobPrototype == null, $"Role {proto.ID} has both a job and antag prototype.");
Assert.That(!comp.ExclusiveAntag || comp.Antag, $"Role {proto.ID} is marked as an exclusive antag, despite not being an antag.");
Assert.That(comp.Antag || comp.AntagPrototype == null, $"Role {proto.ID} has an antag prototype, despite not being an antag.");

if (comp.JobPrototype != null)
Assert.That(proto.Components.ContainsKey(jobComp), $"Role {proto.ID} is a job, despite not having a job prototype.");

// It is possible that this is meant to be supported? Though I would assume that it would be for
// admin / prototype uploads, and that pre-defined roles should still check this.
Assert.That(!comp.Antag || comp.AntagPrototype != null , $"Role {proto.ID} is an antag, despite not having a antag prototype.");
}
});

await pair.CleanReturnAsync();
}

/// <summary>
/// Check that any prototype with a <see cref="JobRoleComponent"/> also has a properly configured
/// <see cref="MindRoleComponent"/>
/// </summary>
[Test]
public async Task ValidateJobPrototypes()
{
await using var pair = await PoolManager.GetServerClient();

var mindCompId = pair.Server.ResolveDependency<IComponentFactory>().GetComponentName(typeof(MindRoleComponent));

Assert.Multiple(() =>
{
foreach (var (proto, comp) in pair.GetPrototypesWithComponent<JobRoleComponent>())
{
if (proto.Components.TryGetComponent(mindCompId, out var mindComp))
Assert.That(((MindRoleComponent)mindComp).JobPrototype, Is.Not.Null);
}
});

await pair.CleanReturnAsync();
}

/// <summary>
/// Check that any prototype with a component that inherits from <see cref="BaseMindRoleComponent"/> also has a
/// <see cref="MindRoleComponent"/>
/// </summary>
[Test]
public async Task ValidateRolesHaveMindRoleComp()
{
await using var pair = await PoolManager.GetServerClient();

var refMan = pair.Server.ResolveDependency<IReflectionManager>();
var mindCompId = pair.Server.ResolveDependency<IComponentFactory>().GetComponentName(typeof(MindRoleComponent));

var compTypes = refMan.GetAllChildren(typeof(BaseMindRoleComponent))
.Append(typeof(RoleBriefingComponent))
.Where(x => !x.IsAbstract);

Assert.Multiple(() =>
{
foreach (var comp in compTypes)
{
foreach (var proto in pair.GetPrototypesWithComponent(comp))
{
Assert.That(proto.Components.ContainsKey(mindCompId), $"Role {proto.ID} does not have a {nameof(MindRoleComponent)} despite having a {comp.Name}");
}
}
});

await pair.CleanReturnAsync();
}
}
2 changes: 1 addition & 1 deletion Content.IntegrationTests/Tests/Sprite/ItemSpriteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task AllItemsHaveSpritesTest()

await pair.Client.WaitPost(() =>
{
foreach (var proto in pair.GetPrototypesWithComponent<ItemComponent>(Ignored))
foreach (var (proto, _) in pair.GetPrototypesWithComponent<ItemComponent>(Ignored))
{
var dummy = pair.Client.EntMan.Spawn(proto.ID);
pair.Client.EntMan.RunMapInit(dummy, pair.Client.MetaData(dummy));
Expand Down
7 changes: 2 additions & 5 deletions Content.IntegrationTests/Tests/StorageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ public async Task TestSufficientSpaceForFill()

await Assert.MultipleAsync(async () =>
{
foreach (var proto in pair.GetPrototypesWithComponent<StorageFillComponent>())
foreach (var (proto, fill) in pair.GetPrototypesWithComponent<StorageFillComponent>())
{
if (proto.HasComponent<EntityStorageComponent>(compFact))
continue;

StorageComponent? storage = null;
ItemComponent? item = null;
StorageFillComponent fill = default!;
var size = 0;
await server.WaitAssertion(() =>
{
Expand All @@ -112,7 +111,6 @@ await server.WaitAssertion(() =>
}

proto.TryGetComponent("Item", out item);
fill = (StorageFillComponent) proto.Components[id].Component;
size = GetFillSize(fill, false, protoMan, itemSys);
});

Expand Down Expand Up @@ -179,7 +177,7 @@ public async Task TestSufficientSpaceForEntityStorageFill()

var itemSys = entMan.System<SharedItemSystem>();

foreach (var proto in pair.GetPrototypesWithComponent<StorageFillComponent>())
foreach (var (proto, fill) in pair.GetPrototypesWithComponent<StorageFillComponent>())
{
if (proto.HasComponent<StorageComponent>(compFact))
continue;
Expand All @@ -192,7 +190,6 @@ await server.WaitAssertion(() =>
if (entStorage == null)
return;

var fill = (StorageFillComponent) proto.Components[id].Component;
var size = GetFillSize(fill, true, protoMan, itemSys);
Assert.That(size, Is.LessThanOrEqualTo(entStorage.Capacity),
$"{proto.ID} storage fill is too large.");
Expand Down
Loading
Loading