Fix stuck in-hand sprites (#5068)

This commit is contained in:
Leon Friedrich
2021-10-29 01:34:59 +13:00
committed by GitHub
parent ac78145b94
commit b427d9cb8b
3 changed files with 60 additions and 61 deletions

View File

@@ -28,15 +28,12 @@ namespace Content.Client.Hands
ActiveHand = state.ActiveHand; ActiveHand = state.ActiveHand;
UpdateHandContainers(); HandsModified();
UpdateHandVisualizer();
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandsModifiedMessage { Hands = this });
} }
public override void HandsModified() public override void HandsModified()
{ {
UpdateHandContainers(); UpdateHandContainers();
UpdateHandVisualizer();
base.HandsModified(); base.HandsModified();
} }
@@ -55,28 +52,5 @@ namespace Content.Client.Hands
} }
} }
} }
public void UpdateHandVisualizer()
{
if (Owner.TryGetComponent(out SharedAppearanceComponent? appearance))
appearance.SetData(HandsVisuals.VisualState, GetHandsVisualState());
}
private HandsVisualState GetHandsVisualState()
{
var hands = new List<HandVisualState>();
foreach (var hand in Hands)
{
if (hand.HeldEntity == null)
continue;
if (!hand.HeldEntity.TryGetComponent(out SharedItemComponent? item) || item.RsiPath == null)
continue;
var handState = new HandVisualState(item.RsiPath, item.EquippedPrefix, hand.Location, item.Color);
hands.Add(handState);
}
return new(hands);
}
} }
} }

View File

@@ -61,38 +61,4 @@ namespace Content.Client.Hands
return location.ToString(); return location.ToString();
} }
} }
public enum HandsVisuals : byte
{
VisualState
}
public class HandsVisualState
{
public List<HandVisualState> Hands { get; } = new();
public HandsVisualState(List<HandVisualState> hands)
{
Hands = hands;
}
}
public class HandVisualState
{
public string RsiPath { get; }
public string? EquippedPrefix { get; }
public HandLocation Location { get; }
public Color Color { get; }
public HandVisualState(string rsiPath, string? equippedPrefix, HandLocation location, Color color)
{
RsiPath = rsiPath;
EquippedPrefix = equippedPrefix;
Location = location;
Color = color;
}
}
} }

View File

@@ -91,11 +91,34 @@ namespace Content.Shared.Hands.Components
public virtual void HandsModified() public virtual void HandsModified()
{ {
// todo axe all this for ECS. // todo axe all this for ECS.
// todo burn it all down.
UpdateHandVisualizer();
Dirty(); Dirty();
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandsModifiedMessage { Hands = this }); Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandsModifiedMessage { Hands = this });
} }
public void UpdateHandVisualizer()
{
if (!Owner.TryGetComponent(out SharedAppearanceComponent? appearance))
return;
var hands = new List<HandVisualState>();
foreach (var hand in Hands)
{
if (hand.HeldEntity == null)
continue;
if (!hand.HeldEntity.TryGetComponent(out SharedItemComponent? item) || item.RsiPath == null)
continue;
var handState = new HandVisualState(item.RsiPath, item.EquippedPrefix, hand.Location, item.Color);
hands.Add(handState);
}
appearance.SetData(HandsVisuals.VisualState, new HandsVisualState(hands));
}
public void AddHand(string handName, HandLocation handLocation) public void AddHand(string handName, HandLocation handLocation)
{ {
if (HasHand(handName)) if (HasHand(handName))
@@ -812,6 +835,42 @@ namespace Content.Shared.Hands.Components
protected virtual void HandlePickupAnimation(IEntity entity) { } protected virtual void HandlePickupAnimation(IEntity entity) { }
} }
#region visualizerData
[Serializable, NetSerializable]
public enum HandsVisuals : byte
{
VisualState
}
[Serializable, NetSerializable]
public class HandsVisualState
{
public List<HandVisualState> Hands { get; } = new();
public HandsVisualState(List<HandVisualState> hands)
{
Hands = hands;
}
}
[Serializable, NetSerializable]
public class HandVisualState
{
public string RsiPath { get; }
public string? EquippedPrefix { get; }
public HandLocation Location { get; }
public Color Color { get; }
public HandVisualState(string rsiPath, string? equippedPrefix, HandLocation location, Color color)
{
RsiPath = rsiPath;
EquippedPrefix = equippedPrefix;
Location = location;
Color = color;
}
}
#endregion
public class Hand public class Hand
{ {
[ViewVariables] [ViewVariables]