From 3a27490c590de40aed19781771d1e37b84d0956d Mon Sep 17 00:00:00 2001
From: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Date: Thu, 20 May 2021 10:37:34 +0200
Subject: [PATCH] Material cleanup (#4025)
* work
* more work
---
Content.Client/IgnoredComponents.cs | 1 +
.../Components/Materials/MaterialComponent.cs | 49 ++++++++++
.../Components/Research/LatheComponent.cs | 22 ++---
.../Components/Materials/MaterialComponent.cs | 71 ---------------
Content.Shared/Materials/Material.cs | 91 -------------------
Content.Shared/Materials/MaterialPrototype.cs | 50 ++++++++++
.../Objects/Materials/Sheets/glass.yml | 30 +++---
.../Objects/Materials/Sheets/metal.yml | 25 +++--
.../Objects/Materials/Sheets/other.yml | 21 +++--
.../Entities/Objects/Materials/ingots.yml | 30 +++---
.../Entities/Objects/Materials/materials.yml | 24 ++++-
.../Entities/Objects/Materials/ore.yml | 42 ++++++---
.../Entities/Objects/Materials/parts.yml | 2 +
.../Prototypes/Reagents/Materials/glass.yml | 34 +++----
.../Reagents/Materials/materials.yml | 35 ++-----
.../Prototypes/Reagents/Materials/metals.yml | 57 +++++-------
SpaceStation14.sln.DotSettings | 1 +
17 files changed, 267 insertions(+), 318 deletions(-)
create mode 100644 Content.Server/GameObjects/Components/Materials/MaterialComponent.cs
delete mode 100644 Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs
delete mode 100644 Content.Shared/Materials/Material.cs
create mode 100644 Content.Shared/Materials/MaterialPrototype.cs
diff --git a/Content.Client/IgnoredComponents.cs b/Content.Client/IgnoredComponents.cs
index 5a42a8e583..4b4fe6adc7 100644
--- a/Content.Client/IgnoredComponents.cs
+++ b/Content.Client/IgnoredComponents.cs
@@ -34,6 +34,7 @@ namespace Content.Client
"Smes",
"LightBulb",
"Healing",
+ "Material",
"RangedMagazine",
"Ammo",
"HitscanWeaponCapacitor",
diff --git a/Content.Server/GameObjects/Components/Materials/MaterialComponent.cs b/Content.Server/GameObjects/Components/Materials/MaterialComponent.cs
new file mode 100644
index 0000000000..0d4836e116
--- /dev/null
+++ b/Content.Server/GameObjects/Components/Materials/MaterialComponent.cs
@@ -0,0 +1,49 @@
+using System.Collections.Generic;
+using Content.Shared.Materials;
+using Robust.Shared.GameObjects;
+using Robust.Shared.IoC;
+using Robust.Shared.Log;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Serialization.Manager.Attributes;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
+using Robust.Shared.ViewVariables;
+
+namespace Content.Server.GameObjects.Components.Materials
+{
+ ///
+ /// Component to store data such as "this object is made out of steel".
+ /// This is not a storage system for say smelteries.
+ ///
+ [RegisterComponent]
+ public class MaterialComponent : Component
+ {
+ public override string Name => "Material";
+
+ [ViewVariables]
+ [DataField("materials", customTypeSerializer:typeof(PrototypeIdListSerializer))]
+ // ReSharper disable once CollectionNeverUpdated.Local
+ private readonly List _materials = new();
+ public IEnumerable MaterialIds => _materials;
+
+ ///
+ /// Returns all materials which make up this entity.
+ /// This property has an IoC resolve and is generally slow, so be sure to cache the results if needed.
+ ///
+ [ViewVariables]
+ public IEnumerable Materials
+ {
+ get
+ {
+ var prototypeManager = IoCManager.Resolve();
+
+ foreach (var id in MaterialIds)
+ {
+ if(prototypeManager.TryIndex(id, out var material))
+ yield return material;
+ else
+ Logger.Error($"Material prototype {id} does not exist! Entity: {Owner}");
+ }
+ }
+ }
+ }
+}
diff --git a/Content.Server/GameObjects/Components/Research/LatheComponent.cs b/Content.Server/GameObjects/Components/Research/LatheComponent.cs
index f07d2f19e2..531ea8fd95 100644
--- a/Content.Server/GameObjects/Components/Research/LatheComponent.cs
+++ b/Content.Server/GameObjects/Components/Research/LatheComponent.cs
@@ -3,10 +3,10 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using Content.Server.GameObjects.Components.Materials;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.Utility;
-using Content.Shared.GameObjects.Components.Materials;
using Content.Shared.GameObjects.Components.Power;
using Content.Shared.GameObjects.Components.Research;
using Content.Shared.Interfaces.GameObjects.Components;
@@ -160,37 +160,37 @@ namespace Content.Server.GameObjects.Components.Research
var totalAmount = 0;
// Check if it can insert all materials.
- foreach (var (_, mat) in material.MaterialTypes)
+ foreach (var mat in material.MaterialIds)
{
// TODO: Change how MaterialComponent works so this is not hard-coded.
- if (!storage.CanInsertMaterial(mat.ID, VolumePerSheet * multiplier)) return false;
+ if (!storage.CanInsertMaterial(mat, VolumePerSheet * multiplier)) return false;
totalAmount += VolumePerSheet * multiplier;
}
// Check if it can take ALL of the material's volume.
if (storage.CanTakeAmount(totalAmount)) return false;
- foreach (var (_, mat) in material.MaterialTypes)
+ foreach (var mat in material.MaterialIds)
{
- storage.InsertMaterial(mat.ID, VolumePerSheet * multiplier);
+ storage.InsertMaterial(mat, VolumePerSheet * multiplier);
}
State = LatheState.Inserting;
- switch (material.MaterialTypes.First().Value.Name)
+ switch (material.Materials.FirstOrDefault()?.ID)
{
- case "steel":
+ case "Steel":
SetAppearance(LatheVisualState.InsertingMetal);
break;
- case "glass":
+ case "Glass":
SetAppearance(LatheVisualState.InsertingGlass);
break;
- case "gold":
+ case "Gold":
SetAppearance(LatheVisualState.InsertingGold);
break;
- case "plastic":
+ case "Plastic":
SetAppearance(LatheVisualState.InsertingPlastic);
break;
- case "plasma":
+ case "Plasma":
SetAppearance(LatheVisualState.InsertingPlasma);
break;
}
diff --git a/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs b/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs
deleted file mode 100644
index 7af11b96d0..0000000000
--- a/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs
+++ /dev/null
@@ -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
-{
- ///
- /// Component to store data such as "this object is made out of steel".
- /// This is not a storage system for say smelteries.
- ///
- [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 _materials = new();
-
- public IEnumerable> MaterialTypes
- {
- get
- {
- foreach (var entry in _materials)
- {
- var prototype = _prototypeManager.Index(entry.Value);
-
- yield return new KeyValuePair