committed by
GitHub
parent
afc8c9163c
commit
3a27490c59
@@ -1,71 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Materials;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Materials
|
||||
{
|
||||
/// <summary>
|
||||
/// Component to store data such as "this object is made out of steel".
|
||||
/// This is not a storage system for say smelteries.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class MaterialComponent : Component, ISerializationHooks
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public const string SerializationCache = "mat";
|
||||
|
||||
public override string Name => "Material";
|
||||
|
||||
[DataField("materials")] private List<MaterialDataEntry> _materials = new();
|
||||
|
||||
public IEnumerable<KeyValuePair<object, MaterialPrototype>> MaterialTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var entry in _materials)
|
||||
{
|
||||
var prototype = _prototypeManager.Index<MaterialPrototype>(entry.Value);
|
||||
|
||||
yield return new KeyValuePair<object, MaterialPrototype>(entry.Key, prototype);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DataDefinition]
|
||||
public class MaterialDataEntry : ISerializationHooks
|
||||
{
|
||||
public object Key = default!;
|
||||
|
||||
[DataField("key", required: true)]
|
||||
public string StringKey = default!;
|
||||
|
||||
[DataField("mat", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<MaterialPrototype>))]
|
||||
public string Value = default!;
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
var refl = IoCManager.Resolve<IReflectionManager>();
|
||||
|
||||
if (refl.TryParseEnumReference(StringKey, out var @enum))
|
||||
{
|
||||
Key = @enum;
|
||||
return;
|
||||
}
|
||||
|
||||
Key = StringKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum MaterialKeys
|
||||
{
|
||||
Stack,
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
#nullable enable
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Materials
|
||||
{
|
||||
/// <summary>
|
||||
/// Materials are read-only storage for the properties of specific materials.
|
||||
/// Properties should be intrinsic (or at least as much is necessary for game purposes).
|
||||
/// </summary>
|
||||
[Prototype("material")]
|
||||
[DataDefinition]
|
||||
public class MaterialPrototype : IPrototype, IInheritingPrototype
|
||||
{
|
||||
[ViewVariables]
|
||||
[DataField("id", required: true)]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
[DataField("name")] public string Name { get; private set; } = "unobtanium";
|
||||
|
||||
[DataField("color")] public Color Color { get; private set; } = Color.Gray;
|
||||
|
||||
/// <summary>
|
||||
/// Volumetric mass density, in kg.m^-3.
|
||||
/// </summary>
|
||||
[DataField("density")]
|
||||
public double Density { get; private set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Electrical resistivity, NOT resistance.
|
||||
/// Unit is ohm-meter (Ω⋅m).
|
||||
/// </summary>
|
||||
[DataField("electricResistivity")]
|
||||
public double ElectricResistivity { get; private set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Thermal conductivity, in W.m-1.K-1
|
||||
/// </summary>
|
||||
[DataField("thermalConductivity")]
|
||||
public double ThermalConductivity { get; private set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Specific heat, in J.kg-1.K-1
|
||||
/// </summary>
|
||||
[DataField("specificHeat")]
|
||||
public double SpecificHeat { get; private set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Controls how durable the material is.
|
||||
/// Basically how slowly it degrades.
|
||||
/// </summary>
|
||||
[DataField("durability")]
|
||||
public double Durability { get; private set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Multiplier for how much this resists damage.
|
||||
/// So higher means armor is more effective, for example.
|
||||
/// </summary>
|
||||
[DataField("hardness")]
|
||||
public double Hardness { get; private set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Multiplier that determines damage on sharpness-based weapons like knives.
|
||||
/// Higher means more damage is done.
|
||||
/// </summary>
|
||||
[DataField("sharpDamage")]
|
||||
public double SharpDamage { get; private set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Multiplier that determines damage on blunt-based weapons like clubs.
|
||||
/// Higher means more damage is done.
|
||||
/// </summary>
|
||||
[DataField("bluntDamage")]
|
||||
public double BluntDamage { get; private set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// An icon used to represent the material in graphic interfaces.
|
||||
/// </summary>
|
||||
[DataField("icon")]
|
||||
public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid;
|
||||
|
||||
[DataField("parent")]
|
||||
public string? Parent { get; }
|
||||
|
||||
[DataField("abstract")]
|
||||
public bool Abstract { get; }
|
||||
}
|
||||
}
|
||||
50
Content.Shared/Materials/MaterialPrototype.cs
Normal file
50
Content.Shared/Materials/MaterialPrototype.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Stacks;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Materials
|
||||
{
|
||||
/// <summary>
|
||||
/// Materials are read-only storage for the properties of specific materials.
|
||||
/// Properties should be intrinsic (or at least as much is necessary for game purposes).
|
||||
/// </summary>
|
||||
[Prototype("material")]
|
||||
public class MaterialPrototype : IPrototype, IInheritingPrototype
|
||||
{
|
||||
[ViewVariables]
|
||||
[DataField("parent")]
|
||||
public string? Parent { get; } = null;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("abstract")]
|
||||
public bool Abstract { get; } = false;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("id", required: true)]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("stack", customTypeSerializer:typeof(PrototypeIdSerializer<StackPrototype>))]
|
||||
public string? StackId { get; } = null;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("name")]
|
||||
public string Name { get; } = "unobtanium";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("color")]
|
||||
public Color Color { get; } = Color.Gray;
|
||||
|
||||
/// <summary>
|
||||
/// An icon used to represent the material in graphic interfaces.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("icon")]
|
||||
public SpriteSpecifier Icon { get; } = SpriteSpecifier.Invalid;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user