Skip to content

Commit

Permalink
Chem dispenser attempts to eject into hands (space-wizards#576)
Browse files Browse the repository at this point in the history
Previously the chem dispenser eject button placed the container on top of the dispenser. Now it will attempt to place it in your active hand, then your secondary hand. If both hands are full then it'll place it on top of the dispenser like before.
  • Loading branch information
Moneyl authored Jan 29, 2020
1 parent 73a9b2a commit 493b800
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
switch (msg.Button)
{
case UiButton.Eject:
TryEject();
TryEject(obj.Session.AttachedEntity);
break;
case UiButton.Clear:
TryClear();
Expand Down Expand Up @@ -189,14 +189,22 @@ private void UpdateUserInterface()

/// <summary>
/// If this component contains an entity with a <see cref="SolutionComponent"/>, eject it.
/// Tries to eject into user's hands first, then ejects onto dispenser if both hands are full.
/// </summary>
private void TryEject()
private void TryEject(IEntity user)
{
if (!HasBeaker) return;
if (!HasBeaker)
return;

var beaker = _beakerContainer.ContainedEntity;
Solution.SolutionChanged -= HandleSolutionChangedEvent;
_beakerContainer.Remove(_beakerContainer.ContainedEntity);

UpdateUserInterface();

if(!user.TryGetComponent<HandsComponent>(out var hands) || !beaker.TryGetComponent<ItemComponent>(out var item))
return;
if (hands.CanPutInHand(item))
hands.PutInHand(item);
}

/// <summary>
Expand Down

0 comments on commit 493b800

Please sign in to comment.