| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using Robust.Shared.Serialization;
- using Robust.Shared.Serialization.Manager;
- using Robust.Shared.Serialization.Markdown.Mapping;
- using Robust.Shared.Serialization.Markdown.Validation;
- using Robust.Shared.Serialization.TypeSerializers.Interfaces;
- namespace Content.Shared.Construction.Steps
- {
- [TypeSerializer]
- public sealed class ConstructionGraphStepTypeSerializer : ITypeReader<ConstructionGraphStep, MappingDataNode>
- {
- private Type? GetType(MappingDataNode node)
- {
- if (node.Has("material"))
- {
- return typeof(MaterialConstructionGraphStep);
- }
- if (node.Has("tool"))
- {
- return typeof(ToolConstructionGraphStep);
- }
- if (node.Has("component"))
- {
- return typeof(ComponentConstructionGraphStep);
- }
- if (node.Has("tag"))
- {
- return typeof(TagConstructionGraphStep);
- }
- if (node.Has("allTags") || node.Has("anyTags"))
- {
- return typeof(MultipleTagsConstructionGraphStep);
- }
- if (node.Has("minTemperature") || node.Has("maxTemperature"))
- {
- return typeof(TemperatureConstructionGraphStep);
- }
- if (node.Has("assemblyId") || node.Has("guideString"))
- {
- return typeof(PartAssemblyConstructionGraphStep);
- }
- return null;
- }
- public ConstructionGraphStep Read(ISerializationManager serializationManager,
- MappingDataNode node,
- IDependencyCollection dependencies,
- SerializationHookContext hookCtx,
- ISerializationContext? context = null,
- ISerializationManager.InstantiationDelegate<ConstructionGraphStep>? instanceProvider = null)
- {
- var type = GetType(node) ??
- throw new ArgumentException(
- "Tried to convert invalid YAML node mapping to ConstructionGraphStep!");
- return (ConstructionGraphStep)serializationManager.Read(type, node, hookCtx, context)!;
- }
- public ValidationNode Validate(ISerializationManager serializationManager, MappingDataNode node,
- IDependencyCollection dependencies,
- ISerializationContext? context = null)
- {
- var type = GetType(node);
- if (type == null)
- return new ErrorNode(node, "No construction graph step type found.");
- return serializationManager.ValidateNode(type, node, context);
- }
- }
- }
|