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

Separate crate machine from market system #2681

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

GreaseMonk
Copy link
Contributor

About the PR

  • Crate machine now separated from market system
  • Added MarketItemSpawnerComponent for spawning market items and moved ItemsToSpawn to it.
  • No change in code other than splitting up code and adding more documentation

Why / Balance

  • Allows crate machine to be used in other systems and makes it a reusable entity

How to test

Start a round and aghost
teleport to cargo depot
sell iron ore
buy iron ore at market console
check if animation is correct and items and crate spawn correctly
check if animation closes when moving crate off the crate hole.

Media

Requirements

Breaking changes

none

Changelog

Copy link
Contributor

@whatston3 whatston3 left a comment

Choose a reason for hiding this comment

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

Looked through this - one issue and one small gripe.
I think you could fire off events from the animation system itself instead of using delegates, seems closer to ECS and less OO.
I also think the CrateMachineVisualState could be scoped outside of the component.

Looks fine skimming it, will test briefly.

Copy link
Contributor

@whatston3 whatston3 left a comment

Choose a reason for hiding this comment

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

Put in a few small suggestions.

I would honestly recommend testing and pulling in https://github.com/new-frontiers-14/frontier-station-14/compare/rack-attack...whatston3:frontier-station-14:2025-01-20-rack-attack-suggestions?expand=1

Seems to work fine under modest tests.

Edit: The TransformSystem distance calc. is probably cleaner vs. Vector2, I'd recommend using that.

Comment on lines +83 to +85
var currentDistance = CalculateDistance(compXform.Coordinates, Transform(from).Coordinates);

var isTooFarAway = currentDistance > maxDistance;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var currentDistance = CalculateDistance(compXform.Coordinates, Transform(from).Coordinates);
var isTooFarAway = currentDistance > maxDistance;
var isTooFarAway = Vector2.Distance(compXform.Coordinates.Position, Transform(from).Coordinates.Position) > maxDistance;

Vector2 has a convenient function for this, and TransformSystem does too. I believe the snippet above should work - I also wrong a version using TransformSystem, which is even better since it'll handle weird parenting better - no false positives.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems odd to assign some conditions to variables when they're only used in an if statement but eh.

Comment on lines +45 to +59

/// <summary>
/// Calculates distance between two EntityCoordinates on the same grid.
/// Used to check for cargo pallets around the console instead of on the grid.
/// </summary>
/// <param name="point1">the first point</param>
/// <param name="point2">the second point</param>
/// <returns></returns>
private static double CalculateDistance(EntityCoordinates point1, EntityCoordinates point2)
{
var xDifference = point2.X - point1.X;
var yDifference = point2.Y - point1.Y;

return Math.Sqrt(xDifference * xDifference + yDifference * yDifference);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// <summary>
/// Calculates distance between two EntityCoordinates on the same grid.
/// Used to check for cargo pallets around the console instead of on the grid.
/// </summary>
/// <param name="point1">the first point</param>
/// <param name="point2">the second point</param>
/// <returns></returns>
private static double CalculateDistance(EntityCoordinates point1, EntityCoordinates point2)
{
var xDifference = point2.X - point1.X;
var yDifference = point2.Y - point1.Y;
return Math.Sqrt(xDifference * xDifference + yDifference * yDifference);
}

Just use Vector2.Distance.

/// </summary>
public sealed partial class CrateMachineSystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[Dependency] private readonly IEntityManager _entityManager = default!;

Shouldn't need this - why isn't this extending SharedCrateMachineSystem? EntitySystem should already has a reference in EntityManager.

/// When calling <see cref="OpenFor"/>, the machine will open the door and give a callback to the given
/// <see cref="ICrateMachineDelegate"/> when it is done opening.
/// </summary>
public sealed partial class CrateMachineSystem
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public sealed partial class CrateMachineSystem
public sealed partial class CrateMachineSystem : SharedCrateMachineSystem

Extend the shared version, add the needed import above?


public sealed class MarketSystem : SharedMarketSystem
public sealed class CrateMachineSystem: SharedCrateMachineSystem
Copy link
Contributor

@whatston3 whatston3 Jan 20, 2025

Choose a reason for hiding this comment

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

Suggested change
public sealed class CrateMachineSystem: SharedCrateMachineSystem
public sealed partial class CrateMachineSystem : SharedCrateMachineSystem

per https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods:
All the parts must use the partial keyword

Comment on lines +34 to 36
// Stop here if we don't have a grid.
if (Transform(consoleUid).GridUid == null)
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend pushing this into FindNearestUnoccupied.

using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using static Content.Shared._NF.Market.Components.CrateMachineComponent;
using CrateMachineComponent = Content.Shared._NF.CrateMachine.Components.CrateMachineComponent;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
using CrateMachineComponent = Content.Shared._NF.CrateMachine.Components.CrateMachineComponent;
using Content.Shared._NF.CrateMachine.Components;

@whatston3 whatston3 added the S: Awaiting Changes This PR has changes that need to be made before merging label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# S: Awaiting Changes This PR has changes that need to be made before merging YML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants