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

IPC Refactor #771

Merged
merged 7 commits into from
Sep 17, 2024
Merged

Conversation

VMSolidus
Copy link
Member

@VMSolidus VMSolidus commented Aug 21, 2024

Description

IPCs were ported from a codebase that didn't necessarily follow all of our repo's coding standards. And while I had done my part to cleanup as much of the system as was practical within the bounds of a Maintainer Review, there were a lot of things that I felt were inappropriate to leave to review, and wished to go over with a fine lense. Thus, here is my Refactor of IPC code.

Do not merge this without first testing that nothing was broken. Because I haven't tested it myself yet.

@github-actions github-actions bot added the Changes: C# Changes any cs files label Aug 21, 2024
@VMSolidus VMSolidus added Size: 3-Medium For medium issues/PRs Priority: 3-Medium Needs to be resolved at some point Status: Needs Review Someone please review this labels Aug 21, 2024

if (entityManager.HasComponent<EncryptionKeyHolderComponent>(target))
{
var encryption = new InternalEncryptionKeySpawner();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really a good approach to make a new instance of EntitySystem? You should use IoC instead.

|| !_silicon.TryGetSiliconBattery(uid, out var drinkerBatteryComponent)
|| !TryComp(uid, out PowerCellSlotComponent? batterySlot)
|| !TryComp<BatteryDrinkerSourceComponent>(args.Target.Value, out var sourceComp)
|| sourceComp is null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sourceComp can't be null since TryComp<BatteryDrinkerSourceComponent>(args.Target.Value, out var sourceComp) already checks for it.

Comment on lines 88 to 95
if (args.Cancelled || args.Target == null
|| !TryComp<BatteryComponent>(args.Target.Value, out var sourceBattery)
|| !_silicon.TryGetSiliconBattery(uid, out var drinkerBatteryComponent)
|| !TryComp(uid, out PowerCellSlotComponent? batterySlot)
|| !TryComp<BatteryDrinkerSourceComponent>(args.Target.Value, out var sourceComp)
|| sourceComp is null
|| !_container.TryGetContainer(uid, batterySlot.CellSlotId, out var container)
|| container.ContainedEntities is null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this checks should probably go in order from args.Target.Value checks to uid checks to increase readability.

if (!args.CanAccess || !args.CanInteract
|| !TryComp<BatteryDrinkerComponent>(args.User, out var drinkerComp)
|| !TestDrinkableBattery(uid, drinkerComp)
|| !_silicon.TryGetSiliconBattery(args.User, out var drinkerBattery))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out var drinkerBattery is not used anywhere in the code after you get it. You should either remove the check entirely or mark variable as not used (out _)

Comment on lines 34 to +35
if (args.User == uid
|| !TryComp<SiliconComponent>(uid, out var siliconComp))
|| !HasComp<SiliconComponent>(uid))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for the style - it should be on the same line since it's not that long.

{
if (args.Cancelled || args.Target == null
|| !TryComp<BlindableComponent>(args.Target, out var blindComp)
|| blindComp is { EyeDamage: 0 })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of pattern check you can directly check blindComp.EyeDamage == 0

public DamageSpecifier Damage;

[DataField(customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
public string QualityNeeded = "Welding";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customTypeSerializerbe can be removed and the variable type should be then changed to ProtoId<ToolQualityPrototype>

Comment on lines +28 to +36
if (args.Cancelled || args.Used == null
|| !TryComp<DamageableComponent>(args.Target, out var damageable)
|| !TryComp<WeldingHealingComponent>(args.Used, out var component)
|| damageable.DamageContainerID is null
|| !component.DamageContainers.Contains(damageable.DamageContainerID)
|| !HasDamage(damageable, component)
|| !TryComp<WelderComponent>(args.Used, out var welder)
|| !TryComp<SolutionContainerManagerComponent>(args.Used, out var solutionContainer)
|| !_solutionContainer.ResolveSolution(((EntityUid) args.Used, solutionContainer), welder.FuelSolutionName, ref welder.FuelSolution))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be probably better ordered. args.Used checks first, then args.Target.

Comment on lines +65 to +72
if (args.Handled
|| !EntityManager.TryGetComponent(args.Used, out WeldingHealingComponent? component)
|| !EntityManager.TryGetComponent(args.Target, out DamageableComponent? damageable)
|| damageable.DamageContainerID is null
|| !component.DamageContainers.Contains(damageable.DamageContainerID)
|| !HasDamage(damageable, component)
|| !_toolSystem.HasQuality(args.Used, component.QualityNeeded)
|| args.User == args.Target && !component.AllowSelfHeal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ordered too


if (!TryComp<PowerCellSlotComponent>(uid, out var cellSlotComp))
return;
args.Cancelled = !component.DoSiliconsDreamOfElectricSheep;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not do it like this. Either check if it's canceled first and return, or use &= instead of =

@FoxxoTrystan FoxxoTrystan requested review from FoxxoTrystan and removed request for DangerRevolution August 30, 2024 05:44
Copy link
Contributor

@Evgencheg Evgencheg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Waiting for merge

@FoxxoTrystan FoxxoTrystan added the Size: 2-Large For large issues/PRs label Sep 17, 2024
@VMSolidus VMSolidus merged commit a553909 into Simple-Station:master Sep 17, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changes: C# Changes any cs files Priority: 3-Medium Needs to be resolved at some point Size: 2-Large For large issues/PRs Size: 3-Medium For medium issues/PRs Status: Needs Review Someone please review this
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants