2023-10-05 22:15:03 -05:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2023-07-13 12:23:52 +02:00
|
|
|
using Content.Shared.Construction.NodeEntities;
|
|
|
|
|
using Content.Shared.Construction.Serialization;
|
2023-04-30 09:04:31 +12:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
|
|
|
namespace Content.Shared.Construction
|
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class ConstructionGraphNode
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("actions", serverOnly: true)]
|
ConstructionGL2 Part 1: ECSification, events and steps. (#5017)
- Completely rewrited the `ConstructionComponent` logic to be ECS, *without* looking too much at the original implementation.
- The original implementation was dirty and unmaintainable, whereas this new implementation is much cleaner, well-organized and maintainable. I've made sure to leave many comments around, explaining what everything does.
- Construction now has a framework for handling events other than `InteractUsing`.
- This means that you can now have CGL steps for things other than inserting items, using tools...
- Construction no longer uses `async` everywhere for `DoAfter`s. Instead it uses events.
- Construction event handling occurs in the `ConstructionSystem` update tick, instead of on event handlers.
- This ensures we can delete/modify entities without worrying about "collection modified while enumerating" exceptions.
- This also means the construction update tick is where all the fun happens, meaning it'll show up on our metrics and give us an idea of how expensive it is/how much tick time is spent in construction.
- `IGraphCondition` and `IGraphAction` have been refactored to take in `EntityUid`, `IEntityManager`, and to not be async.
- Removes nested steps, as they made maintainability significantly worse, and nothing used them yet.
- This fixes #4892 and fixes #4857
Please note, this leaves many things unchanged, as my idea is to split this into multiple PRs. Some unchanged things:
- Initial construction code is the same. In the future, it'll probably use dummy entities.
- Client-side guided steps are the same. In the future, the server will generate the guided steps and send them to clients as needed, caching these in both the server and client to save cycles and bandwidth.
- No new construction graph steps... Yet! :eyes:
2021-10-26 16:38:03 +02:00
|
|
|
private IGraphAction[] _actions = Array.Empty<IGraphAction>();
|
2021-03-15 21:55:49 +01:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("edges")]
|
ConstructionGL2 Part 1: ECSification, events and steps. (#5017)
- Completely rewrited the `ConstructionComponent` logic to be ECS, *without* looking too much at the original implementation.
- The original implementation was dirty and unmaintainable, whereas this new implementation is much cleaner, well-organized and maintainable. I've made sure to leave many comments around, explaining what everything does.
- Construction now has a framework for handling events other than `InteractUsing`.
- This means that you can now have CGL steps for things other than inserting items, using tools...
- Construction no longer uses `async` everywhere for `DoAfter`s. Instead it uses events.
- Construction event handling occurs in the `ConstructionSystem` update tick, instead of on event handlers.
- This ensures we can delete/modify entities without worrying about "collection modified while enumerating" exceptions.
- This also means the construction update tick is where all the fun happens, meaning it'll show up on our metrics and give us an idea of how expensive it is/how much tick time is spent in construction.
- `IGraphCondition` and `IGraphAction` have been refactored to take in `EntityUid`, `IEntityManager`, and to not be async.
- Removes nested steps, as they made maintainability significantly worse, and nothing used them yet.
- This fixes #4892 and fixes #4857
Please note, this leaves many things unchanged, as my idea is to split this into multiple PRs. Some unchanged things:
- Initial construction code is the same. In the future, it'll probably use dummy entities.
- Client-side guided steps are the same. In the future, the server will generate the guided steps and send them to clients as needed, caching these in both the server and client to save cycles and bandwidth.
- No new construction graph steps... Yet! :eyes:
2021-10-26 16:38:03 +02:00
|
|
|
private ConstructionGraphEdge[] _edges = Array.Empty<ConstructionGraphEdge>();
|
2020-10-08 17:41:23 +02:00
|
|
|
|
2021-03-15 21:55:49 +01:00
|
|
|
[DataField("node", required: true)]
|
|
|
|
|
public string Name { get; private set; } = default!;
|
2020-10-08 17:41:23 +02:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public IReadOnlyList<ConstructionGraphEdge> Edges => _edges;
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public IReadOnlyList<IGraphAction> Actions => _actions;
|
|
|
|
|
|
2023-07-13 12:23:52 +02:00
|
|
|
[DataField("transform")]
|
|
|
|
|
public IGraphTransform[] TransformLogic = Array.Empty<IGraphTransform>();
|
|
|
|
|
|
|
|
|
|
[DataField("entity", customTypeSerializer: typeof(GraphNodeEntitySerializer), serverOnly:true)]
|
|
|
|
|
public IGraphNodeEntity Entity { get; private set; } = new NullNodeEntity();
|
2020-10-08 17:41:23 +02:00
|
|
|
|
2023-10-05 22:15:03 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Ignore requests to change the entity if the entity's current prototype inherits from specified replacement
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// When this bool is true and a construction node specifies that the current entity should be replaced with a new entity, if the
|
|
|
|
|
/// current entity has an entity prototype which inherits from the replacement entity prototype, entity replacement will not occur.
|
|
|
|
|
/// E.g., if an entity with the 'AirlockCommand' prototype was to be replaced with a new entity that had the 'Airlock' prototype,
|
|
|
|
|
/// and 'DoNotReplaceInheritingEntities' was true, the entity would not be replaced because 'AirlockCommand' is derived from 'Airlock'
|
|
|
|
|
/// This will largely be used for construction graphs which have removeable upgrades, such as hacking protections for airlocks,
|
|
|
|
|
/// so that the upgrades can be removed and you can return to the last primary construction step without replacing the entity
|
|
|
|
|
/// </remarks>
|
|
|
|
|
[DataField("doNotReplaceInheritingEntities")]
|
|
|
|
|
public bool DoNotReplaceInheritingEntities = false;
|
|
|
|
|
|
2021-03-15 21:55:49 +01:00
|
|
|
public ConstructionGraphEdge? GetEdge(string target)
|
2020-10-08 17:41:23 +02:00
|
|
|
{
|
|
|
|
|
foreach (var edge in _edges)
|
|
|
|
|
{
|
|
|
|
|
if (edge.Target == target)
|
|
|
|
|
return edge;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-03-15 21:55:49 +01:00
|
|
|
|
ConstructionGL2 Part 1: ECSification, events and steps. (#5017)
- Completely rewrited the `ConstructionComponent` logic to be ECS, *without* looking too much at the original implementation.
- The original implementation was dirty and unmaintainable, whereas this new implementation is much cleaner, well-organized and maintainable. I've made sure to leave many comments around, explaining what everything does.
- Construction now has a framework for handling events other than `InteractUsing`.
- This means that you can now have CGL steps for things other than inserting items, using tools...
- Construction no longer uses `async` everywhere for `DoAfter`s. Instead it uses events.
- Construction event handling occurs in the `ConstructionSystem` update tick, instead of on event handlers.
- This ensures we can delete/modify entities without worrying about "collection modified while enumerating" exceptions.
- This also means the construction update tick is where all the fun happens, meaning it'll show up on our metrics and give us an idea of how expensive it is/how much tick time is spent in construction.
- `IGraphCondition` and `IGraphAction` have been refactored to take in `EntityUid`, `IEntityManager`, and to not be async.
- Removes nested steps, as they made maintainability significantly worse, and nothing used them yet.
- This fixes #4892 and fixes #4857
Please note, this leaves many things unchanged, as my idea is to split this into multiple PRs. Some unchanged things:
- Initial construction code is the same. In the future, it'll probably use dummy entities.
- Client-side guided steps are the same. In the future, the server will generate the guided steps and send them to clients as needed, caching these in both the server and client to save cycles and bandwidth.
- No new construction graph steps... Yet! :eyes:
2021-10-26 16:38:03 +02:00
|
|
|
public int? GetEdgeIndex(string target)
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < _edges.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var edge = _edges[i];
|
|
|
|
|
if (edge.Target == target)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 21:55:49 +01:00
|
|
|
public bool TryGetEdge(string target, [NotNullWhen(true)] out ConstructionGraphEdge? edge)
|
|
|
|
|
{
|
|
|
|
|
return (edge = GetEdge(target)) != null;
|
|
|
|
|
}
|
2020-10-08 17:41:23 +02:00
|
|
|
}
|
|
|
|
|
}
|