Files
tbd-station-14/Content.Client/GameObjects/Components/Items/ItemComponent.cs
PrPleGoo 35f3cbe3f9 Engineer's helmet (#188)
* refacting some sprite things

* fix sprites

* Netcode for sending a new icon state to the ClientComponent

* Fixed broken torches.

* Fix dirty calls.

* ClothingComponentState now also includes EquippedPrefix

* Inherritance ClothingComponent : ItemComponent

* Added parameter to ItemComponentState constructor.

* Update RobustToolbox

* Revert "Update RobustToolbox"

This reverts commit 82c7e98ff3853b64698d5e80a45cd7a3758618e0.

Undo weird commit to toolbox?
2019-04-08 12:18:27 +02:00

71 lines
2.1 KiB
C#

using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Items;
using SS14.Client.Graphics;
using SS14.Client.Interfaces.ResourceManagement;
using SS14.Client.ResourceManagement;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Components.Renderable;
using SS14.Shared.IoC;
using SS14.Shared.Serialization;
using SS14.Shared.Utility;
using SS14.Shared.ViewVariables;
using System;
namespace Content.Client.GameObjects
{
public class ItemComponent : Component
{
public override string Name => "Item";
public override uint? NetID => ContentNetIDs.ITEM;
public override Type StateType => typeof(ItemComponentState);
[ViewVariables] protected ResourcePath RsiPath;
private string _equippedPrefix;
[ViewVariables(VVAccess.ReadWrite)]
public string EquippedPrefix
{
get => _equippedPrefix;
set => _equippedPrefix = value;
}
public (RSI rsi, RSI.StateId stateId)? GetInHandStateInfo(string hand)
{
if (RsiPath == null)
{
return null;
}
var rsi = GetRSI();
var stateId = EquippedPrefix != null ? $"{EquippedPrefix}-inhand-{hand}" : $"inhand-{hand}";
if (rsi.TryGetState(stateId, out _))
{
return (rsi, stateId);
}
return null;
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataFieldCached(ref RsiPath, "sprite", null);
serializer.DataFieldCached(ref _equippedPrefix, "prefix", null);
}
protected RSI GetRSI()
{
var resourceCache = IoCManager.Resolve<IResourceCache>();
return resourceCache.GetResource<RSIResource>(SharedSpriteComponent.TextureRoot / RsiPath).RSI;
}
public override void HandleComponentState(ComponentState state)
{
var itemComponentState = (ItemComponentState)state;
EquippedPrefix = itemComponentState.EquippedPrefix;
}
}
}