Simple network replication for hands, untested.

This commit is contained in:
PJB3005
2017-09-26 21:27:48 +02:00
parent a464acf354
commit 4f2d059de4
8 changed files with 107 additions and 10 deletions

View File

@@ -62,6 +62,8 @@
<Compile Include="EntryPoint.cs" /> <Compile Include="EntryPoint.cs" />
<Compile Include="Prototypes\DiscoBall.cs" /> <Compile Include="Prototypes\DiscoBall.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GameObjects\Components\Items\HandsComponent.cs" />
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj"> <ProjectReference Include="..\Content.Shared\Content.Shared.csproj">

View File

@@ -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.Interfaces.GameObjects;
using SS14.Shared.IoC; using SS14.Shared.IoC;
@@ -12,6 +14,9 @@ namespace Content.Client
factory.RegisterIgnore("Inventory"); factory.RegisterIgnore("Inventory");
factory.RegisterIgnore("Item"); factory.RegisterIgnore("Item");
factory.Register<HandsComponent>();
factory.RegisterReference<HandsComponent, IHandsComponent>();
} }
} }
} }

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}

View File

@@ -1,4 +1,5 @@
using Content.Server.Interfaces.GameObjects; using Content.Server.Interfaces.GameObjects;
using Content.Shared.GameObjects;
using SS14.Shared.GameObjects; using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Utility; using SS14.Shared.Utility;
@@ -9,10 +10,8 @@ using YamlDotNet.RepresentationModel;
namespace Content.Server.GameObjects namespace Content.Server.GameObjects
{ {
public class HandsComponent : Component, IHandsComponent public class HandsComponent : SharedHandsComponent, IHandsComponent
{ {
public override string Name => "Hands";
private string activeIndex; private string activeIndex;
public string ActiveIndex public string ActiveIndex
{ {
@@ -54,8 +53,6 @@ namespace Content.Server.GameObjects
public IEnumerable<IItemComponent> GetAllHeldItems() public IEnumerable<IItemComponent> GetAllHeldItems()
{ {
throw new NotImplementedException();
/*
foreach (var slot in hands.Values) foreach (var slot in hands.Values)
{ {
if (slot.Item != null) if (slot.Item != null)
@@ -63,7 +60,6 @@ namespace Content.Server.GameObjects
yield return slot.Item; yield return slot.Item;
} }
} }
*/
} }
public IItemComponent GetHand(string index) public IItemComponent GetHand(string index)
@@ -77,8 +73,6 @@ namespace Content.Server.GameObjects
/// </summary> /// </summary>
private IEnumerable<string> ActivePriorityEnumerable() private IEnumerable<string> ActivePriorityEnumerable()
{ {
throw new NotImplementedException();
/*
yield return ActiveIndex; yield return ActiveIndex;
foreach (var hand in hands.Keys) foreach (var hand in hands.Keys)
{ {
@@ -89,7 +83,6 @@ namespace Content.Server.GameObjects
yield return hand; yield return hand;
} }
*/
} }
public bool PutInHand(IItemComponent item) public bool PutInHand(IItemComponent item)
@@ -183,5 +176,18 @@ namespace Content.Server.GameObjects
/// Get the name of the slot passed to the inventory component. /// Get the name of the slot passed to the inventory component.
/// </summary> /// </summary>
private string HandSlotName(string index) => $"_hand_{index}"; 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);
}
} }
} }

View File

@@ -56,6 +56,8 @@
<ItemGroup> <ItemGroup>
<Compile Include="EntryPoint.cs" /> <Compile Include="EntryPoint.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GameObjects\Components\Items\HandsComponent.cs" />
<Compile Include="GameObjects\Components\NetIDs.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\engine\Lidgren.Network\Lidgren.Network.csproj"> <ProjectReference Include="..\engine\Lidgren.Network\Lidgren.Network.csproj">

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,7 @@
namespace Content.Shared.GameObjects
{
public static class ContentNetIDs
{
public const uint HANDS = 0;
}
}