Slay bobby pt. 1 (#5632)
This commit is contained in:
108
Content.Shared/Body/Part/BodyPartSlot.cs
Normal file
108
Content.Shared/Body/Part/BodyPartSlot.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Body.Part
|
||||
{
|
||||
public class BodyPartSlot
|
||||
{
|
||||
public BodyPartSlot(string id, BodyPartType partType, IEnumerable<BodyPartSlot> connections)
|
||||
{
|
||||
Id = id;
|
||||
PartType = partType;
|
||||
Connections = new HashSet<BodyPartSlot>(connections);
|
||||
}
|
||||
|
||||
public BodyPartSlot(string id, BodyPartType partType)
|
||||
{
|
||||
Id = id;
|
||||
PartType = partType;
|
||||
Connections = new HashSet<BodyPartSlot>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The ID of this slot.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public string Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The part type that this slot accepts.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public BodyPartType PartType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The part currently in this slot, if any.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public SharedBodyPartComponent? Part { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of slots that this slot connects to.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public HashSet<BodyPartSlot> Connections { get; private set; }
|
||||
|
||||
public event Action<SharedBodyPartComponent>? PartAdded;
|
||||
|
||||
public event Action<SharedBodyPartComponent>? PartRemoved;
|
||||
|
||||
internal void SetConnectionsInternal(IEnumerable<BodyPartSlot> connections)
|
||||
{
|
||||
Connections = new HashSet<BodyPartSlot>(connections);
|
||||
}
|
||||
|
||||
public bool CanAddPart(SharedBodyPartComponent part)
|
||||
{
|
||||
return Part == null && part.PartType == PartType;
|
||||
}
|
||||
|
||||
public bool TryAddPart(SharedBodyPartComponent part)
|
||||
{
|
||||
if (!CanAddPart(part))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SetPart(part);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPart(SharedBodyPartComponent part)
|
||||
{
|
||||
if (Part != null)
|
||||
{
|
||||
RemovePart();
|
||||
}
|
||||
|
||||
Part = part;
|
||||
PartAdded?.Invoke(part);
|
||||
}
|
||||
|
||||
public bool RemovePart()
|
||||
{
|
||||
if (Part == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var old = Part;
|
||||
Part = null;
|
||||
|
||||
PartRemoved?.Invoke(old);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
Part = null;
|
||||
Connections.Clear();
|
||||
PartAdded = null;
|
||||
PartRemoved = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Body.Part.Property
|
||||
{
|
||||
/// <summary>
|
||||
/// Property attachable to a <see cref="SharedBodyPartComponent"/>.
|
||||
/// For example, this is used to define the speed capabilities of a leg.
|
||||
/// The movement system will look for a <see cref="LegComponent"/> on all
|
||||
/// <see cref="SharedBodyPartComponent"/>.
|
||||
/// </summary>
|
||||
public abstract class BodyPartPropertyComponent : Component, IBodyPartProperty
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether this property is currently active.
|
||||
/// </summary>
|
||||
[DataField("active")]
|
||||
public bool Active { get; set; } = true;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Body.Part.Property
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the length of a <see cref="SharedBodyPartComponent"/>.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class ExtensionComponent : BodyPartPropertyComponent
|
||||
{
|
||||
public override string Name => "Extension";
|
||||
|
||||
/// <summary>
|
||||
/// Current distance in tiles.
|
||||
/// </summary>
|
||||
[DataField("distance")]
|
||||
public float Distance { get; set; } = 3f;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Body.Part.Property
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a <see cref="SharedBodyPartComponent"/> as being able to grasp around an entity,
|
||||
/// for example picking up an item.
|
||||
/// </summary>
|
||||
// TODO BODY Implement
|
||||
[RegisterComponent]
|
||||
public class GraspComponent : BodyPartPropertyComponent
|
||||
{
|
||||
public override string Name => "Grasp";
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Body.Part.Property
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a property for a <see cref="SharedBodyPartComponent"/>.
|
||||
/// </summary>
|
||||
public interface IBodyPartProperty : IComponent
|
||||
{
|
||||
bool Active { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using Content.Shared.Body.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.Body.Part.Property
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the speed at which a <see cref="SharedBodyPartComponent"/> can move.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class LegComponent : BodyPartPropertyComponent
|
||||
{
|
||||
public override string Name => "Leg";
|
||||
|
||||
/// <summary>
|
||||
/// Speed in tiles per second.
|
||||
/// </summary>
|
||||
[DataField("speed")]
|
||||
public float Speed { get; set; } = 2.6f;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user