Seprated many files, removed IDataCompiler with using YamlConverters. Refactored namespaces
This commit is contained in:
131
src/Blueprints/Provider/Converters/ComponentsNameConverter.cs
Normal file
131
src/Blueprints/Provider/Converters/ComponentsNameConverter.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
namespace FoodFactory.Blueprints.Providers.Converters;
|
||||
|
||||
using System;
|
||||
using SharpYaml.Serialization;
|
||||
|
||||
public sealed class ComponentNameConverter : ItemComponentsConverter<Name>
|
||||
{
|
||||
public override IValueProvider<Name> Read(YamlReader reader)
|
||||
{
|
||||
if (reader.TokenType == YamlTokenType.Scalar)
|
||||
{
|
||||
var key = reader.GetScalarValue();
|
||||
reader.Read();
|
||||
return new StaticCompiledNode<Name>(new(key));
|
||||
}
|
||||
return base.Read(reader);
|
||||
}
|
||||
|
||||
public override void Write(YamlWriter writer, IValueProvider<Name> value) => throw new NotImplementedException();
|
||||
}
|
||||
// public class ComponentBinderRegistry
|
||||
// {
|
||||
// private readonly Dictionary<ComponentType, IComponentBinder> _binder = [];
|
||||
// public void Add<T>(ComponentBinder<T> componentBinder) where T : struct
|
||||
// {
|
||||
|
||||
// _binder.Add(typeof(T), componentBinder);
|
||||
// }
|
||||
// public void Apply(Entity entity, World world, CompiledBlueprint itemData)
|
||||
// {
|
||||
|
||||
// var s = world.GetSignature(entity);
|
||||
// for (int i = 0; i < s.Count; i++)
|
||||
// {
|
||||
// if (!_binder.ContainsKey(s.Components[i]))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// var binder = _binder[s.Components[i]];
|
||||
// var type = s.Components[i].Type;
|
||||
// var context = new BlueprintContext(){World = world};
|
||||
// binder.ApplyUntyped(entity, itemData.Providers[type], context);
|
||||
// }
|
||||
// }
|
||||
// public void Apply(Span<Entity> entities, World world, CompiledBlueprint itemData)
|
||||
// {
|
||||
// var signature = world.GetSignature(entities[0]);
|
||||
// for (int i = 1; i < entities.Length; i++)
|
||||
// {
|
||||
// Debug.Assert(world.GetSignature(entities[i]) == signature);
|
||||
// }
|
||||
|
||||
// for (int i = 0; i < signature.Count; i++)
|
||||
// {
|
||||
// var binder = _binder[signature.Components[i]];
|
||||
// var type = signature.Components[i].Type;
|
||||
// var context = new BlueprintContext(){World = world};
|
||||
// binder.ApplyUntyped(entities, itemData.Providers[type], context);
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// public abstract class DataNode//(Dictionary<string, object> Data)
|
||||
// {
|
||||
// public abstract DataNodeType NodeType { get; }
|
||||
// // public T Get<T>(string name) => (T)Data[name];
|
||||
// }
|
||||
// public enum DataNodeType
|
||||
// {hthous stomatitis, pharyngitis, adenitis) is a
|
||||
// Value,
|
||||
// Sequence,
|
||||
// Mapping,
|
||||
// Component
|
||||
// }
|
||||
// public sealed class ValueNode(object value) : DataNode
|
||||
// {
|
||||
// public override DataNodeType NodeType => DataNodeType.Value;
|
||||
|
||||
// public object Value { get; set; } = value;
|
||||
|
||||
// public Option<T> As<T>() => Value is T o?Option<T>.Some(o):Option<T>.None;
|
||||
// }
|
||||
// public sealed class SequenceNode(IReadOnlyList<DataNode> values) : DataNode
|
||||
// {
|
||||
// public override DataNodeType NodeType => DataNodeType.Sequence;
|
||||
|
||||
// public IReadOnlyList<DataNode> Values { get; set; } = values;
|
||||
// }
|
||||
// public sealed class MappingNode(IReadOnlyDictionary<string, DataNode> values) : DataNode
|
||||
// {
|
||||
// public override DataNodeType NodeType => DataNodeType.Mapping;
|
||||
|
||||
// public IReadOnlyDictionary<string, DataNode> Values { get; set; } = values;
|
||||
|
||||
// public bool TryGet<T>(string key, [NotNullWhen(true)] out T value) where T : DataNode
|
||||
// {
|
||||
// var result = Values.TryGetValue(key, out var node);
|
||||
// value = (T)node!;
|
||||
// return result;
|
||||
|
||||
// }
|
||||
// public bool TryGet(string key, [NotNullWhen(true)] out DataNode node) => Values.TryGetValue(key, out node!);
|
||||
// }
|
||||
|
||||
// public class DataNodeSerlicer : YamlConverter<DataNode>, IJsonFormatter<DataNode>
|
||||
// {
|
||||
// private Dictionary<string,string> _data = new();
|
||||
// public DataNode Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
|
||||
// {
|
||||
// var i = 0;
|
||||
// while (reader.ReadIsInObject(ref i))
|
||||
// {
|
||||
// var name = reader.ReadPropertyName();
|
||||
// var value = reader.ReadString();
|
||||
// _data.Add(name, value);
|
||||
// }
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
// public void Serialize(ref JsonWriter writer, DataNode value, IJsonFormatterResolver formatterResolver) => throw new NotImplementedException();
|
||||
|
||||
// public override DataNode? Read(YamlReader reader)
|
||||
// {
|
||||
// // reader.pa
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public override void Write(YamlWriter writer, DataNode value)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user