Add auto modes to reagent grinder (#26290)

* Add auto-mode to reagent grinder

* Remove redundant stuff with DataField

* Use margin instead of dummy control

* Resolve grinder component
This commit is contained in:
Crotalus
2024-03-29 07:30:50 +01:00
committed by GitHub
parent cdfee5aa0c
commit a606909d30
7 changed files with 73 additions and 11 deletions

View File

@@ -53,11 +53,19 @@ namespace Content.Server.Kitchen.EntitySystems
SubscribeLocalEvent<ReagentGrinderComponent, EntRemovedFromContainerMessage>(OnContainerModified);
SubscribeLocalEvent<ReagentGrinderComponent, ContainerIsRemovingAttemptEvent>(OnEntRemoveAttempt);
SubscribeLocalEvent<ReagentGrinderComponent, ReagentGrinderToggleAutoModeMessage>(OnToggleAutoModeMessage);
SubscribeLocalEvent<ReagentGrinderComponent, ReagentGrinderStartMessage>(OnStartMessage);
SubscribeLocalEvent<ReagentGrinderComponent, ReagentGrinderEjectChamberAllMessage>(OnEjectChamberAllMessage);
SubscribeLocalEvent<ReagentGrinderComponent, ReagentGrinderEjectChamberContentMessage>(OnEjectChamberContentMessage);
}
private void OnToggleAutoModeMessage(Entity<ReagentGrinderComponent> entity, ref ReagentGrinderToggleAutoModeMessage message)
{
entity.Comp.AutoMode = (GrinderAutoMode) (((byte) entity.Comp.AutoMode + 1) % Enum.GetValues(typeof(GrinderAutoMode)).Length);
UpdateUiState(entity);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
@@ -148,6 +156,12 @@ namespace Content.Server.Kitchen.EntitySystems
var outputContainer = _itemSlotsSystem.GetItemOrNull(uid, SharedReagentGrinder.BeakerSlotId);
_appearanceSystem.SetData(uid, ReagentGrinderVisualState.BeakerAttached, outputContainer.HasValue);
if (reagentGrinder.AutoMode != GrinderAutoMode.Off && !HasComp<ActiveReagentGrinderComponent>(uid))
{
var program = reagentGrinder.AutoMode == GrinderAutoMode.Grind ? GrinderProgram.Grind : GrinderProgram.Juice;
DoWork(uid, reagentGrinder, program);
}
}
private void OnInteractUsing(Entity<ReagentGrinderComponent> entity, ref InteractUsingEvent args)
@@ -185,6 +199,10 @@ namespace Content.Server.Kitchen.EntitySystems
private void UpdateUiState(EntityUid uid)
{
ReagentGrinderComponent? grinderComp = null;
if (!Resolve(uid, ref grinderComp))
return;
var inputContainer = _containerSystem.EnsureContainer<Container>(uid, SharedReagentGrinder.InputContainerId);
var outputContainer = _itemSlotsSystem.GetItemOrNull(uid, SharedReagentGrinder.BeakerSlotId);
Solution? containerSolution = null;
@@ -206,6 +224,7 @@ namespace Content.Server.Kitchen.EntitySystems
this.IsPowered(uid, EntityManager),
canJuice,
canGrind,
grinderComp.AutoMode,
GetNetEntityArray(inputContainer.ContainedEntities.ToArray()),
containerSolution?.Contents.ToArray()
);