Equip clothing to preview dummies in the lobby.

This commit is contained in:
Pieter-Jan Briers
2020-01-20 09:20:36 +01:00
parent 03bfb22559
commit 75aa9541e0
7 changed files with 166 additions and 24 deletions

View File

@@ -6,13 +6,28 @@ namespace Content.Shared.GameObjects.Components.Inventory
{
public static class EquipmentSlotDefines
{
public static IReadOnlyCollection<Slots> AllSlots { get; }
static EquipmentSlotDefines()
{
var output = new Slots[(int)Slots.LAST - (int)Slots.HEAD];
// The index stuff is to jump over NONE.
for (var i = 0; i < output.Length; i++)
{
output[i] = (Slots)(i+1);
}
AllSlots = output;
}
/// <summary>
/// Uniquely identifies a single slot in an inventory.
/// </summary>
[Serializable, NetSerializable]
public enum Slots
{
NONE,
NONE = 0,
HEAD,
EYES,
EARS,
@@ -29,7 +44,12 @@ namespace Content.Shared.GameObjects.Components.Inventory
POCKET3,
POCKET4,
EXOSUITSLOT1,
EXOSUITSLOT2
EXOSUITSLOT2,
/// <summary>
/// Not a real slot.
/// </summary>
LAST
}
/// <summary>

View File

@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using YamlDotNet.RepresentationModel;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
namespace Content.Shared.Jobs
{
@@ -11,20 +13,30 @@ namespace Content.Shared.Jobs
public class StartingGearPrototype : IPrototype, IIndexedPrototype
{
private string _id;
private Dictionary<string, string> _equipment;
private Dictionary<Slots, string> _equipment;
[ViewVariables]
public string ID => _id;
[ViewVariables] public string ID => _id;
[ViewVariables]
public Dictionary<string, string> Equipment => _equipment;
[ViewVariables] public IReadOnlyDictionary<Slots, string> Equipment => _equipment;
public void LoadFrom(YamlMappingNode mapping)
{
var serializer = YamlObjectSerializer.NewReader(mapping);
serializer.DataField(ref _id, "id", string.Empty);
serializer.DataField(ref _equipment, "equipment", new Dictionary<string, string>());
var equipment = serializer.ReadDataField<Dictionary<string, string>>("equipment");
_equipment = equipment.ToDictionary(slotStr =>
{
var (key, _) = slotStr;
if (!Enum.TryParse(key, true, out Slots slot))
{
throw new Exception($"{key} is an invalid equipment slot.");
}
return slot;
}, type => type.Value);
}
}
}