mirror of
https://github.com/xivdev/EXDSchema.git
synced 2025-06-06 16:17:46 +00:00
Refine Yaml output and reconsider life choices
This commit is contained in:
parent
2d96cd07b7
commit
b4e19ad8fb
6 changed files with 161 additions and 60 deletions
|
@ -1,41 +1,70 @@
|
|||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
using System.ComponentModel;
|
||||
using SharpYaml;
|
||||
using SharpYaml.Serialization;
|
||||
|
||||
namespace SchemaConverter.New;
|
||||
|
||||
public enum FieldType
|
||||
{
|
||||
scalar,
|
||||
array,
|
||||
icon,
|
||||
modelId,
|
||||
color,
|
||||
Scalar,
|
||||
Array,
|
||||
Icon,
|
||||
ModelId,
|
||||
Color,
|
||||
}
|
||||
|
||||
public class Sheet
|
||||
{
|
||||
[YamlMember(0)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[YamlMember(1)]
|
||||
public string? DisplayField { get; set; }
|
||||
|
||||
[YamlMember(2)]
|
||||
public List<Field> Fields { get; set; }
|
||||
}
|
||||
|
||||
public class Field
|
||||
{
|
||||
[YamlMember(0)]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[YamlMember(1)]
|
||||
public int? Count { get; set; }
|
||||
public string? Comment { get; set; }
|
||||
|
||||
[YamlMember(2)]
|
||||
[DefaultValue(FieldType.Scalar)]
|
||||
public FieldType Type { get; set; }
|
||||
|
||||
[YamlMember(3)]
|
||||
public string? Comment { get; set; }
|
||||
|
||||
[YamlMember(4)]
|
||||
public List<Field>? Fields { get; set; }
|
||||
|
||||
[YamlMember(5)]
|
||||
public Link? Link { get; set; }
|
||||
}
|
||||
|
||||
public class Link
|
||||
{
|
||||
public List<string> Target { get; set; }
|
||||
[YamlMember(0)]
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
[YamlMember(1)]
|
||||
[YamlStyle(YamlStyle.Flow)]
|
||||
public List<string> Target { get; set; }
|
||||
}
|
||||
|
||||
public class Condition
|
||||
{
|
||||
[YamlMember(0)]
|
||||
public string Switch { get; set; }
|
||||
|
||||
[YamlMember(1)]
|
||||
public Dictionary<int, List<string>> Cases { get; set; }
|
||||
}
|
|
@ -123,17 +123,17 @@ public class SchemaConverter
|
|||
Name = col.Name,
|
||||
Type = col.Type switch
|
||||
{
|
||||
"quad" => FieldType.modelId,
|
||||
"icon" => FieldType.icon,
|
||||
"color" => FieldType.color,
|
||||
_ => FieldType.scalar,
|
||||
"quad" => FieldType.ModelId,
|
||||
"icon" => FieldType.Icon,
|
||||
"color" => FieldType.Color,
|
||||
_ => FieldType.Scalar,
|
||||
},
|
||||
Link = col.Link,
|
||||
};
|
||||
newSchema.Fields.Add(field);
|
||||
}
|
||||
|
||||
var newSchemaStr = SerializeUtil.Serialize(newSchema);
|
||||
var newSchemaStr = SerializeUtil3.Serialize(newSchema);
|
||||
File.WriteAllText(newSchemaPath, newSchemaStr);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Lumina" Version="3.11.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="YamlDotNet" Version="13.3.1" />
|
||||
<PackageReference Include="SharpYaml" Version="2.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
|
|
@ -1,47 +1,48 @@
|
|||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.EventEmitters;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
namespace SchemaConverter;
|
||||
|
||||
public static class SerializeUtil
|
||||
{
|
||||
private static readonly ISerializer _serializer;
|
||||
|
||||
static SerializeUtil()
|
||||
{
|
||||
_serializer = new SerializerBuilder()
|
||||
.WithIndentedSequences()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults)
|
||||
// .WithEventEmitter(nextEmitter => new FlowEverythingEmitter(nextEmitter))
|
||||
.Build();
|
||||
}
|
||||
|
||||
public static string Serialize(object o)
|
||||
{
|
||||
return _serializer.Serialize(o);
|
||||
}
|
||||
|
||||
public class FlowEverythingEmitter : ChainedEventEmitter
|
||||
{
|
||||
public FlowEverythingEmitter(IEventEmitter nextEmitter) : base(nextEmitter) { }
|
||||
|
||||
public override void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
Console.WriteLine($"Type: {eventInfo.Source.Type} Style: {eventInfo.Source.StaticType} Value: {eventInfo.Source.Value}");
|
||||
|
||||
eventInfo.Style = MappingStyle.Flow;
|
||||
base.Emit(eventInfo, emitter);
|
||||
}
|
||||
|
||||
public override void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter)
|
||||
{
|
||||
Console.WriteLine($"Type: {eventInfo.Source.Type} StaticType: {eventInfo.Source.StaticType} Value: {eventInfo.Source.Value}");
|
||||
eventInfo.Style = SequenceStyle.Flow;
|
||||
nextEmitter.Emit(eventInfo, emitter);
|
||||
}
|
||||
}
|
||||
}
|
||||
// using YamlDotNet.Core;
|
||||
// using YamlDotNet.Core.Events;
|
||||
// using YamlDotNet.Serialization;
|
||||
// using YamlDotNet.Serialization.EventEmitters;
|
||||
// using YamlDotNet.Serialization.NamingConventions;
|
||||
//
|
||||
// namespace SchemaConverter;
|
||||
//
|
||||
// public static class SerializeUtil
|
||||
// {
|
||||
// private static readonly ISerializer _serializer;
|
||||
//
|
||||
// static SerializeUtil()
|
||||
// {
|
||||
// _serializer = new SerializerBuilder()
|
||||
// .WithIndentedSequences()
|
||||
// .WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||
// .ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults)
|
||||
// .DisableAliases()
|
||||
// // .WithEventEmitter(nextEmitter => new FlowEverythingEmitter(nextEmitter))
|
||||
// .Build();
|
||||
// }
|
||||
//
|
||||
// public static string Serialize(object o)
|
||||
// {
|
||||
// return _serializer.Serialize(o);
|
||||
// }
|
||||
//
|
||||
// public class FlowEverythingEmitter : ChainedEventEmitter
|
||||
// {
|
||||
// public FlowEverythingEmitter(IEventEmitter nextEmitter) : base(nextEmitter) { }
|
||||
//
|
||||
// public override void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
|
||||
// {
|
||||
// Console.WriteLine($"Type: {eventInfo.Source.Type} Style: {eventInfo.Source.StaticType} Value: {eventInfo.Source.Value}");
|
||||
//
|
||||
// eventInfo.Style = MappingStyle.Flow;
|
||||
// base.Emit(eventInfo, emitter);
|
||||
// }
|
||||
//
|
||||
// public override void Emit(SequenceStartEventInfo eventInfo, IEmitter emitter)
|
||||
// {
|
||||
// Console.WriteLine($"Type: {eventInfo.Source.Type} StaticType: {eventInfo.Source.StaticType} Value: {eventInfo.Source.Value}");
|
||||
// eventInfo.Style = SequenceStyle.Flow;
|
||||
// nextEmitter.Emit(eventInfo, emitter);
|
||||
// }
|
||||
// }
|
||||
// }
|
18
SchemaConverter/SerializeUtil2.cs
Normal file
18
SchemaConverter/SerializeUtil2.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
// using YamlMap;
|
||||
//
|
||||
// namespace SchemaConverter;
|
||||
//
|
||||
// public static class SerializeUtil2
|
||||
// {
|
||||
// private static readonly YamlWriter _serializer;
|
||||
//
|
||||
// static SerializeUtil2()
|
||||
// {
|
||||
// _serializer = new YamlWriter();
|
||||
// }
|
||||
//
|
||||
// public static string Serialize(object o)
|
||||
// {
|
||||
// return _serializer.Write(o);
|
||||
// }
|
||||
// }
|
53
SchemaConverter/SerializeUtil3.cs
Normal file
53
SchemaConverter/SerializeUtil3.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using SharpYaml;
|
||||
using SharpYaml.Events;
|
||||
using SharpYaml.Serialization;
|
||||
using SharpYaml.Serialization.Serializers;
|
||||
|
||||
namespace SchemaConverter;
|
||||
|
||||
public static class SerializeUtil3
|
||||
{
|
||||
private static readonly Serializer _serializer;
|
||||
|
||||
static SerializeUtil3()
|
||||
{
|
||||
var settings = new SerializerSettings
|
||||
{
|
||||
EmitAlias = false,
|
||||
EmitDefaultValues = false,
|
||||
NamingConvention = new CamelCaseNamingConvention(),
|
||||
IgnoreNulls = true,
|
||||
};
|
||||
settings.RegisterSerializer(typeof(Dictionary<int, List<string>>), new CustomDictionarySerializer());
|
||||
settings.RegisterSerializer(typeof(New.FieldType), new CustomFieldTypeSerializer());
|
||||
|
||||
_serializer = new Serializer(settings);
|
||||
}
|
||||
|
||||
public static string Serialize(object o)
|
||||
{
|
||||
return _serializer.Serialize(o);
|
||||
}
|
||||
}
|
||||
|
||||
internal class CustomDictionarySerializer : DictionarySerializer
|
||||
{
|
||||
protected override void WriteDictionaryItem(ref ObjectContext objectContext, KeyValuePair<object, object?> keyValue, KeyValuePair<Type, Type> types)
|
||||
{
|
||||
objectContext.SerializerContext.WriteYaml(keyValue.Key, types.Key);
|
||||
objectContext.SerializerContext.WriteYaml(keyValue.Value, types.Value, YamlStyle.Flow);
|
||||
}
|
||||
}
|
||||
|
||||
internal class CustomFieldTypeSerializer : ScalarSerializerBase
|
||||
{
|
||||
public override object? ConvertFrom(ref ObjectContext context, Scalar fromScalar)
|
||||
{
|
||||
return Enum.Parse<New.FieldType>(new PascalNamingConvention().Convert(fromScalar.Value));
|
||||
}
|
||||
|
||||
public override string ConvertTo(ref ObjectContext objectContext)
|
||||
{
|
||||
return objectContext.Settings.NamingConvention.Convert(objectContext.Instance.ToString());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue