Seprated many files, removed IDataCompiler with using YamlConverters. Refactored namespaces
This commit is contained in:
@@ -2,6 +2,8 @@ namespace FoodFactory.Items;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FoodFactory.Blueprints.Providers;
|
||||
using FoodFactory.Core.Components;
|
||||
using FoodFactory.Math;
|
||||
using FoodFactory.Recipes;
|
||||
using SharpYaml;
|
||||
@@ -12,7 +14,7 @@ public class ItemData
|
||||
public string Id { get; set; } = "";
|
||||
public string[] Extend { get; set; } = [];
|
||||
[YamlConverter(typeof(ComponentsPatcherConverter))]
|
||||
public Dictionary<string, object> Components { get; set; } = [];
|
||||
public Dictionary<string, IValueProvider> Components { get; set; } = [];
|
||||
public HashSet<string> Remove { get; set; } = [];
|
||||
// public DataNode GetComponent(Type type)
|
||||
// {
|
||||
@@ -29,12 +31,12 @@ public class ItemData
|
||||
// public DataNode GetComponent<T>() where T : struct => GetComponent(typeof(T));
|
||||
}
|
||||
|
||||
public class ComponentsPatcherConverter : YamlConverter<Dictionary<string, object>>
|
||||
public class ComponentsPatcherConverter : YamlConverter<Dictionary<string, IValueProvider>>
|
||||
{
|
||||
private readonly Dictionary<string, Type> _componentsTypes = new(){
|
||||
[nameof(Temperature)] = typeof(IValueProvider<Temperature>),
|
||||
// [nameof(Tags)] = typeof(IValueProvider<Tags>),
|
||||
// [nameof(Name)] = typeof(IValueProvider<Name>),
|
||||
[nameof(Tags)] = typeof(IValueProvider<Tags>),
|
||||
[nameof(Name)] = typeof(IValueProvider<Name>),
|
||||
// [nameof(Mass)] = typeof(IValueProvider<Mass>),
|
||||
// [nameof(Godot.Color)] = typeof(IValueProvider<Godot.Color>),
|
||||
// [nameof(BurnableTemp)] = typeof(IValueProvider<BurnableTemp>),
|
||||
@@ -45,9 +47,9 @@ public class ComponentsPatcherConverter : YamlConverter<Dictionary<string, objec
|
||||
// _componentsTypes = componentsTypes;
|
||||
// }
|
||||
|
||||
public override Dictionary<string, object>? Read(YamlReader reader)
|
||||
public override Dictionary<string, IValueProvider>? Read(YamlReader reader)
|
||||
{
|
||||
var dict = new Dictionary<string,object>();
|
||||
var dict = new Dictionary<string,IValueProvider>();
|
||||
if (reader.TokenType == YamlTokenType.StartMapping)
|
||||
{
|
||||
reader.Read();
|
||||
@@ -65,15 +67,17 @@ public class ComponentsPatcherConverter : YamlConverter<Dictionary<string, objec
|
||||
if (!reader.TryGetCustomConverter(type, out var converter)){
|
||||
converter = reader.GetConverter(type);
|
||||
}
|
||||
object data;
|
||||
data = converter.Read(reader, type);
|
||||
|
||||
object data = converter.Read(reader, type);
|
||||
if (data is not IValueProvider)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// reader.Read();
|
||||
dict[key] = data;
|
||||
dict[key] = (IValueProvider)data;
|
||||
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
public override void Write(YamlWriter writer, Dictionary<string, object> value) => throw new NotImplementedException();
|
||||
public override void Write(YamlWriter writer, Dictionary<string, IValueProvider> value) => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user