Solution Entities (#21916)
* Creates Content.Shared.Chemistry.Solutions Copies Solution class to new namespace Obsoletes old Solution class * Switches over to the Solutions.Solution Solution * Creates Content.Shared.Chemistry.Containers Copies relevant components/systems to the new namespace Obsoletes old versions * Switches over to the Containers.XYZ namespace * Creates SolutionSystem and obsoletes old SolutionContainerSystem methods * Start using SolutionSystem for Solution manipulation * EnumerateSolutions * Move TryGetMixableSolution * Move EnsureSolution to Server * Create Solution Entities * Stop using obsolete solution system methods * Fix prototype component tests * Add using ..Audio.Systems; back * Wrap solution container slots in ContainerSlots * Actually add the slot to the solution container map * Dirty SolutionContainerComponent when ensuring solutions * Revert namespace changes * Remerge SolutionSystem and SolutionContainerSystem * SolutionContainerManagerComponent refactor * Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release * Readd examine reagent sorting * Fix errors * Poke tests * Fix solution names not being applied * Fix WoolyComponent including statement * Fix merge skew * Fix compile errors * Make reactions use solntities * Reindent solution class namespace * Field attribute changes * AutoGenerateComponentState for SolutionContainerComponent * SolutionContainerComponent -> ContainedSolutionComponent * ref ReactionAttemptEvent * Denetwork preinit solutions * Misc 1 * Nullable TryGetSolution out vars * Cache associated solutions * Fix merge skew * Use explicit regions in SharedSolutionContainerSystem.Capabilities * Add debug assert * Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent * ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName * SolutionComponent doc comments * Implicit DataField names and property purge * ReagentEffect DataField names * Local variables for readability * Sort using statements + Entity<T> event handlers * Fix compile erros * Fix compile errors --------- Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -16,38 +17,38 @@ public sealed class TransformableContainerSystem : EntitySystem
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<TransformableContainerComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<TransformableContainerComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
SubscribeLocalEvent<TransformableContainerComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, TransformableContainerComponent component, MapInitEvent args)
|
||||
private void OnMapInit(Entity<TransformableContainerComponent> entity, ref MapInitEvent args)
|
||||
{
|
||||
var meta = MetaData(uid);
|
||||
if (string.IsNullOrEmpty(component.InitialName))
|
||||
var meta = MetaData(entity.Owner);
|
||||
if (string.IsNullOrEmpty(entity.Comp.InitialName))
|
||||
{
|
||||
component.InitialName = meta.EntityName;
|
||||
entity.Comp.InitialName = meta.EntityName;
|
||||
}
|
||||
if (string.IsNullOrEmpty(component.InitialDescription))
|
||||
if (string.IsNullOrEmpty(entity.Comp.InitialDescription))
|
||||
{
|
||||
component.InitialDescription = meta.EntityDescription;
|
||||
entity.Comp.InitialDescription = meta.EntityDescription;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid owner, TransformableContainerComponent component,
|
||||
SolutionChangedEvent args)
|
||||
private void OnSolutionChange(Entity<TransformableContainerComponent> entity, ref SolutionContainerChangedEvent args)
|
||||
{
|
||||
if (!_solutionsSystem.TryGetFitsInDispenser(owner, out var solution))
|
||||
if (!_solutionsSystem.TryGetFitsInDispenser(entity.Owner, out _, out var solution))
|
||||
return;
|
||||
|
||||
//Transform container into initial state when emptied
|
||||
if (component.CurrentReagent != null && solution.Contents.Count == 0)
|
||||
if (entity.Comp.CurrentReagent != null && solution.Contents.Count == 0)
|
||||
{
|
||||
CancelTransformation(owner, component);
|
||||
CancelTransformation(entity);
|
||||
}
|
||||
|
||||
//the biggest reagent in the solution decides the appearance
|
||||
var reagentId = solution.GetPrimaryReagentId();
|
||||
|
||||
//If biggest reagent didn't changed - don't change anything at all
|
||||
if (component.CurrentReagent != null && component.CurrentReagent.ID == reagentId?.Prototype)
|
||||
if (entity.Comp.CurrentReagent != null && entity.Comp.CurrentReagent.ID == reagentId?.Prototype)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -56,29 +57,29 @@ public sealed class TransformableContainerSystem : EntitySystem
|
||||
if (!string.IsNullOrWhiteSpace(reagentId?.Prototype)
|
||||
&& _prototypeManager.TryIndex(reagentId.Value.Prototype, out ReagentPrototype? proto))
|
||||
{
|
||||
var metadata = MetaData(owner);
|
||||
var metadata = MetaData(entity.Owner);
|
||||
var val = Loc.GetString("transformable-container-component-glass", ("name", proto.LocalizedName));
|
||||
_metadataSystem.SetEntityName(owner, val, metadata);
|
||||
_metadataSystem.SetEntityDescription(owner, proto.LocalizedDescription, metadata);
|
||||
component.CurrentReagent = proto;
|
||||
component.Transformed = true;
|
||||
_metadataSystem.SetEntityName(entity.Owner, val, metadata);
|
||||
_metadataSystem.SetEntityDescription(entity.Owner, proto.LocalizedDescription, metadata);
|
||||
entity.Comp.CurrentReagent = proto;
|
||||
entity.Comp.Transformed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelTransformation(EntityUid owner, TransformableContainerComponent component)
|
||||
private void CancelTransformation(Entity<TransformableContainerComponent> entity)
|
||||
{
|
||||
component.CurrentReagent = null;
|
||||
component.Transformed = false;
|
||||
entity.Comp.CurrentReagent = null;
|
||||
entity.Comp.Transformed = false;
|
||||
|
||||
var metadata = MetaData(owner);
|
||||
var metadata = MetaData(entity);
|
||||
|
||||
if (!string.IsNullOrEmpty(component.InitialName))
|
||||
if (!string.IsNullOrEmpty(entity.Comp.InitialName))
|
||||
{
|
||||
_metadataSystem.SetEntityName(owner, component.InitialName, metadata);
|
||||
_metadataSystem.SetEntityName(entity.Owner, entity.Comp.InitialName, metadata);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(component.InitialDescription))
|
||||
if (!string.IsNullOrEmpty(entity.Comp.InitialDescription))
|
||||
{
|
||||
_metadataSystem.SetEntityDescription(owner, component.InitialDescription, metadata);
|
||||
_metadataSystem.SetEntityDescription(entity.Owner, entity.Comp.InitialDescription, metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user