Simple network replication for hands, untested.
This commit is contained in:
@@ -62,6 +62,8 @@
|
||||
<Compile Include="EntryPoint.cs" />
|
||||
<Compile Include="Prototypes\DiscoBall.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\HandsComponent.cs" />
|
||||
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj">
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using SS14.Shared.ContentPack;
|
||||
using Content.Client.GameObjects;
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using SS14.Shared.ContentPack;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
@@ -12,6 +14,9 @@ namespace Content.Client
|
||||
|
||||
factory.RegisterIgnore("Inventory");
|
||||
factory.RegisterIgnore("Item");
|
||||
|
||||
factory.Register<HandsComponent>();
|
||||
factory.RegisterReference<HandsComponent, IHandsComponent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Client.GameObjects
|
||||
{
|
||||
public class HandsComponent : SharedHandsComponent, IHandsComponent
|
||||
{
|
||||
private readonly Dictionary<string, IEntity> hands = new Dictionary<string, IEntity>();
|
||||
|
||||
public IEntity GetEntity(string index)
|
||||
{
|
||||
if (hands.TryGetValue(index, out var entity))
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState state)
|
||||
{
|
||||
var cast = (HandsComponentState)state;
|
||||
hands.Clear();
|
||||
foreach (var hand in cast.Hands)
|
||||
{
|
||||
hands[hand.Key] = Owner.EntityManager.GetEntity(hand.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Content.Client.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Client.Interfaces.GameObjects
|
||||
{
|
||||
// HYPER SIMPLE HANDS API CLIENT SIDE.
|
||||
// To allow for showing the HUD, mostly.
|
||||
public interface IHandsComponent
|
||||
{
|
||||
IEntity GetEntity(string index);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Utility;
|
||||
@@ -9,10 +10,8 @@ using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Server.GameObjects
|
||||
{
|
||||
public class HandsComponent : Component, IHandsComponent
|
||||
public class HandsComponent : SharedHandsComponent, IHandsComponent
|
||||
{
|
||||
public override string Name => "Hands";
|
||||
|
||||
private string activeIndex;
|
||||
public string ActiveIndex
|
||||
{
|
||||
@@ -54,8 +53,6 @@ namespace Content.Server.GameObjects
|
||||
|
||||
public IEnumerable<IItemComponent> GetAllHeldItems()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
/*
|
||||
foreach (var slot in hands.Values)
|
||||
{
|
||||
if (slot.Item != null)
|
||||
@@ -63,7 +60,6 @@ namespace Content.Server.GameObjects
|
||||
yield return slot.Item;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public IItemComponent GetHand(string index)
|
||||
@@ -77,8 +73,6 @@ namespace Content.Server.GameObjects
|
||||
/// </summary>
|
||||
private IEnumerable<string> ActivePriorityEnumerable()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
/*
|
||||
yield return ActiveIndex;
|
||||
foreach (var hand in hands.Keys)
|
||||
{
|
||||
@@ -89,7 +83,6 @@ namespace Content.Server.GameObjects
|
||||
|
||||
yield return hand;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public bool PutInHand(IItemComponent item)
|
||||
@@ -183,5 +176,18 @@ namespace Content.Server.GameObjects
|
||||
/// Get the name of the slot passed to the inventory component.
|
||||
/// </summary>
|
||||
private string HandSlotName(string index) => $"_hand_{index}";
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
var dict = new Dictionary<string, int>(hands.Count);
|
||||
foreach (var hand in hands)
|
||||
{
|
||||
if (hand.Value.Item != null)
|
||||
{
|
||||
dict[hand.Key] = hand.Value.Item.Owner.Uid;
|
||||
}
|
||||
}
|
||||
return new HandsComponentState(dict);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="EntryPoint.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="GameObjects\Components\Items\HandsComponent.cs" />
|
||||
<Compile Include="GameObjects\Components\NetIDs.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\engine\Lidgren.Network\Lidgren.Network.csproj">
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using SS14.Shared.GameObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Shared.GameObjects
|
||||
{
|
||||
public abstract class SharedHandsComponent : Component
|
||||
{
|
||||
public sealed override string Name => "Hands";
|
||||
public sealed override uint? NetID => ContentNetIDs.HANDS;
|
||||
public sealed override Type StateType => typeof(HandsComponentState);
|
||||
}
|
||||
|
||||
// The IDs of the items get synced over the network.
|
||||
[Serializable]
|
||||
public class HandsComponentState : ComponentState
|
||||
{
|
||||
public readonly Dictionary<string, int> Hands;
|
||||
|
||||
public HandsComponentState(Dictionary<string, int> hands)
|
||||
{
|
||||
Hands = hands;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Content.Shared/GameObjects/Components/NetIDs.cs
Normal file
7
Content.Shared/GameObjects/Components/NetIDs.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Content.Shared.GameObjects
|
||||
{
|
||||
public static class ContentNetIDs
|
||||
{
|
||||
public const uint HANDS = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user